| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 67f5f46 commit c126543
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,17 +194,17 @@ objects. If the prepared statement does not return any results, this method | |||
| 194 | 194 | returns an empty array. The prepared statement [parameters are bound][] using | |
| 195 | 195 | the values in `namedParameters` and `anonymousParameters`. | |
| 196 | 196 | ||
| 197 | - ### `statement.expandedSQL()` | ||
| 197 | + ### `statement.expandedSQL` | ||
| 198 | 198 | ||
| 199 | 199 | <!-- YAML | |
| 200 | 200 | added: v22.5.0 | |
| 201 | 201 | --> | |
| 202 | 202 | ||
| 203 | - * Returns: {string} The source SQL expanded to include parameter values. | ||
| 203 | + * {string} The source SQL expanded to include parameter values. | ||
| 204 | 204 | ||
| 205 | - This method returns the source SQL of the prepared statement with parameter | ||
| 205 | + The source SQL text of the prepared statement with parameter | ||
| 206 | 206 | placeholders replaced by the values that were used during the most recent | |
| 207 | - execution of this prepared statement. This method is a wrapper around | ||
| 207 | + execution of this prepared statement. This property is a wrapper around | ||
| 208 | 208 | [`sqlite3_expanded_sql()`][]. | |
| 209 | 209 | ||
| 210 | 210 | ### `statement.get([namedParameters][, ...anonymousParameters])` | |
@@ -293,15 +293,15 @@ be used to read `INTEGER` data using JavaScript `BigInt`s. This method has no | |||
| 293 | 293 | impact on database write operations where numbers and `BigInt`s are both | |
| 294 | 294 | supported at all times. | |
| 295 | 295 | ||
| 296 | - ### `statement.sourceSQL()` | ||
| 296 | + ### `statement.sourceSQL` | ||
| 297 | 297 | ||
| 298 | 298 | <!-- YAML | |
| 299 | 299 | added: v22.5.0 | |
| 300 | 300 | --> | |
| 301 | 301 | ||
| 302 | - * Returns: {string} The source SQL used to create this prepared statement. | ||
| 302 | + * {string} The source SQL used to create this prepared statement. | ||
| 303 | 303 | ||
| 304 | - This method returns the source SQL of the prepared statement. This method is a | ||
| 304 | + The source SQL text of the prepared statement. This property is a | ||
| 305 | 305 | wrapper around [`sqlite3_sql()`][]. | |
| 306 | 306 | ||
| 307 | 307 | ### Type conversion between JavaScript and SQLite | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,11 @@ using v8::Array; | |||
| 18 | 18 | using v8::ArrayBuffer; | |
| 19 | 19 | using v8::BigInt; | |
| 20 | 20 | using v8::Boolean; | |
| 21 | + using v8::ConstructorBehavior; | ||
| 21 | 22 | using v8::Context; | |
| 23 | + using v8::DontDelete; | ||
| 22 | 24 | using v8::Exception; | |
| 25 | + using v8::FunctionCallback; | ||
| 23 | 26 | using v8::FunctionCallbackInfo; | |
| 24 | 27 | using v8::FunctionTemplate; | |
| 25 | 28 | using v8::Integer; | |
@@ -31,6 +34,7 @@ using v8::Name; | |||
| 31 | 34 | using v8::Null; | |
| 32 | 35 | using v8::Number; | |
| 33 | 36 | using v8::Object; | |
| 37 | + using v8::SideEffectType; | ||
| 34 | 38 | using v8::String; | |
| 35 | 39 | using v8::Uint8Array; | |
| 36 | 40 | using v8::Value; | |
@@ -643,7 +647,7 @@ void StatementSync::Run(const FunctionCallbackInfo<Value>& args) { | |||
| 643 | 647 | args.GetReturnValue().Set(result); | |
| 644 | 648 | } | |
| 645 | 649 | ||
| 646 | - void StatementSync::SourceSQL(const FunctionCallbackInfo<Value>& args) { | ||
| 650 | + void StatementSync::SourceSQLGetter(const FunctionCallbackInfo<Value>& args) { | ||
| 647 | 651 | StatementSync* stmt; | |
| 648 | 652 | ASSIGN_OR_RETURN_UNWRAP(&stmt, args.This()); | |
| 649 | 653 | Environment* env = Environment::GetCurrent(args); | |
@@ -657,7 +661,7 @@ void StatementSync::SourceSQL(const FunctionCallbackInfo<Value>& args) { | |||
| 657 | 661 | args.GetReturnValue().Set(sql); | |
| 658 | 662 | } | |
| 659 | 663 | ||
| 660 | - void StatementSync::ExpandedSQL(const FunctionCallbackInfo<Value>& args) { | ||
| 664 | + void StatementSync::ExpandedSQLGetter(const FunctionCallbackInfo<Value>& args) { | ||
| 661 | 665 | StatementSync* stmt; | |
| 662 | 666 | ASSIGN_OR_RETURN_UNWRAP(&stmt, args.This()); | |
| 663 | 667 | Environment* env = Environment::GetCurrent(args); | |
@@ -717,6 +721,23 @@ void IllegalConstructor(const FunctionCallbackInfo<Value>& args) { | |||
| 717 | 721 | node::THROW_ERR_ILLEGAL_CONSTRUCTOR(Environment::GetCurrent(args)); | |
| 718 | 722 | } | |
| 719 | 723 | ||
| 724 | + static inline void SetSideEffectFreeGetter( | ||
| 725 | + Isolate* isolate, | ||
| 726 | + Local<FunctionTemplate> class_template, | ||
| 727 | + Local<String> name, | ||
| 728 | + FunctionCallback fn) { | ||
| 729 | + Local<FunctionTemplate> getter = | ||
| 730 | + FunctionTemplate::New(isolate, | ||
| 731 | + fn, | ||
| 732 | + Local<Value>(), | ||
| 733 | + v8::Signature::New(isolate, class_template), | ||
| 734 | + /* length */ 0, | ||
| 735 | + ConstructorBehavior::kThrow, | ||
| 736 | + SideEffectType::kHasNoSideEffect); | ||
| 737 | + class_template->InstanceTemplate()->SetAccessorProperty( | ||
| 738 | + name, getter, Local<FunctionTemplate>(), DontDelete); | ||
| 739 | + } | ||
| 740 | + | ||
| 720 | 741 | Local<FunctionTemplate> StatementSync::GetConstructorTemplate( | |
| 721 | 742 | Environment* env) { | |
| 722 | 743 | Local<FunctionTemplate> tmpl = | |
@@ -730,8 +751,14 @@ Local<FunctionTemplate> StatementSync::GetConstructorTemplate( | |||
| 730 | 751 | SetProtoMethod(isolate, tmpl, "all", StatementSync::All); | |
| 731 | 752 | SetProtoMethod(isolate, tmpl, "get", StatementSync::Get); | |
| 732 | 753 | SetProtoMethod(isolate, tmpl, "run", StatementSync::Run); | |
| 733 | - SetProtoMethod(isolate, tmpl, "sourceSQL", StatementSync::SourceSQL); | ||
| 734 | - SetProtoMethod(isolate, tmpl, "expandedSQL", StatementSync::ExpandedSQL); | ||
| 754 | + SetSideEffectFreeGetter(isolate, | ||
| 755 | + tmpl, | ||
| 756 | + FIXED_ONE_BYTE_STRING(isolate, "sourceSQL"), | ||
| 757 | + StatementSync::SourceSQLGetter); | ||
| 758 | + SetSideEffectFreeGetter(isolate, | ||
| 759 | + tmpl, | ||
| 760 | + FIXED_ONE_BYTE_STRING(isolate, "expandedSQL"), | ||
| 761 | + StatementSync::ExpandedSQLGetter); | ||
| 735 | 762 | SetProtoMethod(isolate, | |
| 736 | 763 | tmpl, | |
| 737 | 764 | "setAllowBareNamedParameters", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,8 +62,9 @@ class StatementSync : public BaseObject { | |||
| 62 | 62 | static void All(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 63 | 63 | static void Get(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 64 | 64 | static void Run(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 65 | - static void SourceSQL(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 66 | - static void ExpandedSQL(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 65 | + static void SourceSQLGetter(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 66 | + static void ExpandedSQLGetter( | ||
| 67 | + const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 67 | 68 | static void SetAllowBareNamedParameters( | |
| 68 | 69 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 69 | 70 | static void SetReadBigInts(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -135,8 +135,8 @@ suite('StatementSync.prototype.run()', () => { | |||
| 135 | 135 | }); | |
| 136 | 136 | }); | |
| 137 | 137 | ||
| 138 | - suite('StatementSync.prototype.sourceSQL()', () => { | ||
| 139 | - test('returns input SQL', (t) => { | ||
| 138 | + suite('StatementSync.prototype.sourceSQL', () => { | ||
| 139 | + test('equals input SQL', (t) => { | ||
| 140 | 140 | const db = new DatabaseSync(nextDb()); | |
| 141 | 141 | t.after(() => { db.close(); }); | |
| 142 | 142 | const setup = db.exec( | |
@@ -145,12 +145,12 @@ suite('StatementSync.prototype.sourceSQL()', () => { | |||
| 145 | 145 | t.assert.strictEqual(setup, undefined); | |
| 146 | 146 | const sql = 'INSERT INTO types (key, val) VALUES ($k, $v)'; | |
| 147 | 147 | const stmt = db.prepare(sql); | |
| 148 | - t.assert.strictEqual(stmt.sourceSQL(), sql); | ||
| 148 | + t.assert.strictEqual(stmt.sourceSQL, sql); | ||
| 149 | 149 | }); | |
| 150 | 150 | }); | |
| 151 | 151 | ||
| 152 | - suite('StatementSync.prototype.expandedSQL()', () => { | ||
| 153 | - test('returns expanded SQL', (t) => { | ||
| 152 | + suite('StatementSync.prototype.expandedSQL', () => { | ||
| 153 | + test('equals expanded SQL', (t) => { | ||
| 154 | 154 | const db = new DatabaseSync(nextDb()); | |
| 155 | 155 | t.after(() => { db.close(); }); | |
| 156 | 156 | const setup = db.exec( | |
@@ -164,7 +164,7 @@ suite('StatementSync.prototype.expandedSQL()', () => { | |||
| 164 | 164 | stmt.run({ $k: '33' }, '42'), | |
| 165 | 165 | { changes: 1, lastInsertRowid: 33 }, | |
| 166 | 166 | ); | |
| 167 | - t.assert.strictEqual(stmt.expandedSQL(), expanded); | ||
| 167 | + t.assert.strictEqual(stmt.expandedSQL, expanded); | ||
| 168 | 168 | }); | |
| 169 | 169 | }); | |
| 170 | 170 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments