@gjsify/sqlite 0.51.1 → 0.52.0

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.
@@ -1,2 +1,2 @@
1
- import"./_virtual/_rolldown/runtime.js";import{ConstructCallRequiredError as e,InvalidArgTypeError as t,InvalidStateError as n,InvalidUrlSchemeError as r,SqliteError as i}from"./errors.js";import{convertParameterSyntax as a}from"./parameter-syntax.js";import{parseSql as o}from"./parse-sql.js";import{StatementSync as s}from"./statement-sync.js";import c from"@girs/gda-6.0";import{lastPathSeparatorIndex as l}from"@gjsify/utils/core";const u=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[u](){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{if(this.#r)this.#e=c.Connection.new_from_string(`SQLite`,`DB_DIR=;DB_NAME=:memory:`,null,c.ConnectionOptions.NONE);else{let e=l(this.#t),t=e>=0?this.#t.substring(0,e):`.`,n=e>=0?this.#t.substring(e+1):this.#t,r=`DB_DIR=${t};DB_NAME=${n.endsWith(`.db`)?n.slice(0,-3):n}`,i=this.#n.readOnly?c.ConnectionOptions.READ_ONLY:c.ConnectionOptions.NONE;this.#e=c.Connection.new_from_string(`SQLite`,r,null,i)}this.#e.open()}catch(e){throw this.#e=null,new i(e instanceof Error?e.message:String(e))}this.#s()}close(){if(!this.isOpen)throw new n(`database is not open`);this.#e.close(),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]=this.#o(e);this.#c(t)}}catch(e){throw e instanceof i||e instanceof n||e instanceof t?e:new i(e instanceof Error?e.message:String(e))}this.#u(e)}prepare(e,n){if(this.#a(),typeof e!=`string`)throw new t(`The "sql" argument must be a string.`);let[r,o]=a(e);try{this.#o(r)}catch(e){throw e instanceof i||e instanceof t?e:new i(e instanceof Error?e.message:String(e))}let c={readBigInts:this.#n.readBigInts??!1,returnArrays:this.#n.returnArrays??!1,allowBareNamedParameters:this.#n.allowBareNamedParameters??!0,allowUnknownNamedParameters:this.#n.allowUnknownNamedParameters??!1};return s._create(this.#e,e,c,o)}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](){if(this.isOpen)try{this.close()}catch{}}#a(){if(!this.isOpen)throw new n(`database is not open`)}#o(e){return o(this.#e,e)}#s(){let e=this.#e,runPragma=t=>{let[n]=this.#o(t);e.statement_execute_select(n,null)};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}`)}#c(e){if(e.get_statement_type()===c.SqlStatementType.SELECT)this.#e.statement_execute_select(e,null);else try{this.#e.statement_execute_non_select(e,null)}catch{this.#e.statement_execute_select(e,null)}}#l(e){let t=[],n=``,r=e.length,i=0,flush=()=>{let e=n.trim();e.length>0&&t.push(e),n=``};for(;i<r;){let t=e[i],a=e[i+1];if(t===`-`&&a===`-`){let t=i+2;for(;t<r&&e[t]!==`
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{convertParameterSyntax as s}from"./parameter-syntax.js";import{parseSql as c}from"./parse-sql.js";import{StatementSync as l}from"./statement-sync.js";import u from"@girs/gda-6.0";import{lastPathSeparatorIndex as d}from"@gjsify/utils/core";const f=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[f](){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{if(this.#r)this.#e=u.Connection.new_from_string(`SQLite`,`DB_DIR=;DB_NAME=:memory:`,null,u.ConnectionOptions.NONE);else{let e=d(this.#t),t=e>=0?this.#t.substring(0,e):`.`,n=e>=0?this.#t.substring(e+1):this.#t,r=`DB_DIR=${t};DB_NAME=${n.endsWith(`.db`)?n.slice(0,-3):n}`,i=this.#n.readOnly?u.ConnectionOptions.READ_ONLY:u.ConnectionOptions.NONE;this.#e=u.Connection.new_from_string(`SQLite`,r,null,i)}this.#e.open()}catch(e){throw this.#e=null,new i(o(e))}this.#s()}close(){if(!this.isOpen)throw new n(`database is not open`);this.#e.close(),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]=this.#o(e);this.#c(t)}}catch(e){throw a(e)?e:new i(o(e))}this.#u(e)}prepare(e,n){if(this.#a(),typeof e!=`string`)throw new t(`The "sql" argument must be a string.`);let[r,c]=s(e);try{this.#o(r)}catch(e){throw a(e)?e:new i(o(e))}let u={readBigInts:this.#n.readBigInts??!1,returnArrays:this.#n.returnArrays??!1,allowBareNamedParameters:this.#n.allowBareNamedParameters??!0,allowUnknownNamedParameters:this.#n.allowUnknownNamedParameters??!1};return l._create(this.#e,e,u,c)}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(e){return c(this.#e,e)}#s(){let e=this.#e,runPragma=t=>{let[n]=this.#o(t);e.statement_execute_select(n,null)};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}`)}#c(e){if(e.get_statement_type()===u.SqlStatementType.SELECT)this.#e.statement_execute_select(e,null);else try{this.#e.statement_execute_non_select(e,null)}catch{this.#e.statement_execute_select(e,null)}}#l(e){let t=[],n=``,r=e.length,i=0,flush=()=>{let e=n.trim();e.length>0&&t.push(e),n=``};for(;i<r;){let t=e[i],a=e[i+1];if(t===`-`&&a===`-`){let t=i+2;for(;t<r&&e[t]!==`
2
2
  `;)t++;i=t;continue}if(t===`/`&&a===`*`){let t=i+2;for(;t<r&&!(e[t]===`*`&&e[t+1]===`/`);)t++;i=t<r?t+2:r,n+=` `;continue}if(t===`'`||t===`"`||t==="`"||t===`[`){let a=t===`[`?`]`:t,o=t!==`[`,s=i+1;for(n+=t;s<r;){if(e[s]===a){if(o&&e[s+1]===a){n+=a+a,s+=2;continue}n+=a,s++;break}n+=e[s],s++}i=s;continue}if(t===`;`){flush(),i++;continue}n+=t,i++}return flush(),t}#u(e){let t=e.trim().toUpperCase();/\bBEGIN\b/.test(t)&&(this.#i=!0),(/\bCOMMIT\b/.test(t)||/\bROLLBACK\b/.test(t))&&(this.#i=!1)}};DatabaseSync.prototype.exec=DatabaseSync.prototype.sqlExec;export{DatabaseSync};
package/lib/esm/errors.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";var SqliteError=class extends Error{code=`ERR_SQLITE_ERROR`;errcode;errstr;constructor(e,t=0,n=``){super(e),this.name=`SqliteError`,this.errcode=t,this.errstr=n||e}},InvalidStateError=class extends Error{code=`ERR_INVALID_STATE`;constructor(e){super(e),this.name=`InvalidStateError`}},InvalidArgTypeError=class extends TypeError{code=`ERR_INVALID_ARG_TYPE`;constructor(e){super(e),this.name=`InvalidArgTypeError`}},InvalidArgValueError=class extends Error{code=`ERR_INVALID_ARG_VALUE`;constructor(e){super(e),this.name=`InvalidArgValueError`}},OutOfRangeError=class extends RangeError{code=`ERR_OUT_OF_RANGE`;constructor(e){super(e),this.name=`OutOfRangeError`}},ConstructCallRequiredError=class extends TypeError{code=`ERR_CONSTRUCT_CALL_REQUIRED`;constructor(e){super(`Cannot call constructor without \`new\`: ${e}`),this.name=`ConstructCallRequiredError`}},InvalidUrlSchemeError=class extends TypeError{code=`ERR_INVALID_URL_SCHEME`;constructor(e=`The URL must be of scheme file:`){super(e),this.name=`InvalidUrlSchemeError`}},IllegalConstructorError=class extends TypeError{code=`ERR_ILLEGAL_CONSTRUCTOR`;constructor(){super(`Illegal constructor`),this.name=`IllegalConstructorError`}};export{ConstructCallRequiredError,IllegalConstructorError,InvalidArgTypeError,InvalidArgValueError,InvalidStateError,InvalidUrlSchemeError,OutOfRangeError,SqliteError};
1
+ import"./_virtual/_rolldown/runtime.js";var SqliteError=class extends Error{code=`ERR_SQLITE_ERROR`;errcode;errstr;constructor(e,t=0,n=``){super(e),this.name=`SqliteError`,this.errcode=t,this.errstr=n||e}},InvalidStateError=class extends Error{code=`ERR_INVALID_STATE`;constructor(e){super(e),this.name=`InvalidStateError`}},InvalidArgTypeError=class extends TypeError{code=`ERR_INVALID_ARG_TYPE`;constructor(e){super(e),this.name=`InvalidArgTypeError`}},InvalidArgValueError=class extends Error{code=`ERR_INVALID_ARG_VALUE`;constructor(e){super(e),this.name=`InvalidArgValueError`}},OutOfRangeError=class extends RangeError{code=`ERR_OUT_OF_RANGE`;constructor(e){super(e),this.name=`OutOfRangeError`}},ConstructCallRequiredError=class extends TypeError{code=`ERR_CONSTRUCT_CALL_REQUIRED`;constructor(e){super(`Cannot call constructor without \`new\`: ${e}`),this.name=`ConstructCallRequiredError`}},InvalidUrlSchemeError=class extends TypeError{code=`ERR_INVALID_URL_SCHEME`;constructor(e=`The URL must be of scheme file:`){super(e),this.name=`InvalidUrlSchemeError`}},IllegalConstructorError=class extends TypeError{code=`ERR_ILLEGAL_CONSTRUCTOR`;constructor(){super(`Illegal constructor`),this.name=`IllegalConstructorError`}};function isNodeSqliteError(e){return e instanceof SqliteError||e instanceof InvalidStateError||e instanceof InvalidArgTypeError||e instanceof InvalidArgValueError||e instanceof OutOfRangeError||e instanceof ConstructCallRequiredError||e instanceof InvalidUrlSchemeError||e instanceof IllegalConstructorError}function sqliteErrorMessage(e){let t=e?.message;return typeof t==`string`?t:String(e)}export{ConstructCallRequiredError,IllegalConstructorError,InvalidArgTypeError,InvalidArgValueError,InvalidStateError,InvalidUrlSchemeError,OutOfRangeError,SqliteError,isNodeSqliteError,sqliteErrorMessage};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{IllegalConstructorError as e,InvalidArgTypeError as t,InvalidArgValueError as n,SqliteError as r}from"./errors.js";import{readAllRows as i,readFirstRow as a}from"./data-model-reader.js";import{convertParameterSyntax as o}from"./parameter-syntax.js";import{parseSql as s}from"./parse-sql.js";import{bindStringHolders as c}from"./param-binding.js";import l from"@girs/gda-6.0";const u=Symbol(`StatementSync.internal`);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 sqlLiteral(e){if(e==null)return`NULL`;if(typeof e==`number`){if(Number.isNaN(e))return`NULL`;if(e===1/0)return`9e999`;if(e===-1/0)return`-9e999`;let t=String(e);return Number.isInteger(e)&&!t.includes(`e`)&&!t.includes(`E`)?`${t}.0`:t}if(typeof e==`boolean`)return e?`1`:`0`;if(typeof e==`bigint`){if(e>9223372036854775807n||e<-9223372036854775808n)throw new n(`BigInt value is too large to bind.`);return String(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 d=class StatementSync{#e;#t;#n;#r;#i;#a;#o;constructor(t,n,r,i,a){if(t!==u)throw new e;this.#e=n,this.#t=r,this.#n=a,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(u,e,t,n,r)}get sourceSQL(){return this.#t}get expandedSQL(){return this.#t}#s(){return{readBigInts:this.#r,returnArrays:this.#i}}#c(){let e=-1;for(let t of this.#n)t.position>e&&(e=t.position);return e}#l(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,strings: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.#c())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.#c()+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[s]=o(this.#t,e=>{let n=a.get(e.gdaId);return typeof n==`string`?(t.set(e.gdaId,n),`##${e.gdaId}::string`):sqlLiteral(n)});return{sql:s,strings:t}}#u(e){let{sql:t,strings:n}=this.#l(e),[r,i]=s(this.#e,t);if(c(i,n),r.get_statement_type()===l.SqlStatementType.SELECT)return{model:this.#e.statement_execute_select(r,i),isSelect:!0};try{return this.#e.statement_execute_non_select(r,i),{model:null,isSelect:!1}}catch{return{model:this.#e.statement_execute_select(r,i),isSelect:!0}}}run(...e){this.#u(e);let t=0,n=0;try{let e=this.#e.execute_select_command(`SELECT changes()`);e&&e.get_n_rows()>0&&(t=e.get_value_at(0,0))}catch{}try{let e=this.#e.execute_select_command(`SELECT last_insert_rowid()`);e&&e.get_n_rows()>0&&(n=e.get_value_at(0,0))}catch{}return this.#r&&(t=BigInt(t),n=BigInt(n)),{changes:t,lastInsertRowid:n}}get(...e){try{let{model:t}=this.#u(e);return!t||t.get_n_rows()===0?void 0:a(t,this.#s())}catch{return}}all(...e){try{let{model:t}=this.#u(e);return t?i(t,this.#s()):[]}catch{return[]}}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{d as StatementSync};
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{readAllRows as o,readFirstRow as s}from"./data-model-reader.js";import{convertParameterSyntax as c}from"./parameter-syntax.js";import{parseSql as l}from"./parse-sql.js";import{bindStringHolders as u}from"./param-binding.js";import d from"@girs/gda-6.0";const f=Symbol(`StatementSync.internal`);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 sqlLiteral(e){if(e==null)return`NULL`;if(typeof e==`number`){if(Number.isNaN(e))return`NULL`;if(e===1/0)return`9e999`;if(e===-1/0)return`-9e999`;let t=String(e);return Number.isInteger(e)&&!t.includes(`e`)&&!t.includes(`E`)?`${t}.0`:t}if(typeof e==`boolean`)return e?`1`:`0`;if(typeof e==`bigint`){if(e>9223372036854775807n||e<-9223372036854775808n)throw new n(`BigInt value is too large to bind.`);return String(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 p=class StatementSync{#e;#t;#n;#r;#i;#a;#o;constructor(t,n,r,i,a){if(t!==f)throw new e;this.#e=n,this.#t=r,this.#n=a,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(f,e,t,n,r)}get sourceSQL(){return this.#t}get expandedSQL(){return this.#t}#s(){return{readBigInts:this.#r,returnArrays:this.#i}}#c(){let e=-1;for(let t of this.#n)t.position>e&&(e=t.position);return e}#l(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,strings: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.#c())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.#c()+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]=c(this.#t,e=>{let n=a.get(e.gdaId);return typeof n==`string`?(t.set(e.gdaId,n),`##${e.gdaId}::string`):sqlLiteral(n)});return{sql:o,strings:t}}#u(e){let{sql:t,strings:n}=this.#l(e);try{let[e,r]=l(this.#e,t);if(u(r,n),e.get_statement_type()===d.SqlStatementType.SELECT)return{model:this.#e.statement_execute_select(e,r),isSelect:!0};try{return this.#e.statement_execute_non_select(e,r),{model:null,isSelect:!1}}catch{return{model:this.#e.statement_execute_select(e,r),isSelect:!0}}}catch(e){throw i(e)?e:new r(a(e))}}run(...e){this.#u(e);let t=0,n=0,r=this.#e.execute_select_command(`SELECT changes()`);r&&r.get_n_rows()>0&&(t=r.get_value_at(0,0));let i=this.#e.execute_select_command(`SELECT last_insert_rowid()`);return i&&i.get_n_rows()>0&&(n=i.get_value_at(0,0)),this.#r&&(t=BigInt(t),n=BigInt(n)),{changes:t,lastInsertRowid:n}}get(...e){let{model:t}=this.#u(e);if(!(!t||t.get_n_rows()===0))return s(t,this.#s())}all(...e){let{model:t}=this.#u(e);return t?o(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{p as StatementSync};
@@ -32,3 +32,26 @@ export declare class IllegalConstructorError extends TypeError {
32
32
  code: string;
33
33
  constructor();
34
34
  }
35
+ /**
36
+ * Whether `cause` is one of the errors above — already Node-shaped, so a catch that
37
+ * translates libgda's must let it through untouched.
38
+ *
39
+ * **The discriminator cannot be `instanceof Error`.** libgda reports through
40
+ * `GLib.Error`, and that is a boxed GObject value under GJS but a real `Error`
41
+ * SUBCLASS under `@gjsify/node-gi` (`class GLibError extends Error` in its `gi.js`)
42
+ * — the bridge that runs this very package's suite on Node. An `instanceof Error`
43
+ * test would therefore wrap on one host and pass the raw GError through on the
44
+ * other, and the leg that disagreed is the one nobody runs locally.
45
+ */
46
+ export declare function isNodeSqliteError(cause: unknown): boolean;
47
+ /**
48
+ * The message libgda actually reported.
49
+ *
50
+ * An `e instanceof Error ? e.message : String(e)` extraction takes the `String(e)`
51
+ * branch for a GJS `GLib.Error` and yields
52
+ * `"GLib.Error gda_server_provider_error: no such table: t"`; under node-gi the same
53
+ * expression takes the OTHER branch and yields the bare message. The `message`
54
+ * property alone is SQLite's own text on both — byte-for-byte what node:sqlite
55
+ * reports for the same statement — so read the property instead of stringifying.
56
+ */
57
+ export declare function sqliteErrorMessage(cause: unknown): string;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/sqlite",
3
- "version": "0.51.1",
3
+ "version": "0.52.0",
4
4
  "description": "Node.js sqlite module for Gjs using libgda",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -40,17 +40,17 @@
40
40
  "libgda"
41
41
  ],
42
42
  "devDependencies": {
43
- "@gjsify/cli": "^0.51.1",
43
+ "@gjsify/cli": "^0.52.0",
44
44
  "@gjsify/node-gi": "file:../../../packages/node-gi/node-gi",
45
- "@gjsify/unit": "^0.51.1",
45
+ "@gjsify/unit": "^0.52.0",
46
46
  "@types/node": "^25.9.2",
47
47
  "typescript": "^6.0.3"
48
48
  },
49
49
  "dependencies": {
50
- "@girs/gda-6.0": "5.0.0",
51
- "@girs/glib-2.0": "5.0.0",
52
- "@girs/gobject-2.0": "5.0.0",
53
- "@gjsify/utils": "^0.51.1"
50
+ "@girs/gda-6.0": "5.4.0",
51
+ "@girs/glib-2.0": "5.4.0",
52
+ "@girs/gobject-2.0": "5.4.0",
53
+ "@gjsify/utils": "^0.52.0"
54
54
  },
55
55
  "gjsify": {
56
56
  "runtimes": {