@gjsify/sqlite 0.3.20 → 0.4.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.
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
@@ -1 +1 @@
1
- import{OutOfRangeError as e}from"./errors.js";function t(t,n){if(t==null)return null;if(typeof t==`number`){if(Number.isInteger(t)&&!Number.isSafeInteger(t)){if(!n)throw new e(`Value is too large to be represented as a JavaScript number: ${t}`);return BigInt(t)}return n&&Number.isInteger(t)?BigInt(t):t}if(typeof t==`bigint`){if(!n){if(t>BigInt(2**53-1)||t<BigInt(-(2**53-1)))throw new e(`Value is too large to be represented as a JavaScript number: ${t}`);return Number(t)}return t}return typeof t==`string`||t instanceof Uint8Array?t:t&&typeof t.toArray==`function`?new Uint8Array(t.toArray()):t}function n(e,n,r){let i=e.get_n_columns();if(r.returnArrays){let a=[];for(let o=0;o<i;o++){let i=e.get_value_at(o,n);a.push(t(i,r.readBigInts))}return a}let a=Object.create(null);for(let o=0;o<i;o++){let i=e.get_column_name(o);a[i]=t(e.get_value_at(o,n),r.readBigInts)}return a}function r(e,t){let r=e.get_n_rows(),i=[];for(let a=0;a<r;a++){let r=n(e,a,t);r!==void 0&&i.push(r)}return i}function i(e,t){if(e.get_n_rows()!==0)return n(e,0,t)}export{r as readAllRows,i as readFirstRow,n as readRow};
1
+ import"./_virtual/_rolldown/runtime.js";import{OutOfRangeError as e}from"./errors.js";function convertValue(t,n){if(t==null)return null;if(typeof t==`number`){if(Number.isInteger(t)&&!Number.isSafeInteger(t)){if(!n)throw new e(`Value is too large to be represented as a JavaScript number: ${t}`);return BigInt(t)}return n&&Number.isInteger(t)?BigInt(t):t}if(typeof t==`bigint`){if(!n){if(t>BigInt(2**53-1)||t<BigInt(-(2**53-1)))throw new e(`Value is too large to be represented as a JavaScript number: ${t}`);return Number(t)}return t}return typeof t==`string`||t instanceof Uint8Array?t:t&&typeof t.toArray==`function`?new Uint8Array(t.toArray()):t}function readRow(e,t,n){let r=e.get_n_columns();if(n.returnArrays){let i=[];for(let a=0;a<r;a++){let r=e.get_value_at(a,t);i.push(convertValue(r,n.readBigInts))}return i}let i=Object.create(null);for(let a=0;a<r;a++){let r=e.get_column_name(a);i[r]=convertValue(e.get_value_at(a,t),n.readBigInts)}return i}function readAllRows(e,t){let n=e.get_n_rows(),r=[];for(let i=0;i<n;i++){let n=readRow(e,i,t);n!==void 0&&r.push(n)}return r}function readFirstRow(e,t){if(e.get_n_rows()!==0)return readRow(e,0,t)}export{readAllRows,readFirstRow,readRow};
@@ -1 +1 @@
1
- import{ConstructCallRequiredError as e,InvalidArgTypeError as t,InvalidStateError as n,InvalidUrlSchemeError as r,SqliteError as i}from"./errors.js";import{StatementSync as a}from"./statement-sync.js";import o from"@girs/gda-6.0";const s=Symbol.for(`sqlite-type`);function c(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 l(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}function u(e){let t=[],n=0,r=``,i=0;for(;i<e.length;){if(e[i]===`'`){let t=i;for(i++;i<e.length&&e[i]!==`'`;){if(e[i]===`'`&&e[i+1]===`'`){i+=2;continue}i++}i<e.length&&i++,r+=e.substring(t,i);continue}if(e[i]===`?`){i++;let a=``;for(;i<e.length&&e[i]>=`0`&&e[i]<=`9`;)a+=e[i],i++;let o=a?parseInt(a,10)-1:n;n=a?n:n+1;let s=`p${o}`;t.push({gdaId:s,originalName:a?`?${a}`:`?`,position:o}),r+=`##${s}::string`;continue}if((e[i]===`$`||e[i]===`:`||e[i]===`@`)&&i+1<e.length&&/[a-zA-Z_]/.test(e[i+1])){let n=e[i];i++;let a=``;for(;i<e.length&&/[a-zA-Z0-9_]/.test(e[i]);)a+=e[i],i++;let o=a;t.push({gdaId:o,originalName:`${n}${a}`,position:-1}),r+=`##${o}::string`;continue}r+=e[i],i++}return[r,t]}var d=class{#e=null;#t=null;#n;#r;#i;#a=!1;constructor(t,n){if(!new.target)throw new e(`DatabaseSync`);this.#n=c(t),this.#r=l(n),this.#i=this.#n===`:memory:`,this.#r.open!==!1&&this.open()}get[s](){return`node:sqlite`}get isOpen(){return this.#e!==null&&this.#e.is_opened()}get isTransaction(){return this.#o(),this.#a}open(){if(this.isOpen)throw new n(`database is already open`);try{if(this.#i)this.#e=o.Connection.new_from_string(`SQLite`,`DB_DIR=;DB_NAME=:memory:`,null,o.ConnectionOptions.NONE);else{let e=this.#n.lastIndexOf(`/`),t=`DB_DIR=${e>=0?this.#n.substring(0,e):`.`};DB_NAME=${e>=0?this.#n.substring(e+1):this.#n}`,n=this.#r.readOnly?o.ConnectionOptions.READ_ONLY:o.ConnectionOptions.NONE;this.#e=o.Connection.new_from_string(`SQLite`,t,null,n)}this.#e.open()}catch(e){throw this.#e=null,new i(e instanceof Error?e.message:String(e))}this.#t=this.#e.create_parser()??new o.SqlParser,this.#s()}close(){if(!this.isOpen)throw new n(`database is not open`);this.#e.close(),this.#e=null,this.#t=null,this.#a=!1}sqlExec(e){if(this.#o(),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.#t.parse_string(e);t&&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.#o(),typeof e!=`string`)throw new t(`The "sql" argument must be a string.`);let[,r]=u(e);try{let t=r.length>0?e.replace(/\?(\d+)?/g,`NULL`).replace(/[\$:@][a-zA-Z_][a-zA-Z0-9_]*/g,`NULL`):e,[n]=this.#t.parse_string(t);if(!n)throw new i(`Failed to parse SQL statement`)}catch(e){throw e instanceof i||e instanceof t?e:new i(e instanceof Error?e.message:String(e))}let o={readBigInts:this.#r.readBigInts??!1,returnArrays:this.#r.returnArrays??!1,allowBareNamedParameters:this.#r.allowBareNamedParameters??!0,allowUnknownNamedParameters:this.#r.allowUnknownNamedParameters??!1};return a._create(this.#e,e,o,r,this.#t)}location(e){if(this.#o(),e!==void 0&&typeof e!=`string`)throw new t(`The "dbName" argument must be a string.`);return this.#i?null:this.#n}[Symbol.dispose](){if(this.isOpen)try{this.close()}catch{}}#o(){if(!this.isOpen)throw new n(`database is not open`)}#s(){let e=this.#e,t=t=>{let[n]=this.#t.parse_string(t);n&&e.statement_execute_select(n,null)};this.#r.enableForeignKeyConstraints===!1?t(`PRAGMA foreign_keys = OFF`):t(`PRAGMA foreign_keys = ON`),this.#r.timeout!==void 0&&this.#r.timeout>0&&t(`PRAGMA busy_timeout = ${this.#r.timeout}`)}#c(e){if(e.get_statement_type()===o.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=!1;for(let i=0;i<e.length;i++){let a=e[i];if(a===`'`&&!r)r=!0,n+=a;else if(a===`'`&&r)e[i+1]===`'`?(n+=`''`,i++):(r=!1,n+=a);else if(a===`;`&&!r){let e=n.trim();e.length>0&&t.push(e),n=``}else n+=a}let i=n.trim();return i.length>0&&t.push(i),t}#u(e){let t=e.trim().toUpperCase();/\bBEGIN\b/.test(t)&&(this.#a=!0),(/\bCOMMIT\b/.test(t)||/\bROLLBACK\b/.test(t))&&(this.#a=!1)}};d.prototype.exec=d.prototype.sqlExec;export{d as DatabaseSync};
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{StatementSync as a}from"./statement-sync.js";import o from"@girs/gda-6.0";const s=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}function convertParameterSyntax(e){let t=[],n=0,r=``,i=0;for(;i<e.length;){if(e[i]===`'`){let t=i;for(i++;i<e.length&&e[i]!==`'`;){if(e[i]===`'`&&e[i+1]===`'`){i+=2;continue}i++}i<e.length&&i++,r+=e.substring(t,i);continue}if(e[i]===`?`){i++;let a=``;for(;i<e.length&&e[i]>=`0`&&e[i]<=`9`;)a+=e[i],i++;let o=a?parseInt(a,10)-1:n;n=a?n:n+1;let s=`p${o}`;t.push({gdaId:s,originalName:a?`?${a}`:`?`,position:o}),r+=`##${s}::string`;continue}if((e[i]===`$`||e[i]===`:`||e[i]===`@`)&&i+1<e.length&&/[a-zA-Z_]/.test(e[i+1])){let n=e[i];i++;let a=``;for(;i<e.length&&/[a-zA-Z0-9_]/.test(e[i]);)a+=e[i],i++;let o=a;t.push({gdaId:o,originalName:`${n}${a}`,position:-1}),r+=`##${o}::string`;continue}r+=e[i],i++}return[r,t]}var DatabaseSync=class{#e=null;#t=null;#n;#r;#i;#a=!1;constructor(t,n){if(!new.target)throw new e(`DatabaseSync`);this.#n=parsePath(t),this.#r=validateOptions(n),this.#i=this.#n===`:memory:`,this.#r.open!==!1&&this.open()}get[s](){return`node:sqlite`}get isOpen(){return this.#e!==null&&this.#e.is_opened()}get isTransaction(){return this.#o(),this.#a}open(){if(this.isOpen)throw new n(`database is already open`);try{if(this.#i)this.#e=o.Connection.new_from_string(`SQLite`,`DB_DIR=;DB_NAME=:memory:`,null,o.ConnectionOptions.NONE);else{let e=this.#n.lastIndexOf(`/`),t=`DB_DIR=${e>=0?this.#n.substring(0,e):`.`};DB_NAME=${e>=0?this.#n.substring(e+1):this.#n}`,n=this.#r.readOnly?o.ConnectionOptions.READ_ONLY:o.ConnectionOptions.NONE;this.#e=o.Connection.new_from_string(`SQLite`,t,null,n)}this.#e.open()}catch(e){throw this.#e=null,new i(e instanceof Error?e.message:String(e))}this.#t=this.#e.create_parser()??new o.SqlParser,this.#s()}close(){if(!this.isOpen)throw new n(`database is not open`);this.#e.close(),this.#e=null,this.#t=null,this.#a=!1}sqlExec(e){if(this.#o(),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.#t.parse_string(e);t&&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.#o(),typeof e!=`string`)throw new t(`The "sql" argument must be a string.`);let[,r]=convertParameterSyntax(e);try{let t=r.length>0?e.replace(/\?(\d+)?/g,`NULL`).replace(/[\$:@][a-zA-Z_][a-zA-Z0-9_]*/g,`NULL`):e,[n]=this.#t.parse_string(t);if(!n)throw new i(`Failed to parse SQL statement`)}catch(e){throw e instanceof i||e instanceof t?e:new i(e instanceof Error?e.message:String(e))}let o={readBigInts:this.#r.readBigInts??!1,returnArrays:this.#r.returnArrays??!1,allowBareNamedParameters:this.#r.allowBareNamedParameters??!0,allowUnknownNamedParameters:this.#r.allowUnknownNamedParameters??!1};return a._create(this.#e,e,o,r,this.#t)}location(e){if(this.#o(),e!==void 0&&typeof e!=`string`)throw new t(`The "dbName" argument must be a string.`);return this.#i?null:this.#n}[Symbol.dispose](){if(this.isOpen)try{this.close()}catch{}}#o(){if(!this.isOpen)throw new n(`database is not open`)}#s(){let e=this.#e,runPragma=t=>{let[n]=this.#t.parse_string(t);n&&e.statement_execute_select(n,null)};this.#r.enableForeignKeyConstraints===!1?runPragma(`PRAGMA foreign_keys = OFF`):runPragma(`PRAGMA foreign_keys = ON`),this.#r.timeout!==void 0&&this.#r.timeout>0&&runPragma(`PRAGMA busy_timeout = ${this.#r.timeout}`)}#c(e){if(e.get_statement_type()===o.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=!1;for(let i=0;i<e.length;i++){let a=e[i];if(a===`'`&&!r)r=!0,n+=a;else if(a===`'`&&r)e[i+1]===`'`?(n+=`''`,i++):(r=!1,n+=a);else if(a===`;`&&!r){let e=n.trim();e.length>0&&t.push(e),n=``}else n+=a}let i=n.trim();return i.length>0&&t.push(i),t}#u(e){let t=e.trim().toUpperCase();/\bBEGIN\b/.test(t)&&(this.#a=!0),(/\bCOMMIT\b/.test(t)||/\bROLLBACK\b/.test(t))&&(this.#a=!1)}};DatabaseSync.prototype.exec=DatabaseSync.prototype.sqlExec;export{DatabaseSync};
package/lib/esm/errors.js CHANGED
@@ -1 +1 @@
1
- var e=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}},t=class extends Error{code=`ERR_INVALID_STATE`;constructor(e){super(e),this.name=`InvalidStateError`}},n=class extends TypeError{code=`ERR_INVALID_ARG_TYPE`;constructor(e){super(e),this.name=`InvalidArgTypeError`}},r=class extends Error{code=`ERR_INVALID_ARG_VALUE`;constructor(e){super(e),this.name=`InvalidArgValueError`}},i=class extends RangeError{code=`ERR_OUT_OF_RANGE`;constructor(e){super(e),this.name=`OutOfRangeError`}},a=class extends TypeError{code=`ERR_CONSTRUCT_CALL_REQUIRED`;constructor(e){super(`Cannot call constructor without \`new\`: ${e}`),this.name=`ConstructCallRequiredError`}},o=class extends TypeError{code=`ERR_INVALID_URL_SCHEME`;constructor(e=`The URL must be of scheme file:`){super(e),this.name=`InvalidUrlSchemeError`}},s=class extends TypeError{code=`ERR_ILLEGAL_CONSTRUCTOR`;constructor(){super(`Illegal constructor`),this.name=`IllegalConstructorError`}};export{a as ConstructCallRequiredError,s as IllegalConstructorError,n as InvalidArgTypeError,r as InvalidArgValueError,t as InvalidStateError,o as InvalidUrlSchemeError,i as OutOfRangeError,e as 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`}};export{ConstructCallRequiredError,IllegalConstructorError,InvalidArgTypeError,InvalidArgValueError,InvalidStateError,InvalidUrlSchemeError,OutOfRangeError,SqliteError};
@@ -1 +1 @@
1
- import{InvalidArgTypeError as e,InvalidArgValueError as t,InvalidStateError as n,SqliteError as r}from"./errors.js";function i(t,n){if(t==null)return;let r=typeof t;if(!(r===`number`||r===`bigint`||r===`string`||r===`boolean`)&&!(t instanceof Uint8Array||t instanceof ArrayBuffer)&&!ArrayBuffer.isView(t))throw new e(`Provided value cannot be bound to SQLite parameter ${n}.`)}function a(e,n){if(n==null){e.set_value(null);return}if(typeof n==`number`){e.set_value(n);return}if(typeof n==`bigint`){if(n>9223372036854775807n||n<-9223372036854775808n)throw new t(`BigInt value is too large to bind.`);e.set_value(Number(n));return}if(typeof n==`string`){e.set_value(n);return}if(typeof n==`boolean`){e.set_value(+!!n);return}if(n instanceof Uint8Array||ArrayBuffer.isView(n)){let t=n instanceof Uint8Array?n:new Uint8Array(n.buffer);e.set_value(t);return}e.set_value(n)}function o(e,t,o,s){if(!e){if(t.length>0)throw new r(`column index out of range`,25,`column index out of range`);return}let c=e.get_holders();if(o){let e=new Set;for(let t of c){let r=t.get_id(),l,u=!1;if(r in o&&(l=o[r],e.add(r),u=!0),!u&&s.allowBareNamedParameters){let t=r.replace(/^[\$:@]/,``);t in o&&(l=o[t],e.add(t),u=!0)}if(!u&&!s.allowBareNamedParameters){let e=r.replace(/^[\$:@]/,``);if(e in o)throw new n(`Unknown named parameter '${e}'`)}if(u){let e=c.indexOf(t)+1;i(l,e),a(t,l)}else a(t,null)}if(!s.allowUnknownNamedParameters){for(let t of Object.keys(o))if(!e.has(t)&&!c.some(e=>{let n=e.get_id();return n===t||n.replace(/^[\$:@]/,``)===t}))throw new n(`Unknown named parameter '${t}'`)}}else{if(t.length>c.length)throw new r(`column index out of range`,25,`column index out of range`);for(let e=0;e<c.length;e++){let n=e<t.length?t[e]:void 0;i(n,e+1),a(c[e],n??null)}}}export{o as bindParameters};
1
+ import"./_virtual/_rolldown/runtime.js";import{InvalidArgTypeError as e,InvalidArgValueError as t,InvalidStateError as n,SqliteError as r}from"./errors.js";function validateBindValue(t,n){if(t==null)return;let r=typeof t;if(!(r===`number`||r===`bigint`||r===`string`||r===`boolean`)&&!(t instanceof Uint8Array||t instanceof ArrayBuffer)&&!ArrayBuffer.isView(t))throw new e(`Provided value cannot be bound to SQLite parameter ${n}.`)}function setHolderValue(e,n){if(n==null){e.set_value(null);return}if(typeof n==`number`){e.set_value(n);return}if(typeof n==`bigint`){if(n>9223372036854775807n||n<-9223372036854775808n)throw new t(`BigInt value is too large to bind.`);e.set_value(Number(n));return}if(typeof n==`string`){e.set_value(n);return}if(typeof n==`boolean`){e.set_value(+!!n);return}if(n instanceof Uint8Array||ArrayBuffer.isView(n)){let t=n instanceof Uint8Array?n:new Uint8Array(n.buffer);e.set_value(t);return}e.set_value(n)}function bindParameters(e,t,i,a){if(!e){if(t.length>0)throw new r(`column index out of range`,25,`column index out of range`);return}let o=e.get_holders();if(i){let e=new Set;for(let t of o){let r=t.get_id(),s,c=!1;if(r in i&&(s=i[r],e.add(r),c=!0),!c&&a.allowBareNamedParameters){let t=r.replace(/^[\$:@]/,``);t in i&&(s=i[t],e.add(t),c=!0)}if(!c&&!a.allowBareNamedParameters){let e=r.replace(/^[\$:@]/,``);if(e in i)throw new n(`Unknown named parameter '${e}'`)}if(c){let e=o.indexOf(t)+1;validateBindValue(s,e),setHolderValue(t,s)}else setHolderValue(t,null)}if(!a.allowUnknownNamedParameters){for(let t of Object.keys(i))if(!e.has(t)&&!o.some(e=>{let n=e.get_id();return n===t||n.replace(/^[\$:@]/,``)===t}))throw new n(`Unknown named parameter '${t}'`)}}else{if(t.length>o.length)throw new r(`column index out of range`,25,`column index out of range`);for(let e=0;e<o.length;e++){let n=e<t.length?t[e]:void 0;validateBindValue(n,e+1),setHolderValue(o[e],n??null)}}}export{bindParameters};
@@ -1 +1 @@
1
- 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 o from"@girs/gda-6.0";const s=Symbol(`StatementSync.internal`);function c(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 l(e){if(e==null)return`NULL`;if(typeof e==`number`)return String(e);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(typeof e==`string`)return`'`+e.replace(/'/g,`''`)+`'`;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)?l(new Uint8Array(e.buffer)):`NULL`}var u=class n{#e;#t;#n;#r;#i;#a;#o;#s;constructor(t,n,r,i,a,o){if(t!==s)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,this.#s=o}static _create(e,t,r,i,a){return new n(s,e,t,r,i,a)}get sourceSQL(){return this.#t}get expandedSQL(){return this.#t}#c(){return{readBigInts:this.#r,returnArrays:this.#i}}#l(e){if(this.#n.length===0){if(e.length>0&&!(e.length>0&&e[0]!==null&&typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!ArrayBuffer.isView(e[0])))throw new r(`column index out of range`,25,`column index out of range`);return this.#t}let t=null,n=e;e.length>0&&e[0]!==null&&typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!ArrayBuffer.isView(e[0])&&(t=e[0],n=e.slice(1));let i=new Map,a={};if(t){for(let e of this.#n){if(e.position>=0)continue;let n=e.originalName,a,o=!1;if(n in t&&(a=t[n],o=!0),!o&&this.#a){let e=n.replace(/^[\$:@]/,``);e in t&&(a=t[e],o=!0)}if(!o&&!this.#a){let e=n.replace(/^[\$:@]/,``);if(e in t)throw new r(`Unknown named parameter '${e}'`,0,`Unknown named parameter '${e}'`)}o?(c(a,this.#n.indexOf(e)+1),i.set(e.originalName,l(a))):i.set(e.originalName,`NULL`)}let e=this.#n.filter(e=>e.position>=0);for(let t=0;t<n.length;t++){if(t>=e.length)throw new r(`column index out of range`,25,`column index out of range`);c(n[t],t+1),a[e[t].position]=l(n[t])}}else{let e=this.#n.filter(e=>e.position>=0);if(n.length>e.length&&e.length>0)throw new r(`column index out of range`,25,`column index out of range`);for(let t=0;t<e.length;t++)t<n.length?(c(n[t],t+1),a[e[t].position]=l(n[t])):a[e[t].position]=`NULL`}let o=this.#t,s=this.#n.filter(e=>e.position<0).sort((e,t)=>t.originalName.length-e.originalName.length);for(let e of s){let t=i.get(e.originalName)??`NULL`;o=o.split(e.originalName).join(t)}if(Object.keys(a).length>0){let e=``,t=0,n=0;for(;n<o.length;){if(o[n]===`'`){let t=n;for(n++;n<o.length&&o[n]!==`'`;){if(o[n]===`'`&&o[n+1]===`'`){n+=2;continue}n++}n<o.length&&n++,e+=o.substring(t,n);continue}if(o[n]===`?`){n++;let r=``;for(;n<o.length&&o[n]>=`0`&&o[n]<=`9`;)r+=o[n],n++;let i=r?parseInt(r,10)-1:t;t=r?t:t+1,e+=i in a?a[i]:`NULL`;continue}e+=o[n],n++}o=e}return o}#u(e){let[t]=this.#s.parse_string(e);if(!t)throw new r(`Failed to parse SQL statement`);if(t.get_statement_type()===o.SqlStatementType.SELECT)return{model:this.#e.statement_execute_select(t,null),isSelect:!0};try{return this.#e.statement_execute_non_select(t,null),{model:null,isSelect:!1}}catch{return{model:this.#e.statement_execute_select(t,null),isSelect:!0}}}run(...e){let t=this.#l(e);this.#u(t);let n=0,r=0;try{let e=this.#e.execute_select_command(`SELECT changes()`);e&&e.get_n_rows()>0&&(n=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&&(r=e.get_value_at(0,0))}catch{}return this.#r&&(n=BigInt(n),r=BigInt(r)),{changes:n,lastInsertRowid:r}}get(...e){let t=this.#l(e);try{let{model:e}=this.#u(t);return!e||e.get_n_rows()===0?void 0:a(e,this.#c())}catch{return}}all(...e){let t=this.#l(e);try{let{model:e}=this.#u(t);return e?i(e,this.#c()):[]}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{u as StatementSync};
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 o from"@girs/gda-6.0";const s=Symbol(`StatementSync.internal`);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 sqlEscapeValue(e){if(e==null)return`NULL`;if(typeof e==`number`)return String(e);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(typeof e==`string`)return`'`+e.replace(/'/g,`''`)+`'`;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)?sqlEscapeValue(new Uint8Array(e.buffer)):`NULL`}var c=class StatementSync{#e;#t;#n;#r;#i;#a;#o;#s;constructor(t,n,r,i,a,o){if(t!==s)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,this.#s=o}static _create(e,t,n,r,i){return new StatementSync(s,e,t,n,r,i)}get sourceSQL(){return this.#t}get expandedSQL(){return this.#t}#c(){return{readBigInts:this.#r,returnArrays:this.#i}}#l(e){if(this.#n.length===0){if(e.length>0&&!(e.length>0&&e[0]!==null&&typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!ArrayBuffer.isView(e[0])))throw new r(`column index out of range`,25,`column index out of range`);return this.#t}let t=null,n=e;e.length>0&&e[0]!==null&&typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!ArrayBuffer.isView(e[0])&&(t=e[0],n=e.slice(1));let i=new Map,a={};if(t){for(let e of this.#n){if(e.position>=0)continue;let n=e.originalName,a,o=!1;if(n in t&&(a=t[n],o=!0),!o&&this.#a){let e=n.replace(/^[\$:@]/,``);e in t&&(a=t[e],o=!0)}if(!o&&!this.#a){let e=n.replace(/^[\$:@]/,``);if(e in t)throw new r(`Unknown named parameter '${e}'`,0,`Unknown named parameter '${e}'`)}o?(validateBindValue(a,this.#n.indexOf(e)+1),i.set(e.originalName,sqlEscapeValue(a))):i.set(e.originalName,`NULL`)}let e=this.#n.filter(e=>e.position>=0);for(let t=0;t<n.length;t++){if(t>=e.length)throw new r(`column index out of range`,25,`column index out of range`);validateBindValue(n[t],t+1),a[e[t].position]=sqlEscapeValue(n[t])}}else{let e=this.#n.filter(e=>e.position>=0);if(n.length>e.length&&e.length>0)throw new r(`column index out of range`,25,`column index out of range`);for(let t=0;t<e.length;t++)t<n.length?(validateBindValue(n[t],t+1),a[e[t].position]=sqlEscapeValue(n[t])):a[e[t].position]=`NULL`}let o=this.#t,s=this.#n.filter(e=>e.position<0).sort((e,t)=>t.originalName.length-e.originalName.length);for(let e of s){let t=i.get(e.originalName)??`NULL`;o=o.split(e.originalName).join(t)}if(Object.keys(a).length>0){let e=``,t=0,n=0;for(;n<o.length;){if(o[n]===`'`){let t=n;for(n++;n<o.length&&o[n]!==`'`;){if(o[n]===`'`&&o[n+1]===`'`){n+=2;continue}n++}n<o.length&&n++,e+=o.substring(t,n);continue}if(o[n]===`?`){n++;let r=``;for(;n<o.length&&o[n]>=`0`&&o[n]<=`9`;)r+=o[n],n++;let i=r?parseInt(r,10)-1:t;t=r?t:t+1,e+=i in a?a[i]:`NULL`;continue}e+=o[n],n++}o=e}return o}#u(e){let[t]=this.#s.parse_string(e);if(!t)throw new r(`Failed to parse SQL statement`);if(t.get_statement_type()===o.SqlStatementType.SELECT)return{model:this.#e.statement_execute_select(t,null),isSelect:!0};try{return this.#e.statement_execute_non_select(t,null),{model:null,isSelect:!1}}catch{return{model:this.#e.statement_execute_select(t,null),isSelect:!0}}}run(...e){let t=this.#l(e);this.#u(t);let n=0,r=0;try{let e=this.#e.execute_select_command(`SELECT changes()`);e&&e.get_n_rows()>0&&(n=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&&(r=e.get_value_at(0,0))}catch{}return this.#r&&(n=BigInt(n),r=BigInt(r)),{changes:n,lastInsertRowid:r}}get(...e){let t=this.#l(e);try{let{model:e}=this.#u(t);return!e||e.get_n_rows()===0?void 0:a(e,this.#c())}catch{return}}all(...e){let t=this.#l(e);try{let{model:e}=this.#u(t);return e?i(e,this.#c()):[]}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{c as StatementSync};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/sqlite",
3
- "version": "0.3.20",
3
+ "version": "0.4.0",
4
4
  "description": "Node.js sqlite module for Gjs using libgda",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -31,14 +31,14 @@
31
31
  "libgda"
32
32
  ],
33
33
  "devDependencies": {
34
- "@gjsify/cli": "^0.3.20",
35
- "@gjsify/unit": "^0.3.20",
34
+ "@gjsify/cli": "^0.4.0",
35
+ "@gjsify/unit": "^0.4.0",
36
36
  "@types/node": "^25.6.2",
37
37
  "typescript": "^6.0.3"
38
38
  },
39
39
  "dependencies": {
40
- "@girs/gda-6.0": "6.0.0-4.0.0-rc.14",
41
- "@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
42
- "@girs/gobject-2.0": "2.88.0-4.0.0-rc.14"
40
+ "@girs/gda-6.0": "6.0.0-4.0.0-rc.15",
41
+ "@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
42
+ "@girs/gobject-2.0": "2.88.0-4.0.0-rc.15"
43
43
  }
44
44
  }