@gjsify/sqlite 0.64.6 → 0.64.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/database-sync.js +1 -1
- package/lib/esm/execution.js +1 -1
- package/lib/esm/statement-kind.js +1 -0
- package/lib/esm/statement-sync.js +1 -1
- package/lib/types/cte.spec.d.ts +2 -0
- package/lib/types/execution.d.ts +11 -0
- package/lib/types/statement-kind.d.ts +39 -0
- package/package.json +4 -4
package/lib/esm/database-sync.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{ConstructCallRequiredError as e,InvalidArgTypeError as t,InvalidStateError as n,InvalidUrlSchemeError as r,SqliteError as i,isNodeSqliteError as a,sqliteErrorMessage as o}from"./errors.js";import{executeStatement as s}from"./execution.js";import{parseSql as c}from"./parse-sql.js";import{acquire as l,release as u}from"./connection-pool.js";import{convertParameterSyntax as d}from"./parameter-syntax.js";import{sqlRegions as f}from"./sql-regions.js";import{rewriteExistsSubqueries as p}from"./exists-subquery.js";import{
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{ConstructCallRequiredError as e,InvalidArgTypeError as t,InvalidStateError as n,InvalidUrlSchemeError as r,SqliteError as i,isNodeSqliteError as a,sqliteErrorMessage as o}from"./errors.js";import{executeStatement as s}from"./execution.js";import{parseSql as c}from"./parse-sql.js";import{acquire as l,release as u}from"./connection-pool.js";import{convertParameterSyntax as d}from"./parameter-syntax.js";import{sqlRegions as f}from"./sql-regions.js";import{rewriteExistsSubqueries as p}from"./exists-subquery.js";import{providerSql as m,statementKind as h}from"./statement-kind.js";import{StatementSync as g}from"./statement-sync.js";import _ from"@girs/gda-6.0";import{lastPathSeparatorIndex as v}from"@gjsify/utils/core";const y=Symbol.for(`sqlite-type`);function parsePath(e){if(typeof e==`string`){if(e.includes(`\0`))throw new t(`The "path" argument must be a string, Uint8Array, or URL without null bytes.`);return e}if(e instanceof URL){if(e.protocol!==`file:`)throw new r;let n=e.pathname;if(n.includes(`\0`))throw new t(`The "path" argument must be a string, Uint8Array, or URL without null bytes.`);return n}if(e instanceof Uint8Array){for(let n=0;n<e.length;n++)if(e[n]===0)throw new t(`The "path" argument must be a string, Uint8Array, or URL without null bytes.`);return new TextDecoder().decode(e)}throw new t(`The "path" argument must be a string, Uint8Array, or URL without null bytes.`)}function validateOptions(e){if(e===void 0)return{};if(typeof e!=`object`||!e)throw new t(`The "options" argument must be an object.`);let n=e,r={};if(n.open!==void 0){if(typeof n.open!=`boolean`)throw new t(`The "options.open" argument must be a boolean.`);r.open=n.open}if(n.readOnly!==void 0){if(typeof n.readOnly!=`boolean`)throw new t(`The "options.readOnly" argument must be a boolean.`);r.readOnly=n.readOnly}if(n.timeout!==void 0){if(typeof n.timeout!=`number`||!Number.isInteger(n.timeout))throw new t(`The "options.timeout" argument must be an integer.`);r.timeout=n.timeout}if(n.enableForeignKeyConstraints!==void 0){if(typeof n.enableForeignKeyConstraints!=`boolean`)throw new t(`The "options.enableForeignKeyConstraints" argument must be a boolean.`);r.enableForeignKeyConstraints=n.enableForeignKeyConstraints}if(n.enableDoubleQuotedStringLiterals!==void 0){if(typeof n.enableDoubleQuotedStringLiterals!=`boolean`)throw new t(`The "options.enableDoubleQuotedStringLiterals" argument must be a boolean.`);r.enableDoubleQuotedStringLiterals=n.enableDoubleQuotedStringLiterals}if(n.readBigInts!==void 0){if(typeof n.readBigInts!=`boolean`)throw new t(`The "options.readBigInts" argument must be a boolean.`);r.readBigInts=n.readBigInts}if(n.returnArrays!==void 0){if(typeof n.returnArrays!=`boolean`)throw new t(`The "options.returnArrays" argument must be a boolean.`);r.returnArrays=n.returnArrays}if(n.allowBareNamedParameters!==void 0){if(typeof n.allowBareNamedParameters!=`boolean`)throw new t(`The "options.allowBareNamedParameters" argument must be a boolean.`);r.allowBareNamedParameters=n.allowBareNamedParameters}if(n.allowUnknownNamedParameters!==void 0){if(typeof n.allowUnknownNamedParameters!=`boolean`)throw new t(`The "options.allowUnknownNamedParameters" argument must be a boolean.`);r.allowUnknownNamedParameters=n.allowUnknownNamedParameters}if(n.defensive!==void 0){if(typeof n.defensive!=`boolean`)throw new t(`The "options.defensive" argument must be a boolean.`);r.defensive=n.defensive}if(n.allowExtension!==void 0){if(typeof n.allowExtension!=`boolean`)throw new t(`The "options.allowExtension" argument must be a boolean.`);r.allowExtension=n.allowExtension}return r}var DatabaseSync=class{#e=null;#t;#n;#r;#i=!1;constructor(t,n){if(!new.target)throw new e(`DatabaseSync`);this.#t=parsePath(t),this.#n=validateOptions(n),this.#r=this.#t===`:memory:`,this.#n.open!==!1&&this.open()}get[y](){return`node:sqlite`}get isOpen(){return this.#e!==null&&this.#e.is_opened()}get isTransaction(){return this.#a(),this.#i}open(){if(this.isOpen)throw new n(`database is already open`);try{this.#e=l(this.#o(),()=>{let e;if(this.#r)e=_.Connection.new_from_string(`SQLite`,`DB_DIR=;DB_NAME=:memory:`,null,_.ConnectionOptions.NONE);else{let t=v(this.#t),n=t>=0?this.#t.substring(0,t):`.`,r=t>=0?this.#t.substring(t+1):this.#t,i=`DB_DIR=${n};DB_NAME=${r.endsWith(`.db`)?r.slice(0,-3):r}`,a=this.#n.readOnly?_.ConnectionOptions.READ_ONLY:_.ConnectionOptions.NONE;e=_.Connection.new_from_string(`SQLite`,i,null,a)}return e.open(),e})}catch(e){throw this.#e=null,new i(o(e))}this.#c()}close(){if(!this.isOpen)throw new n(`database is not open`);u(this.#o(),this.#e),this.#e=null,this.#i=!1}sqlExec(e){if(this.#a(),typeof e!=`string`)throw new t(`The "sql" argument must be a string.`);try{let t=this.#l(e);for(let e of t){let t=h(e),[n]=this.#s(m(p(e),t));s(this.#e,n,null,()=>void 0,{kind:t})}}catch(e){throw a(e)?e:new i(o(e))}this.#u()}prepare(e,n){if(this.#a(),typeof e!=`string`)throw new t(`The "sql" argument must be a string.`);let[r,s]=d(e),c=h(r);try{this.#s(m(p(r),c))}catch(e){throw a(e)?e:new i(o(e))}let l={readBigInts:this.#n.readBigInts??!1,returnArrays:this.#n.returnArrays??!1,allowBareNamedParameters:this.#n.allowBareNamedParameters??!0,allowUnknownNamedParameters:this.#n.allowUnknownNamedParameters??!1};return g._create(this.#e,e,l,s)}location(e){if(this.#a(),e!==void 0&&typeof e!=`string`)throw new t(`The "dbName" argument must be a string.`);return this.#r?null:this.#t}[Symbol.dispose](){this.isOpen&&this.close()}#a(){if(!this.isOpen)throw new n(`database is not open`)}#o(){return{path:this.#t,isMemory:this.#r,readOnly:this.#n.readOnly??!1}}#s(e){return c(this.#e,e)}#c(){let runPragma=e=>{let[t]=this.#s(e);s(this.#e,t,null,()=>void 0)};this.#n.enableForeignKeyConstraints===!1?runPragma(`PRAGMA foreign_keys = OFF`):runPragma(`PRAGMA foreign_keys = ON`),this.#n.timeout!==void 0&&this.#n.timeout>0&&runPragma(`PRAGMA busy_timeout = ${this.#n.timeout}`)}#l(e){let t=[],n=``,flush=()=>{let e=n.trim();e.length>0&&t.push(e),n=``};for(let t of f(e))if(t.kind===`code`){let r=e.slice(t.start,t.end).split(`;`);n+=r[0];for(let e of r.slice(1))flush(),n+=e}else t.kind===`block-comment`?n+=` `:n+=e.slice(t.start,t.end);return flush(),t}#u(){this.#i=this.#e.get_transaction_status()!==null}};DatabaseSync.prototype.exec=DatabaseSync.prototype.sqlExec;export{DatabaseSync};
|
package/lib/esm/execution.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{SqliteError as e}from"./errors.js";import t from"@girs/gda-6.0";import n from"@girs/gobject-2.0";let r=null;function typeNull(){if(r===null&&(t.value_new_null(),r=n.type_from_name(`GdaNull`),!r))throw new e(`libgda did not register GdaNull`);return r}const i=new Set([`gint`,`guint`,`gint64`,`guint64`,`gboolean`,`GDate`,`GdaTime`,`GDateTime`]);var ColumnTypes=class{types;constructor(e=null){this.types=e}get textColumns(){return(this.types??[]).map(e=>e===n.TYPE_STRING)}};function integerColumns(e){return new ColumnTypes(Array.from({length:e},()=>n.TYPE_STRING))}const a=new Map;function retainPrepared(e,t){for(a.delete(t),a.set(t,e);a.size>512;){let[e,t]=a.entries().next().value;a.delete(e),t.del_prepared_statement(e)}}function releaseStatement(e,t){a.delete(t),e.del_prepared_statement(t)}function releaseRetained(e){for(let[t,n]of a)n===e&&releaseStatement(e,t)}function executeStatement(e,t,n,r,i={}){let a=i.columns,o=null,s=!1;try{o=execute(e,t,n,a),o&&assertTyped(o);let
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{SqliteError as e}from"./errors.js";import t from"@girs/gda-6.0";import n from"@girs/gobject-2.0";let r=null;function typeNull(){if(r===null&&(t.value_new_null(),r=n.type_from_name(`GdaNull`),!r))throw new e(`libgda did not register GdaNull`);return r}const i=new Set([`gint`,`guint`,`gint64`,`guint64`,`gboolean`,`GDate`,`GdaTime`,`GDateTime`]);var ColumnTypes=class{types;constructor(e=null){this.types=e}get textColumns(){return(this.types??[]).map(e=>e===n.TYPE_STRING)}};function integerColumns(e){return new ColumnTypes(Array.from({length:e},()=>n.TYPE_STRING))}const a=new Map;function retainPrepared(e,t){for(a.delete(t),a.set(t,e);a.size>512;){let[e,t]=a.entries().next().value;a.delete(e),t.del_prepared_statement(e)}}function releaseStatement(e,t){a.delete(t),e.del_prepared_statement(t)}function releaseRetained(e){for(let[t,n]of a)n===e&&releaseStatement(e,t)}function executeStatement(e,t,n,r,i={}){let a=i.columns,o=null,s=!1;try{o=execute(e,t,n,a,i.kind),o&&assertTyped(o);let c=r(o,a?.textColumns??[]);return s=!isForwardCursor(t,o,a,i.kind),c}finally{o&&(s&&i.retain&&o.get_n_rows(),releasePreparedStatement(o)),s&&i.retain?retainPrepared(e,t):releaseStatement(e,t)}}function returnsRows(e,n){let r=e.get_statement_type();return r===t.SqlStatementType.SELECT?!0:r===t.SqlStatementType.UNKNOWN?n===`rows`:!1}function isForwardCursor(e,t,n,r){return t!==null&&n===void 0&&returnsRows(e,r)}function execute(e,n,r,i,a){if(returnsRows(n,a))return i?executeTyped(e,n,r,i):e.statement_execute_select_full(n,r,t.StatementModelUsage.CURSOR_FORWARD,null);let o=t.Batch.new();o.add_statement(n);let[s]=e.batch_execute(o,r,t.StatementModelUsage.RANDOM_ACCESS);return!s||s instanceof t.Set?null:s}function executeTyped(t,n,r,i){let a=i.types===null;a&&(i.types=probeColumns(t,n,r));let o=selectWith(t,n,r,i.types);if(matches(o,i.types))return o;if(releasePreparedStatement(o),releaseStatement(t,n),a)throw new e(`the result columns changed between two executions`);i.types=probeColumns(t,n,r);let s=selectWith(t,n,r,i.types);if(matches(s,i.types))return s;throw releasePreparedStatement(s),new e(`the result columns changed between two executions`)}function matches(e,t){if(e.get_n_columns()!==t.length)return!1;for(let r=0;r<t.length;r++){if(t[r]===n.TYPE_STRING)continue;let a=n.type_name(e.describe_column(r).get_g_type());if(a!==null&&i.has(a))return!1}return!0}function selectWith(e,r,i,a){return e.statement_execute_select_full(r,i,t.StatementModelUsage.RANDOM_ACCESS,[...a,n.TYPE_NONE])}function probeColumns(e,r,a){let o=e.statement_execute_select_full(r,a,t.StatementModelUsage.CURSOR_FORWARD,null);try{assertTyped(o);let e=[];for(let t=0;t<o.get_n_columns();t++){let r=n.type_name(o.describe_column(t).get_g_type());e.push(r!==null&&i.has(r)?n.TYPE_STRING:typeNull())}return e}finally{releasePreparedStatement(o),releaseStatement(e,r)}}function assertTyped(t){let n=t.get_n_columns();for(let r=0;r<n;r++){let n=t.describe_column(r);if(n&&!n.get_g_type())throw new e(`libgda could not type a result column; the connection has lost its SQLite provider`)}}function releasePreparedStatement(e){e.prepared_stmt=null}export{ColumnTypes,executeStatement,integerColumns,releaseRetained,releaseStatement};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{sqlRegions as e}from"./sql-regions.js";const t=new Set([`SELECT`,`VALUES`]),n=new Set([`INSERT`,`UPDATE`,`DELETE`,`REPLACE`]);function statementKind(e){let r=tokenize(e),i=r[0];if(!i||i.kind!==`word`)return`other`;let a=i.text.toUpperCase()===`WITH`?verbAfterCtes(r):i.text.toUpperCase();return a===null?`other`:t.has(a)?`rows`:n.has(a)?`write`:`other`}function providerSql(e,t){if(t!==`rows`)return e;let n=tokenize(e)[0];if(n&&n.kind===`word`&&n.text.toUpperCase()===`SELECT`)return e;let r=splitTrailingSemicolon(e);return`SELECT * FROM (${endsInsideLineComment(r.body)?`${r.body}\n`:r.body})${r.tail}`}function verbAfterCtes(e){let t=1;for(isWord(e[t],`RECURSIVE`)&&t++;;){if(!e[t]||e[t].kind!==`word`&&e[t].kind!==`quoted`)return null;if(t++,isPunct(e[t],`(`)){let n=matchingParen(e,t);if(n<0)return null;t=n+1}if(!isWord(e[t],`AS`)||(t++,isWord(e[t],`NOT`)&&t++,isWord(e[t],`MATERIALIZED`)&&t++,!isPunct(e[t],`(`)))return null;let n=matchingParen(e,t);if(n<0)return null;if(t=n+1,isPunct(e[t],`,`)){t++;continue}let r=e[t];return r&&r.kind===`word`?r.text.toUpperCase():null}}function matchingParen(e,t){let n=0;for(let r=t;r<e.length;r++)if(e[r].kind===`punct`){if(e[r].text===`(`)n++;else if(e[r].text===`)`&&--n===0)return r}return-1}function isWord(e,t){return e!==void 0&&e.kind===`word`&&e.text.toUpperCase()===t}function isPunct(e,t){return e!==void 0&&e.kind===`punct`&&e.text===t}function splitTrailingSemicolon(t){let n=e(t),r=-1;for(let e of n)if(e.kind===`code`)for(let n=e.start;n<e.end;n++)t[n]===`;`&&(r=n);if(r<0)return{body:t,tail:``};for(let e of n){let n=Math.max(e.start,r+1);if(!(n>=e.end)){if(e.kind===`code`){if(t.slice(n,e.end).trim()!==``)return{body:t,tail:``}}else if(e.kind===`quoted`)return{body:t,tail:``}}}return{body:t.slice(0,r),tail:t.slice(r)}}function endsInsideLineComment(t){let n=e(t),r=n[n.length-1];return r!==void 0&&r.kind===`line-comment`&&r.end===t.length}function tokenize(t){let n=[];for(let r of e(t)){if(r.kind===`quoted`){n.push({kind:`quoted`,text:t.slice(r.start,r.end)});continue}if(r.kind!==`code`)continue;let e=r.start;for(;e<r.end;){let i=t[e];if(isSpace(i)){e++;continue}if(i===`#`&&t[e+1]===`#`){let i=placeholderEnd(t,e,r.end);n.push({kind:`param`,text:t.slice(e,i)}),e=i;continue}if(i===`?`){let i=e+1;for(;i<r.end&&t[i]>=`0`&&t[i]<=`9`;)i++;n.push({kind:`param`,text:t.slice(e,i)}),e=i;continue}if((i===`:`||i===`$`||i===`@`)&&isNameStart(t[e+1])){let i=e+1;for(;i<r.end&&isNamePart(t[i]);)i++;n.push({kind:`param`,text:t.slice(e,i)}),e=i;continue}if(isNameStart(i)){let i=e+1;for(;i<r.end&&isNamePart(t[i]);)i++;n.push({kind:`word`,text:t.slice(e,i)}),e=i;continue}n.push({kind:`punct`,text:i}),e++}}return n}function placeholderEnd(e,t,n){let r=t+2;for(;r<n&&isNamePart(e[r]);)r++;if(e[r]===`:`&&e[r+1]===`:`)for(r+=2;r<n&&isNamePart(e[r]);)r++;return r}function isSpace(e){return e!==void 0&&/\s/.test(e)}function isNameStart(e){return e!==void 0&&/[A-Za-z_]/.test(e)}function isNamePart(e){return e!==void 0&&/[A-Za-z0-9_$]/.test(e)}export{providerSql,statementKind};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{IllegalConstructorError as e,InvalidArgTypeError as t,InvalidArgValueError as n,SqliteError as r,isNodeSqliteError as i,sqliteErrorMessage as a}from"./errors.js";import{ColumnTypes as o,executeStatement as s,integerColumns as c,releaseStatement as l}from"./execution.js";import{parseSql as u}from"./parse-sql.js";import{readAllRows as d,readFirstRow as f}from"./data-model-reader.js";import{convertParameterSyntax as p}from"./parameter-syntax.js";import{rewriteExistsSubqueries as m}from"./exists-subquery.js";import{
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{IllegalConstructorError as e,InvalidArgTypeError as t,InvalidArgValueError as n,SqliteError as r,isNodeSqliteError as i,sqliteErrorMessage as a}from"./errors.js";import{ColumnTypes as o,executeStatement as s,integerColumns as c,releaseStatement as l}from"./execution.js";import{parseSql as u}from"./parse-sql.js";import{readAllRows as d,readFirstRow as f}from"./data-model-reader.js";import{convertParameterSyntax as p}from"./parameter-syntax.js";import{rewriteExistsSubqueries as m}from"./exists-subquery.js";import{providerSql as h,statementKind as g}from"./statement-kind.js";import{bindHolders as _,releaseHolders as v}from"./param-binding.js";const y=Symbol(`StatementSync.internal`),b=`SELECT changes(), last_insert_rowid()`,x=c(2),S=new WeakMap;function counterStatement(e){let t=S.get(e);if(t)return t;let[n]=u(e,b);return S.set(e,n),n}function isNamedArgObject(e){return typeof e==`object`&&!!e&&!(e instanceof Uint8Array)&&!ArrayBuffer.isView(e)}function validateBindValue(e,n){if(e==null)return;let r=typeof e;if(!(r===`number`||r===`bigint`||r===`string`||r===`boolean`)&&!(e instanceof Uint8Array||e instanceof ArrayBuffer)&&!ArrayBuffer.isView(e))throw new t(`Provided value cannot be bound to SQLite parameter ${n}.`)}function holderBinding(e){if(typeof e==`string`)return{type:`gchararray`,value:e};if(typeof e==`number`)return{type:`gdouble`,value:e};if(typeof e==`bigint`){if(e>9223372036854775807n||e<-9223372036854775808n)throw new n(`BigInt value is too large to bind.`);return{type:`gint64`,value:e}}return typeof e==`boolean`?{type:`gint64`,value:+!!e}:null}function sqlLiteral(e){if(e instanceof Uint8Array){let t=``;for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,`0`);return`X'`+t+`'`}return ArrayBuffer.isView(e)?sqlLiteral(new Uint8Array(e.buffer)):`NULL`}var C=class StatementSync{#e;#t;#n;#r;#i;#a;#o;#s=new o;#c;#l=new Map;constructor(t,n,r,i,a){if(t!==y)throw new e;this.#e=n,this.#t=r,this.#n=a,this.#c=g(r),this.#r=i.readBigInts??!1,this.#i=i.returnArrays??!1,this.#a=i.allowBareNamedParameters??!0,this.#o=i.allowUnknownNamedParameters??!1}static _create(e,t,n,r){return new StatementSync(y,e,t,n,r)}get sourceSQL(){return this.#t}get expandedSQL(){return this.#t}#u(e){return{readBigInts:this.#r,returnArrays:this.#i,textColumns:e}}#d(){let e=-1;for(let t of this.#n)t.position>e&&(e=t.position);return e}#f(e){let t=new Map;if(this.#n.length===0){if(e.length>0&&!isNamedArgObject(e[0]))throw new r(`column index out of range`,25,`column index out of range`);return{sql:this.#t,bindings:t}}let n=null,i=e;e.length>0&&isNamedArgObject(e[0])&&(n=e[0],i=e.slice(1));let a=new Map;if(n){for(let e of this.#n){if(e.position>=0)continue;let t=e.originalName,i,o=!1;if(t in n&&(i=n[t],o=!0),!o&&this.#a){let e=t.replace(/^[$:@]/,``);e in n&&(i=n[e],o=!0)}if(!o&&!this.#a){let e=t.replace(/^[$:@]/,``);if(e in n)throw new r(`Unknown named parameter '${e}'`,0,`Unknown named parameter '${e}'`)}o&&(validateBindValue(i,this.#n.indexOf(e)+1),a.set(e.gdaId,i))}if(!this.#o){let e=new Set;for(let t of this.#n)t.position>=0||(e.add(t.originalName),e.add(t.originalName.replace(/^[$:@]/,``)));for(let t of Object.keys(n))if(!e.has(t)&&!e.has(t.replace(/^[$:@]/,``)))throw new r(`Unknown named parameter '${t}'`,0,`Unknown named parameter '${t}'`)}for(let e=0;e<i.length;e++){if(e>this.#d())throw new r(`column index out of range`,25,`column index out of range`);validateBindValue(i[e],e+1),a.set(`p${e}`,i[e])}}else{let e=this.#d()+1;if(i.length>e&&e>0)throw new r(`column index out of range`,25,`column index out of range`);for(let t=0;t<Math.min(i.length,e);t++)validateBindValue(i[t],t+1),a.set(`p${t}`,i[t])}let[o]=p(this.#t,e=>{let n=a.get(e.gdaId),r=holderBinding(n);return r?(t.set(e.gdaId,r),`##${e.gdaId}::${r.type}`):sqlLiteral(n)});return{sql:o,bindings:t}}#p(e){let t=this.#l.get(e);if(t)return this.#l.delete(e),this.#l.set(e,t),t;let n=u(this.#e,h(m(e),this.#c));for(this.#l.set(e,n);this.#l.size>8;){let[e,[t]]=this.#l.entries().next().value;this.#l.delete(e),l(this.#e,t)}return n}#m(e,t,n){let{sql:o,bindings:c}=this.#f(e),l=null;try{let e;return[e,l]=this.#p(o),_(l,c),s(this.#e,e,l,t,{columns:n,retain:!0,kind:this.#c})}catch(e){throw i(e)?e:new r(a(e))}finally{v(l,c)}}run(...e){this.#m(e,()=>void 0);let[t,n]=s(this.#e,counterStatement(this.#e),null,e=>{if(!e||e.get_n_rows()===0)throw new r(`${b} returned no row`);return[BigInt(e.get_value_at(0,0)),BigInt(e.get_value_at(1,0))]},{columns:x,retain:!0});return this.#r?{changes:t,lastInsertRowid:n}:{changes:Number(t),lastInsertRowid:Number(n)}}get(...e){return this.#m(e,(e,t)=>{if(!(!e||e.get_n_rows()===0))return f(e,this.#u(t))},this.#s)}all(...e){return this.#m(e,(e,t)=>e?d(e,this.#u(t)):[],this.#s)}setReadBigInts(e){if(typeof e!=`boolean`)throw new t(`The "readBigInts" argument must be a boolean.`);this.#r=e}setReturnArrays(e){if(typeof e!=`boolean`)throw new t(`The "returnArrays" argument must be a boolean.`);this.#i=e}setAllowBareNamedParameters(e){if(typeof e!=`boolean`)throw new t(`The "allowBareNamedParameters" argument must be a boolean.`);this.#a=e}setAllowUnknownNamedParameters(e){if(typeof e!=`boolean`)throw new t(`The "allowUnknownNamedParameters" argument must be a boolean.`);this.#o=e}};export{C as StatementSync};
|
package/lib/types/execution.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Gda from '@girs/gda-6.0';
|
|
2
2
|
import GObject from '@girs/gobject-2.0';
|
|
3
|
+
import type { StatementKind } from './statement-kind.ts';
|
|
3
4
|
/**
|
|
4
5
|
* How the result columns of one prepared statement are read, remembered between its
|
|
5
6
|
* executions.
|
|
@@ -51,6 +52,16 @@ export interface ExecuteOptions {
|
|
|
51
52
|
* reuse asks for this; a one-shot statement would just occupy the bound.
|
|
52
53
|
*/
|
|
53
54
|
retain?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* What the statement does, for the statements libgda cannot classify.
|
|
57
|
+
*
|
|
58
|
+
* A statement with a CTE reaches libgda as UNKNOWN whatever it does (see
|
|
59
|
+
* `statement-kind.ts`), so the row-vs-rows decision cannot be left to
|
|
60
|
+
* `get_statement_type()` alone — the answer comes from the SQL text instead. A
|
|
61
|
+
* caller that does not know the statement leaves it out, and an UNKNOWN statement
|
|
62
|
+
* then keeps the path it had.
|
|
63
|
+
*/
|
|
64
|
+
kind?: StatementKind;
|
|
54
65
|
}
|
|
55
66
|
/**
|
|
56
67
|
* Execute `stmt`, hand its result to `read`, and leave NOTHING behind on the connection.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a statement does.
|
|
3
|
+
*
|
|
4
|
+
* `other` is everything this package does not read rows from and does not treat as a
|
|
5
|
+
* write: a PRAGMA, a CREATE, an EXPLAIN. Those keep the path they had before — see
|
|
6
|
+
* `returnsRows()` in execution.ts.
|
|
7
|
+
*/
|
|
8
|
+
export type StatementKind = 'rows' | 'write' | 'other';
|
|
9
|
+
/**
|
|
10
|
+
* Does this statement return rows, write, or neither?
|
|
11
|
+
*
|
|
12
|
+
* The answer comes from the SQL TEXT, because libgda's own classification cannot be
|
|
13
|
+
* asked: a statement with a CTE is UNKNOWN to it whatever it does (see the header).
|
|
14
|
+
*
|
|
15
|
+
* A statement that does not start with `WITH` is classified by its first word. A
|
|
16
|
+
* `WITH` statement is classified by the verb that follows its CTE definitions — the
|
|
17
|
+
* CTEs themselves may hide anything, so the verb is what decides, and `WITH q AS
|
|
18
|
+
* (SELECT 1) INSERT INTO t SELECT * FROM q` is a WRITE.
|
|
19
|
+
*/
|
|
20
|
+
export declare function statementKind(sql: string): StatementKind;
|
|
21
|
+
/**
|
|
22
|
+
* The text the provider must be given for a statement of this kind.
|
|
23
|
+
*
|
|
24
|
+
* The provider dispatches on the FIRST WORD of the text it renders (see the header), so
|
|
25
|
+
* a statement that returns rows but does not start with `SELECT` has to be stated in a
|
|
26
|
+
* shape that does: `SELECT * FROM ( … )` — a derived table, which SQLite accepts around
|
|
27
|
+
* a whole CTE statement. The rows and their column names are the inner statement's:
|
|
28
|
+
* SQLite names the columns of a subquery after the ones its own SELECT produced.
|
|
29
|
+
*
|
|
30
|
+
* A statement that already starts with `SELECT` is handed over unchanged, and so is
|
|
31
|
+
* every statement that does not return rows: a write must stay a write, and the
|
|
32
|
+
* provider runs it as a command — which is what an INSERT, an UPDATE and a DELETE
|
|
33
|
+
* need.
|
|
34
|
+
*
|
|
35
|
+
* A trailing `;` moves OUT of the parentheses: it would end the statement there and
|
|
36
|
+
* leave the parenthesis unclosed ("incomplete input"). SQLite does not need it, and
|
|
37
|
+
* libgda's parser drops a trailing `;` of its own accord.
|
|
38
|
+
*/
|
|
39
|
+
export declare function providerSql(sql: string, kind: StatementKind): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/sqlite",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.7",
|
|
4
4
|
"description": "Node.js sqlite module for Gjs using libgda",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"libgda"
|
|
41
41
|
],
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@gjsify/cli": "^0.64.
|
|
43
|
+
"@gjsify/cli": "^0.64.7",
|
|
44
44
|
"@gjsify/node-gi": "file:../../../packages/node-gi/node-gi",
|
|
45
|
-
"@gjsify/unit": "^0.64.
|
|
45
|
+
"@gjsify/unit": "^0.64.7",
|
|
46
46
|
"@types/node": "^25.9.2",
|
|
47
47
|
"typescript": "^6.0.3"
|
|
48
48
|
},
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@girs/gio-2.0": "5.4.0",
|
|
52
52
|
"@girs/glib-2.0": "5.4.0",
|
|
53
53
|
"@girs/gobject-2.0": "5.4.0",
|
|
54
|
-
"@gjsify/utils": "^0.64.
|
|
54
|
+
"@gjsify/utils": "^0.64.7"
|
|
55
55
|
},
|
|
56
56
|
"gjsify": {
|
|
57
57
|
"runtimes": {
|