| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 98b6dc1 commit 324ea4f
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1074,13 +1074,17 @@ Executes the given SQL query, which is expected to not return any rows (e.g., IN | |||
| 1074 | 1074 | This function is intended to be used as a template literal tag, not to be | |
| 1075 | 1075 | called directly. | |
| 1076 | 1076 | ||
| 1077 | - ### `sqlTagStore.size()` | ||
| 1077 | + ### `sqlTagStore.size` | ||
| 1078 | 1078 | ||
| 1079 | 1079 | <!-- YAML | |
| 1080 | 1080 | added: v24.9.0 | |
| 1081 | + changes: | ||
| 1082 | + - version: REPLACEME | ||
| 1083 | + pr-url: https://github.com/nodejs/node/pull/60246 | ||
| 1084 | + description: Changed from a method to a getter. | ||
| 1081 | 1085 | --> | |
| 1082 | 1086 | ||
| 1083 | - * Returns: {integer} The number of prepared statements currently in the cache. | ||
| 1087 | + * Type: {integer} | ||
| 1084 | 1088 | ||
| 1085 | 1089 | A read-only property that returns the number of prepared statements currently in the cache. | |
| 1086 | 1090 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2700,11 +2700,13 @@ Local<FunctionTemplate> SQLTagStore::GetConstructorTemplate(Environment* env) { | |||
| 2700 | 2700 | SetProtoMethod(isolate, tmpl, "iterate", Iterate); | |
| 2701 | 2701 | SetProtoMethod(isolate, tmpl, "run", Run); | |
| 2702 | 2702 | SetProtoMethod(isolate, tmpl, "clear", Clear); | |
| 2703 | - SetProtoMethod(isolate, tmpl, "size", Size); | ||
| 2704 | - SetSideEffectFreeGetter( | ||
| 2705 | - isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "capacity"), Capacity); | ||
| 2703 | + SetSideEffectFreeGetter(isolate, | ||
| 2704 | + tmpl, | ||
| 2705 | + FIXED_ONE_BYTE_STRING(isolate, "capacity"), | ||
| 2706 | + CapacityGetter); | ||
| 2706 | 2707 | SetSideEffectFreeGetter( | |
| 2707 | 2708 | isolate, tmpl, FIXED_ONE_BYTE_STRING(isolate, "db"), DatabaseGetter); | |
| 2709 | + SetSideEffectFreeGetter(isolate, tmpl, env->size_string(), SizeGetter); | ||
| 2708 | 2710 | return tmpl; | |
| 2709 | 2711 | } | |
| 2710 | 2712 | ||
@@ -2720,32 +2722,44 @@ BaseObjectPtr<SQLTagStore> SQLTagStore::Create( | |||
| 2720 | 2722 | return MakeBaseObject<SQLTagStore>(env, obj, std::move(database), capacity); | |
| 2721 | 2723 | } | |
| 2722 | 2724 | ||
| 2725 | + void SQLTagStore::CapacityGetter(const FunctionCallbackInfo<Value>& args) { | ||
| 2726 | + SQLTagStore* store; | ||
| 2727 | + ASSIGN_OR_RETURN_UNWRAP(&store, args.This()); | ||
| 2728 | + args.GetReturnValue().Set(static_cast<double>(store->sql_tags_.Capacity())); | ||
| 2729 | + } | ||
| 2730 | + | ||
| 2723 | 2731 | void SQLTagStore::DatabaseGetter(const FunctionCallbackInfo<Value>& args) { | |
| 2724 | 2732 | SQLTagStore* store; | |
| 2725 | 2733 | ASSIGN_OR_RETURN_UNWRAP(&store, args.This()); | |
| 2726 | 2734 | args.GetReturnValue().Set(store->database_->object()); | |
| 2727 | 2735 | } | |
| 2728 | 2736 | ||
| 2729 | - void SQLTagStore::Run(const FunctionCallbackInfo<Value>& info) { | ||
| 2737 | + void SQLTagStore::SizeGetter(const FunctionCallbackInfo<Value>& args) { | ||
| 2738 | + SQLTagStore* store; | ||
| 2739 | + ASSIGN_OR_RETURN_UNWRAP(&store, args.This()); | ||
| 2740 | + args.GetReturnValue().Set(static_cast<double>(store->sql_tags_.Size())); | ||
| 2741 | + } | ||
| 2742 | + | ||
| 2743 | + void SQLTagStore::Run(const FunctionCallbackInfo<Value>& args) { | ||
| 2730 | 2744 | SQLTagStore* session; | |
| 2731 | - ASSIGN_OR_RETURN_UNWRAP(&session, info.This()); | ||
| 2732 | - Environment* env = Environment::GetCurrent(info); | ||
| 2745 | + ASSIGN_OR_RETURN_UNWRAP(&session, args.This()); | ||
| 2746 | + Environment* env = Environment::GetCurrent(args); | ||
| 2733 | 2747 | ||
| 2734 | 2748 | THROW_AND_RETURN_ON_BAD_STATE( | |
| 2735 | 2749 | env, !session->database_->IsOpen(), "database is not open"); | |
| 2736 | 2750 | ||
| 2737 | - BaseObjectPtr<StatementSync> stmt = PrepareStatement(info); | ||
| 2751 | + BaseObjectPtr<StatementSync> stmt = PrepareStatement(args); | ||
| 2738 | 2752 | ||
| 2739 | 2753 | if (!stmt) { | |
| 2740 | 2754 | return; | |
| 2741 | 2755 | } | |
| 2742 | 2756 | ||
| 2743 | - uint32_t n_params = info.Length() - 1; | ||
| 2757 | + uint32_t n_params = args.Length() - 1; | ||
| 2744 | 2758 | int r = sqlite3_reset(stmt->statement_); | |
| 2745 | 2759 | CHECK_ERROR_OR_THROW(env->isolate(), stmt->db_.get(), r, SQLITE_OK, void()); | |
| 2746 | 2760 | int param_count = sqlite3_bind_parameter_count(stmt->statement_); | |
| 2747 | 2761 | for (int i = 0; i < static_cast<int>(n_params) && i < param_count; ++i) { | |
| 2748 | - Local<Value> value = info[i + 1]; | ||
| 2762 | + Local<Value> value = args[i + 1]; | ||
| 2749 | 2763 | if (!stmt->BindValue(value, i + 1)) { | |
| 2750 | 2764 | return; | |
| 2751 | 2765 | } | |
@@ -2755,7 +2769,7 @@ void SQLTagStore::Run(const FunctionCallbackInfo<Value>& info) { | |||
| 2755 | 2769 | if (StatementExecutionHelper::Run( | |
| 2756 | 2770 | env, stmt->db_.get(), stmt->statement_, stmt->use_big_ints_) | |
| 2757 | 2771 | .ToLocal(&result)) { | |
| 2758 | - info.GetReturnValue().Set(result); | ||
| 2772 | + args.GetReturnValue().Set(result); | ||
| 2759 | 2773 | } | |
| 2760 | 2774 | } | |
| 2761 | 2775 | ||
@@ -2873,23 +2887,9 @@ void SQLTagStore::All(const FunctionCallbackInfo<Value>& args) { | |||
| 2873 | 2887 | } | |
| 2874 | 2888 | } | |
| 2875 | 2889 | ||
| 2876 | - void SQLTagStore::Size(const FunctionCallbackInfo<Value>& info) { | ||
| 2890 | + void SQLTagStore::Clear(const FunctionCallbackInfo<Value>& args) { | ||
| 2877 | 2891 | SQLTagStore* store; | |
| 2878 | - ASSIGN_OR_RETURN_UNWRAP(&store, info.This()); | ||
| 2879 | - info.GetReturnValue().Set( | ||
| 2880 | - Integer::New(info.GetIsolate(), store->sql_tags_.Size())); | ||
| 2881 | - } | ||
| 2882 | - | ||
| 2883 | - void SQLTagStore::Capacity(const FunctionCallbackInfo<Value>& info) { | ||
| 2884 | - SQLTagStore* store; | ||
| 2885 | - ASSIGN_OR_RETURN_UNWRAP(&store, info.This()); | ||
| 2886 | - info.GetReturnValue().Set( | ||
| 2887 | - Integer::New(info.GetIsolate(), store->sql_tags_.Capacity())); | ||
| 2888 | - } | ||
| 2889 | - | ||
| 2890 | - void SQLTagStore::Clear(const FunctionCallbackInfo<Value>& info) { | ||
| 2891 | - SQLTagStore* store; | ||
| 2892 | - ASSIGN_OR_RETURN_UNWRAP(&store, info.This()); | ||
| 2892 | + ASSIGN_OR_RETURN_UNWRAP(&store, args.This()); | ||
| 2893 | 2893 | store->sql_tags_.Clear(); | |
| 2894 | 2894 | } | |
| 2895 | 2895 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -313,15 +313,14 @@ class SQLTagStore : public BaseObject { | |||
| 313 | 313 | Environment* env, BaseObjectWeakPtr<DatabaseSync> database, int capacity); | |
| 314 | 314 | static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( | |
| 315 | 315 | Environment* env); | |
| 316 | - static void All(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 317 | - static void Get(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 318 | - static void Iterate(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 319 | - static void Run(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 320 | - static void Size(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 321 | - static void Capacity(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 322 | - static void Reset(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 323 | - static void Clear(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 324 | - static void DatabaseGetter(const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 316 | + static void All(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 317 | + static void Get(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 318 | + static void Iterate(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 319 | + static void Run(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 320 | + static void Clear(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 321 | + static void CapacityGetter(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 322 | + static void DatabaseGetter(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 323 | + static void SizeGetter(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 325 | 324 | void MemoryInfo(MemoryTracker* tracker) const override; | |
| 326 | 325 | SET_MEMORY_INFO_NAME(SQLTagStore) | |
| 327 | 326 | SET_SELF_SIZE(SQLTagStore) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,23 +77,23 @@ test('queries with no results', () => { | |||
| 77 | 77 | ||
| 78 | 78 | test('TagStore capacity, size, and clear', () => { | |
| 79 | 79 | assert.strictEqual(sql.capacity, 10); | |
| 80 | - assert.strictEqual(sql.size(), 0); | ||
| 80 | + assert.strictEqual(sql.size, 0); | ||
| 81 | 81 | ||
| 82 | 82 | assert.strictEqual(sql.run`INSERT INTO foo (text) VALUES (${'one'})`.changes, 1); | |
| 83 | - assert.strictEqual(sql.size(), 1); | ||
| 83 | + assert.strictEqual(sql.size, 1); | ||
| 84 | 84 | ||
| 85 | 85 | assert.ok(sql.get`SELECT * FROM foo WHERE text = ${'one'}`); | |
| 86 | - assert.strictEqual(sql.size(), 2); | ||
| 86 | + assert.strictEqual(sql.size, 2); | ||
| 87 | 87 | ||
| 88 | 88 | // Using the same template string shouldn't increase the size | |
| 89 | 89 | assert.strictEqual(sql.get`SELECT * FROM foo WHERE text = ${'two'}`, undefined); | |
| 90 | - assert.strictEqual(sql.size(), 2); | ||
| 90 | + assert.strictEqual(sql.size, 2); | ||
| 91 | 91 | ||
| 92 | 92 | assert.strictEqual(sql.all`SELECT * FROM foo`.length, 1); | |
| 93 | - assert.strictEqual(sql.size(), 3); | ||
| 93 | + assert.strictEqual(sql.size, 3); | ||
| 94 | 94 | ||
| 95 | 95 | sql.clear(); | |
| 96 | - assert.strictEqual(sql.size(), 0); | ||
| 96 | + assert.strictEqual(sql.size, 0); | ||
| 97 | 97 | assert.strictEqual(sql.capacity, 10); | |
| 98 | 98 | }); | |
| 99 | 99 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments