Commit 6302168

Browse files
araujoguiaduh95
authored andcommitted
sqlite: add stmt persistent flag
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: #62757 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2989311 commit 6302168

3 files changed

Lines changed: 119 additions & 83 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ console.log(query.get());
696696
<!-- YAML
697697
added: v22.5.0
698698
changes:
699+
- version: REPLACEME
700+
pr-url: https://github.com/nodejs/node/pull/62757
701+
description: Add the `persistent` option.
699702
- version: REPLACEME
700703
pr-url: https://github.com/nodejs/node/pull/65157
701704
description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements.
@@ -712,10 +715,14 @@ changes:
712715
database options or `true`.
713716
*`allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters
714717
are ignored. **Default:** inherited from database options or `false`.
718+
*`persistent` {boolean} If `true`, hints to SQLite that this statement will
719+
be retained for a long time and likely reused many times. SQLite currently
720+
responds to this hint by avoiding lookaside memory. Corresponds to the
721+
[`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:**`false`.
715722
* Returns: {StatementSync} The prepared statement.
716723

717724
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
718-
around [`sqlite3_prepare_v2()`][].
725+
around [`sqlite3_prepare_v3()`][].
719726

720727
### `database.createTagStore([maxSize])`
721728

@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized.
18821889
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
18831890
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
18841891
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg
1892+
[`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent
18851893
[`SQLTagStore`]: #class-sqltagstore
18861894
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options
18871895
[`database.createTagStore()`]: #databasecreatetagstoremaxsize
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized.
19071915
[`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html
19081916
[`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html
19091917
[`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html
1910-
[`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html
1918+
[`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html
19111919
[`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html
19121920
[`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html
19131921
[`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html

‎src/node_sqlite.cc‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
15391539
std::optional<bool> use_big_ints;
15401540
std::optional<bool> allow_bare_named_params;
15411541
std::optional<bool> allow_unknown_named_params;
1542+
std::optional<bool> persistent;
15421543

15431544
if (args.Length() > 1 && !args[1]->IsUndefined()) {
15441545
if (!args[1]->IsObject()) {
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
16191620
}
16201621
allow_unknown_named_params = allow_unknown_named_params_v->IsTrue();
16211622
}
1623+
1624+
Local<Value> persistent_v;
1625+
if (!options
1626+
->Get(env->context(),
1627+
FIXED_ONE_BYTE_STRING(env->isolate(), "persistent"))
1628+
.ToLocal(&persistent_v)) {
1629+
return;
1630+
}
1631+
if (!persistent_v->IsUndefined()) {
1632+
if (!persistent_v->IsBoolean()) {
1633+
THROW_ERR_INVALID_ARG_TYPE(
1634+
env->isolate(),
1635+
"The \"options.persistent\" argument must be a boolean.");
1636+
return;
1637+
}
1638+
persistent = persistent_v->IsTrue();
1639+
}
16221640
}
16231641

16241642
Utf8Value sql(env->isolate(), args[0].As<String>());
16251643
sqlite3_stmt* s = nullptr;
1626-
int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr);
1644+
1645+
unsignedint prep_flags =
1646+
persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0;
1647+
1648+
int r =
1649+
sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr);
1650+
16271651
StatementPtr stmt_ptr(s);
16281652

16291653
CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void());
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
38453869

38463870
if (stmt == nullptr) {
38473871
sqlite3_stmt* s = nullptr;
3848-
int r = sqlite3_prepare_v2(
3849-
session->database_->connection_, sql.data(), sql.size(), &s, nullptr);
3872+
int r = sqlite3_prepare_v3(session->database_->connection_,
3873+
sql.data(),
3874+
sql.size(),
3875+
SQLITE_PREPARE_PERSISTENT,
3876+
&s,
3877+
nullptr);
38503878
StatementPtr stmt_ptr(s);
38513879

38523880
if (r != SQLITE_OK) {

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Commit 6302168

Browse files
araujoguiaduh95
authored andcommitted
sqlite: add stmt persistent flag
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: #62757 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2989311 commit 6302168

3 files changed

Lines changed: 119 additions & 83 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ console.log(query.get());
696696
<!-- YAML
697697
added: v22.5.0
698698
changes:
699+
- version: REPLACEME
700+
pr-url: https://github.com/nodejs/node/pull/62757
701+
description: Add the `persistent` option.
699702
- version: REPLACEME
700703
pr-url: https://github.com/nodejs/node/pull/65157
701704
description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements.
@@ -712,10 +715,14 @@ changes:
712715
database options or `true`.
713716
*`allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters
714717
are ignored. **Default:** inherited from database options or `false`.
718+
*`persistent` {boolean} If `true`, hints to SQLite that this statement will
719+
be retained for a long time and likely reused many times. SQLite currently
720+
responds to this hint by avoiding lookaside memory. Corresponds to the
721+
[`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:**`false`.
715722
* Returns: {StatementSync} The prepared statement.
716723

717724
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
718-
around [`sqlite3_prepare_v2()`][].
725+
around [`sqlite3_prepare_v3()`][].
719726

720727
### `database.createTagStore([maxSize])`
721728

@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized.
18821889
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
18831890
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
18841891
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg
1892+
[`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent
18851893
[`SQLTagStore`]: #class-sqltagstore
18861894
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options
18871895
[`database.createTagStore()`]: #databasecreatetagstoremaxsize
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized.
19071915
[`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html
19081916
[`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html
19091917
[`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html
1910-
[`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html
1918+
[`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html
19111919
[`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html
19121920
[`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html
19131921
[`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html

‎src/node_sqlite.cc‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
15391539
std::optional<bool> use_big_ints;
15401540
std::optional<bool> allow_bare_named_params;
15411541
std::optional<bool> allow_unknown_named_params;
1542+
std::optional<bool> persistent;
15421543

15431544
if (args.Length() > 1 && !args[1]->IsUndefined()) {
15441545
if (!args[1]->IsObject()) {
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
16191620
}
16201621
allow_unknown_named_params = allow_unknown_named_params_v->IsTrue();
16211622
}
1623+
1624+
Local<Value> persistent_v;
1625+
if (!options
1626+
->Get(env->context(),
1627+
FIXED_ONE_BYTE_STRING(env->isolate(), "persistent"))
1628+
.ToLocal(&persistent_v)) {
1629+
return;
1630+
}
1631+
if (!persistent_v->IsUndefined()) {
1632+
if (!persistent_v->IsBoolean()) {
1633+
THROW_ERR_INVALID_ARG_TYPE(
1634+
env->isolate(),
1635+
"The \"options.persistent\" argument must be a boolean.");
1636+
return;
1637+
}
1638+
persistent = persistent_v->IsTrue();
1639+
}
16221640
}
16231641

16241642
Utf8Value sql(env->isolate(), args[0].As<String>());
16251643
sqlite3_stmt* s = nullptr;
1626-
int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr);
1644+
1645+
unsignedint prep_flags =
1646+
persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0;
1647+
1648+
int r =
1649+
sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr);
1650+
16271651
StatementPtr stmt_ptr(s);
16281652

16291653
CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void());
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
38453869

38463870
if (stmt == nullptr) {
38473871
sqlite3_stmt* s = nullptr;
3848-
int r = sqlite3_prepare_v2(
3849-
session->database_->connection_, sql.data(), sql.size(), &s, nullptr);
3872+
int r = sqlite3_prepare_v3(session->database_->connection_,
3873+
sql.data(),
3874+
sql.size(),
3875+
SQLITE_PREPARE_PERSISTENT,
3876+
&s,
3877+
nullptr);
38503878
StatementPtr stmt_ptr(s);
38513879

38523880
if (r != SQLITE_OK) {

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 6302168

Browse files
araujoguiaduh95
authored andcommitted
sqlite: add stmt persistent flag
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: #62757 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2989311 commit 6302168

3 files changed

Lines changed: 119 additions & 83 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ console.log(query.get());
696696
<!-- YAML
697697
added: v22.5.0
698698
changes:
699+
- version: REPLACEME
700+
pr-url: https://github.com/nodejs/node/pull/62757
701+
description: Add the `persistent` option.
699702
- version: REPLACEME
700703
pr-url: https://github.com/nodejs/node/pull/65157
701704
description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements.
@@ -712,10 +715,14 @@ changes:
712715
database options or `true`.
713716
*`allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters
714717
are ignored. **Default:** inherited from database options or `false`.
718+
*`persistent` {boolean} If `true`, hints to SQLite that this statement will
719+
be retained for a long time and likely reused many times. SQLite currently
720+
responds to this hint by avoiding lookaside memory. Corresponds to the
721+
[`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:**`false`.
715722
* Returns: {StatementSync} The prepared statement.
716723

717724
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
718-
around [`sqlite3_prepare_v2()`][].
725+
around [`sqlite3_prepare_v3()`][].
719726

720727
### `database.createTagStore([maxSize])`
721728

@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized.
18821889
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
18831890
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
18841891
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg
1892+
[`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent
18851893
[`SQLTagStore`]: #class-sqltagstore
18861894
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options
18871895
[`database.createTagStore()`]: #databasecreatetagstoremaxsize
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized.
19071915
[`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html
19081916
[`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html
19091917
[`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html
1910-
[`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html
1918+
[`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html
19111919
[`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html
19121920
[`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html
19131921
[`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html

‎src/node_sqlite.cc‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
15391539
std::optional<bool> use_big_ints;
15401540
std::optional<bool> allow_bare_named_params;
15411541
std::optional<bool> allow_unknown_named_params;
1542+
std::optional<bool> persistent;
15421543

15431544
if (args.Length() > 1 && !args[1]->IsUndefined()) {
15441545
if (!args[1]->IsObject()) {
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
16191620
}
16201621
allow_unknown_named_params = allow_unknown_named_params_v->IsTrue();
16211622
}
1623+
1624+
Local<Value> persistent_v;
1625+
if (!options
1626+
->Get(env->context(),
1627+
FIXED_ONE_BYTE_STRING(env->isolate(), "persistent"))
1628+
.ToLocal(&persistent_v)) {
1629+
return;
1630+
}
1631+
if (!persistent_v->IsUndefined()) {
1632+
if (!persistent_v->IsBoolean()) {
1633+
THROW_ERR_INVALID_ARG_TYPE(
1634+
env->isolate(),
1635+
"The \"options.persistent\" argument must be a boolean.");
1636+
return;
1637+
}
1638+
persistent = persistent_v->IsTrue();
1639+
}
16221640
}
16231641

16241642
Utf8Value sql(env->isolate(), args[0].As<String>());
16251643
sqlite3_stmt* s = nullptr;
1626-
int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr);
1644+
1645+
unsignedint prep_flags =
1646+
persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0;
1647+
1648+
int r =
1649+
sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr);
1650+
16271651
StatementPtr stmt_ptr(s);
16281652

16291653
CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void());
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
38453869

38463870
if (stmt == nullptr) {
38473871
sqlite3_stmt* s = nullptr;
3848-
int r = sqlite3_prepare_v2(
3849-
session->database_->connection_, sql.data(), sql.size(), &s, nullptr);
3872+
int r = sqlite3_prepare_v3(session->database_->connection_,
3873+
sql.data(),
3874+
sql.size(),
3875+
SQLITE_PREPARE_PERSISTENT,
3876+
&s,
3877+
nullptr);
38503878
StatementPtr stmt_ptr(s);
38513879

38523880
if (r != SQLITE_OK) {

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 6302168

Browse files
araujoguiaduh95
authored andcommitted
sqlite: add stmt persistent flag
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: #62757 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2989311 commit 6302168

3 files changed

Lines changed: 119 additions & 83 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ console.log(query.get());
696696
<!-- YAML
697697
added: v22.5.0
698698
changes:
699+
- version: REPLACEME
700+
pr-url: https://github.com/nodejs/node/pull/62757
701+
description: Add the `persistent` option.
699702
- version: REPLACEME
700703
pr-url: https://github.com/nodejs/node/pull/65157
701704
description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements.
@@ -712,10 +715,14 @@ changes:
712715
database options or `true`.
713716
*`allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters
714717
are ignored. **Default:** inherited from database options or `false`.
718+
*`persistent` {boolean} If `true`, hints to SQLite that this statement will
719+
be retained for a long time and likely reused many times. SQLite currently
720+
responds to this hint by avoiding lookaside memory. Corresponds to the
721+
[`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:**`false`.
715722
* Returns: {StatementSync} The prepared statement.
716723

717724
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
718-
around [`sqlite3_prepare_v2()`][].
725+
around [`sqlite3_prepare_v3()`][].
719726

720727
### `database.createTagStore([maxSize])`
721728

@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized.
18821889
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
18831890
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
18841891
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg
1892+
[`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent
18851893
[`SQLTagStore`]: #class-sqltagstore
18861894
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options
18871895
[`database.createTagStore()`]: #databasecreatetagstoremaxsize
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized.
19071915
[`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html
19081916
[`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html
19091917
[`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html
1910-
[`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html
1918+
[`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html
19111919
[`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html
19121920
[`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html
19131921
[`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html

‎src/node_sqlite.cc‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
15391539
std::optional<bool> use_big_ints;
15401540
std::optional<bool> allow_bare_named_params;
15411541
std::optional<bool> allow_unknown_named_params;
1542+
std::optional<bool> persistent;
15421543

15431544
if (args.Length() > 1 && !args[1]->IsUndefined()) {
15441545
if (!args[1]->IsObject()) {
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
16191620
}
16201621
allow_unknown_named_params = allow_unknown_named_params_v->IsTrue();
16211622
}
1623+
1624+
Local<Value> persistent_v;
1625+
if (!options
1626+
->Get(env->context(),
1627+
FIXED_ONE_BYTE_STRING(env->isolate(), "persistent"))
1628+
.ToLocal(&persistent_v)) {
1629+
return;
1630+
}
1631+
if (!persistent_v->IsUndefined()) {
1632+
if (!persistent_v->IsBoolean()) {
1633+
THROW_ERR_INVALID_ARG_TYPE(
1634+
env->isolate(),
1635+
"The \"options.persistent\" argument must be a boolean.");
1636+
return;
1637+
}
1638+
persistent = persistent_v->IsTrue();
1639+
}
16221640
}
16231641

16241642
Utf8Value sql(env->isolate(), args[0].As<String>());
16251643
sqlite3_stmt* s = nullptr;
1626-
int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr);
1644+
1645+
unsignedint prep_flags =
1646+
persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0;
1647+
1648+
int r =
1649+
sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr);
1650+
16271651
StatementPtr stmt_ptr(s);
16281652

16291653
CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void());
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
38453869

38463870
if (stmt == nullptr) {
38473871
sqlite3_stmt* s = nullptr;
3848-
int r = sqlite3_prepare_v2(
3849-
session->database_->connection_, sql.data(), sql.size(), &s, nullptr);
3872+
int r = sqlite3_prepare_v3(session->database_->connection_,
3873+
sql.data(),
3874+
sql.size(),
3875+
SQLITE_PREPARE_PERSISTENT,
3876+
&s,
3877+
nullptr);
38503878
StatementPtr stmt_ptr(s);
38513879

38523880
if (r != SQLITE_OK) {

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Commit 6302168

Browse files
araujoguiaduh95
authored andcommitted
sqlite: add stmt persistent flag
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: #62757 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2989311 commit 6302168

3 files changed

Lines changed: 119 additions & 83 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ console.log(query.get());
696696
<!-- YAML
697697
added: v22.5.0
698698
changes:
699+
- version: REPLACEME
700+
pr-url: https://github.com/nodejs/node/pull/62757
701+
description: Add the `persistent` option.
699702
- version: REPLACEME
700703
pr-url: https://github.com/nodejs/node/pull/65157
701704
description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements.
@@ -712,10 +715,14 @@ changes:
712715
database options or `true`.
713716
*`allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters
714717
are ignored. **Default:** inherited from database options or `false`.
718+
*`persistent` {boolean} If `true`, hints to SQLite that this statement will
719+
be retained for a long time and likely reused many times. SQLite currently
720+
responds to this hint by avoiding lookaside memory. Corresponds to the
721+
[`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:**`false`.
715722
* Returns: {StatementSync} The prepared statement.
716723

717724
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
718-
around [`sqlite3_prepare_v2()`][].
725+
around [`sqlite3_prepare_v3()`][].
719726

720727
### `database.createTagStore([maxSize])`
721728

@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized.
18821889
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
18831890
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
18841891
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg
1892+
[`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent
18851893
[`SQLTagStore`]: #class-sqltagstore
18861894
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options
18871895
[`database.createTagStore()`]: #databasecreatetagstoremaxsize
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized.
19071915
[`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html
19081916
[`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html
19091917
[`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html
1910-
[`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html
1918+
[`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html
19111919
[`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html
19121920
[`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html
19131921
[`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html

‎src/node_sqlite.cc‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
15391539
std::optional<bool> use_big_ints;
15401540
std::optional<bool> allow_bare_named_params;
15411541
std::optional<bool> allow_unknown_named_params;
1542+
std::optional<bool> persistent;
15421543

15431544
if (args.Length() > 1 && !args[1]->IsUndefined()) {
15441545
if (!args[1]->IsObject()) {
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
16191620
}
16201621
allow_unknown_named_params = allow_unknown_named_params_v->IsTrue();
16211622
}
1623+
1624+
Local<Value> persistent_v;
1625+
if (!options
1626+
->Get(env->context(),
1627+
FIXED_ONE_BYTE_STRING(env->isolate(), "persistent"))
1628+
.ToLocal(&persistent_v)) {
1629+
return;
1630+
}
1631+
if (!persistent_v->IsUndefined()) {
1632+
if (!persistent_v->IsBoolean()) {
1633+
THROW_ERR_INVALID_ARG_TYPE(
1634+
env->isolate(),
1635+
"The \"options.persistent\" argument must be a boolean.");
1636+
return;
1637+
}
1638+
persistent = persistent_v->IsTrue();
1639+
}
16221640
}
16231641

16241642
Utf8Value sql(env->isolate(), args[0].As<String>());
16251643
sqlite3_stmt* s = nullptr;
1626-
int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr);
1644+
1645+
unsignedint prep_flags =
1646+
persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0;
1647+
1648+
int r =
1649+
sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr);
1650+
16271651
StatementPtr stmt_ptr(s);
16281652

16291653
CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void());
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
38453869

38463870
if (stmt == nullptr) {
38473871
sqlite3_stmt* s = nullptr;
3848-
int r = sqlite3_prepare_v2(
3849-
session->database_->connection_, sql.data(), sql.size(), &s, nullptr);
3872+
int r = sqlite3_prepare_v3(session->database_->connection_,
3873+
sql.data(),
3874+
sql.size(),
3875+
SQLITE_PREPARE_PERSISTENT,
3876+
&s,
3877+
nullptr);
38503878
StatementPtr stmt_ptr(s);
38513879

38523880
if (r != SQLITE_OK) {

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 6302168

Browse files
araujoguiaduh95
authored andcommitted
sqlite: add stmt persistent flag
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: #62757 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2989311 commit 6302168

3 files changed

Lines changed: 119 additions & 83 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ console.log(query.get());
696696
<!-- YAML
697697
added: v22.5.0
698698
changes:
699+
- version: REPLACEME
700+
pr-url: https://github.com/nodejs/node/pull/62757
701+
description: Add the `persistent` option.
699702
- version: REPLACEME
700703
pr-url: https://github.com/nodejs/node/pull/65157
701704
description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements.
@@ -712,10 +715,14 @@ changes:
712715
database options or `true`.
713716
*`allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters
714717
are ignored. **Default:** inherited from database options or `false`.
718+
*`persistent` {boolean} If `true`, hints to SQLite that this statement will
719+
be retained for a long time and likely reused many times. SQLite currently
720+
responds to this hint by avoiding lookaside memory. Corresponds to the
721+
[`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:**`false`.
715722
* Returns: {StatementSync} The prepared statement.
716723

717724
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
718-
around [`sqlite3_prepare_v2()`][].
725+
around [`sqlite3_prepare_v3()`][].
719726

720727
### `database.createTagStore([maxSize])`
721728

@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized.
18821889
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
18831890
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
18841891
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg
1892+
[`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent
18851893
[`SQLTagStore`]: #class-sqltagstore
18861894
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options
18871895
[`database.createTagStore()`]: #databasecreatetagstoremaxsize
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized.
19071915
[`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html
19081916
[`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html
19091917
[`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html
1910-
[`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html
1918+
[`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html
19111919
[`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html
19121920
[`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html
19131921
[`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html

‎src/node_sqlite.cc‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
15391539
std::optional<bool> use_big_ints;
15401540
std::optional<bool> allow_bare_named_params;
15411541
std::optional<bool> allow_unknown_named_params;
1542+
std::optional<bool> persistent;
15421543

15431544
if (args.Length() > 1 && !args[1]->IsUndefined()) {
15441545
if (!args[1]->IsObject()) {
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
16191620
}
16201621
allow_unknown_named_params = allow_unknown_named_params_v->IsTrue();
16211622
}
1623+
1624+
Local<Value> persistent_v;
1625+
if (!options
1626+
->Get(env->context(),
1627+
FIXED_ONE_BYTE_STRING(env->isolate(), "persistent"))
1628+
.ToLocal(&persistent_v)) {
1629+
return;
1630+
}
1631+
if (!persistent_v->IsUndefined()) {
1632+
if (!persistent_v->IsBoolean()) {
1633+
THROW_ERR_INVALID_ARG_TYPE(
1634+
env->isolate(),
1635+
"The \"options.persistent\" argument must be a boolean.");
1636+
return;
1637+
}
1638+
persistent = persistent_v->IsTrue();
1639+
}
16221640
}
16231641

16241642
Utf8Value sql(env->isolate(), args[0].As<String>());
16251643
sqlite3_stmt* s = nullptr;
1626-
int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr);
1644+
1645+
unsignedint prep_flags =
1646+
persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0;
1647+
1648+
int r =
1649+
sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr);
1650+
16271651
StatementPtr stmt_ptr(s);
16281652

16291653
CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void());
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
38453869

38463870
if (stmt == nullptr) {
38473871
sqlite3_stmt* s = nullptr;
3848-
int r = sqlite3_prepare_v2(
3849-
session->database_->connection_, sql.data(), sql.size(), &s, nullptr);
3872+
int r = sqlite3_prepare_v3(session->database_->connection_,
3873+
sql.data(),
3874+
sql.size(),
3875+
SQLITE_PREPARE_PERSISTENT,
3876+
&s,
3877+
nullptr);
38503878
StatementPtr stmt_ptr(s);
38513879

38523880
if (r != SQLITE_OK) {

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Commit 6302168

Browse files
araujoguiaduh95
authored andcommitted
sqlite: add stmt persistent flag
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: #62757 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2989311 commit 6302168

3 files changed

Lines changed: 119 additions & 83 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ console.log(query.get());
696696
<!-- YAML
697697
added: v22.5.0
698698
changes:
699+
- version: REPLACEME
700+
pr-url: https://github.com/nodejs/node/pull/62757
701+
description: Add the `persistent` option.
699702
- version: REPLACEME
700703
pr-url: https://github.com/nodejs/node/pull/65157
701704
description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements.
@@ -712,10 +715,14 @@ changes:
712715
database options or `true`.
713716
*`allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters
714717
are ignored. **Default:** inherited from database options or `false`.
718+
*`persistent` {boolean} If `true`, hints to SQLite that this statement will
719+
be retained for a long time and likely reused many times. SQLite currently
720+
responds to this hint by avoiding lookaside memory. Corresponds to the
721+
[`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:**`false`.
715722
* Returns: {StatementSync} The prepared statement.
716723

717724
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
718-
around [`sqlite3_prepare_v2()`][].
725+
around [`sqlite3_prepare_v3()`][].
719726

720727
### `database.createTagStore([maxSize])`
721728

@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized.
18821889
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
18831890
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
18841891
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg
1892+
[`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent
18851893
[`SQLTagStore`]: #class-sqltagstore
18861894
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options
18871895
[`database.createTagStore()`]: #databasecreatetagstoremaxsize
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized.
19071915
[`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html
19081916
[`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html
19091917
[`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html
1910-
[`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html
1918+
[`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html
19111919
[`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html
19121920
[`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html
19131921
[`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html

‎src/node_sqlite.cc‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
15391539
std::optional<bool> use_big_ints;
15401540
std::optional<bool> allow_bare_named_params;
15411541
std::optional<bool> allow_unknown_named_params;
1542+
std::optional<bool> persistent;
15421543

15431544
if (args.Length() > 1 && !args[1]->IsUndefined()) {
15441545
if (!args[1]->IsObject()) {
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
16191620
}
16201621
allow_unknown_named_params = allow_unknown_named_params_v->IsTrue();
16211622
}
1623+
1624+
Local<Value> persistent_v;
1625+
if (!options
1626+
->Get(env->context(),
1627+
FIXED_ONE_BYTE_STRING(env->isolate(), "persistent"))
1628+
.ToLocal(&persistent_v)) {
1629+
return;
1630+
}
1631+
if (!persistent_v->IsUndefined()) {
1632+
if (!persistent_v->IsBoolean()) {
1633+
THROW_ERR_INVALID_ARG_TYPE(
1634+
env->isolate(),
1635+
"The \"options.persistent\" argument must be a boolean.");
1636+
return;
1637+
}
1638+
persistent = persistent_v->IsTrue();
1639+
}
16221640
}
16231641

16241642
Utf8Value sql(env->isolate(), args[0].As<String>());
16251643
sqlite3_stmt* s = nullptr;
1626-
int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr);
1644+
1645+
unsignedint prep_flags =
1646+
persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0;
1647+
1648+
int r =
1649+
sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr);
1650+
16271651
StatementPtr stmt_ptr(s);
16281652

16291653
CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void());
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
38453869

38463870
if (stmt == nullptr) {
38473871
sqlite3_stmt* s = nullptr;
3848-
int r = sqlite3_prepare_v2(
3849-
session->database_->connection_, sql.data(), sql.size(), &s, nullptr);
3872+
int r = sqlite3_prepare_v3(session->database_->connection_,
3873+
sql.data(),
3874+
sql.size(),
3875+
SQLITE_PREPARE_PERSISTENT,
3876+
&s,
3877+
nullptr);
38503878
StatementPtr stmt_ptr(s);
38513879

38523880
if (r != SQLITE_OK) {

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Commit 6302168

Browse files
araujoguiaduh95
authored andcommitted
sqlite: add stmt persistent flag
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: #62757 Reviewed-By: Xuguang Mei <meixuguang@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
1 parent 2989311 commit 6302168

3 files changed

Lines changed: 119 additions & 83 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ console.log(query.get());
696696
<!-- YAML
697697
added: v22.5.0
698698
changes:
699+
- version: REPLACEME
700+
pr-url: https://github.com/nodejs/node/pull/62757
701+
description: Add the `persistent` option.
699702
- version: REPLACEME
700703
pr-url: https://github.com/nodejs/node/pull/65157
701704
description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements.
@@ -712,10 +715,14 @@ changes:
712715
database options or `true`.
713716
*`allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters
714717
are ignored. **Default:** inherited from database options or `false`.
718+
*`persistent` {boolean} If `true`, hints to SQLite that this statement will
719+
be retained for a long time and likely reused many times. SQLite currently
720+
responds to this hint by avoiding lookaside memory. Corresponds to the
721+
[`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:**`false`.
715722
* Returns: {StatementSync} The prepared statement.
716723

717724
Compiles a SQL statement into a [prepared statement][]. This method is a wrapper
718-
around [`sqlite3_prepare_v2()`][].
725+
around [`sqlite3_prepare_v3()`][].
719726

720727
### `database.createTagStore([maxSize])`
721728

@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized.
18821889
[`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html
18831890
[`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html
18841891
[`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg
1892+
[`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent
18851893
[`SQLTagStore`]: #class-sqltagstore
18861894
[`database.applyChangeset()`]: #databaseapplychangesetchangeset-options
18871895
[`database.createTagStore()`]: #databasecreatetagstoremaxsize
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized.
19071915
[`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html
19081916
[`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html
19091917
[`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html
1910-
[`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html
1918+
[`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html
19111919
[`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html
19121920
[`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html
19131921
[`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html

‎src/node_sqlite.cc‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
15391539
std::optional<bool> use_big_ints;
15401540
std::optional<bool> allow_bare_named_params;
15411541
std::optional<bool> allow_unknown_named_params;
1542+
std::optional<bool> persistent;
15421543

15431544
if (args.Length() > 1 && !args[1]->IsUndefined()) {
15441545
if (!args[1]->IsObject()) {
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) {
16191620
}
16201621
allow_unknown_named_params = allow_unknown_named_params_v->IsTrue();
16211622
}
1623+
1624+
Local<Value> persistent_v;
1625+
if (!options
1626+
->Get(env->context(),
1627+
FIXED_ONE_BYTE_STRING(env->isolate(), "persistent"))
1628+
.ToLocal(&persistent_v)) {
1629+
return;
1630+
}
1631+
if (!persistent_v->IsUndefined()) {
1632+
if (!persistent_v->IsBoolean()) {
1633+
THROW_ERR_INVALID_ARG_TYPE(
1634+
env->isolate(),
1635+
"The \"options.persistent\" argument must be a boolean.");
1636+
return;
1637+
}
1638+
persistent = persistent_v->IsTrue();
1639+
}
16221640
}
16231641

16241642
Utf8Value sql(env->isolate(), args[0].As<String>());
16251643
sqlite3_stmt* s = nullptr;
1626-
int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr);
1644+
1645+
unsignedint prep_flags =
1646+
persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0;
1647+
1648+
int r =
1649+
sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr);
1650+
16271651
StatementPtr stmt_ptr(s);
16281652

16291653
CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void());
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
38453869

38463870
if (stmt == nullptr) {
38473871
sqlite3_stmt* s = nullptr;
3848-
int r = sqlite3_prepare_v2(
3849-
session->database_->connection_, sql.data(), sql.size(), &s, nullptr);
3872+
int r = sqlite3_prepare_v3(session->database_->connection_,
3873+
sql.data(),
3874+
sql.size(),
3875+
SQLITE_PREPARE_PERSISTENT,
3876+
&s,
3877+
nullptr);
38503878
StatementPtr stmt_ptr(s);
38513879

38523880
if (r != SQLITE_OK) {

0 commit comments

Comments
 (0)