@gjsify/sqlite 0.7.2 → 0.7.3
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 +2 -1
- package/package.json +3 -3
package/lib/esm/database-sync.js
CHANGED
|
@@ -1 +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{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
|
+
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=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
|
+
`;)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.#a=!0),(/\bCOMMIT\b/.test(t)||/\bROLLBACK\b/.test(t))&&(this.#a=!1)}};DatabaseSync.prototype.exec=DatabaseSync.prototype.sqlExec;export{DatabaseSync};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/sqlite",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Node.js sqlite module for Gjs using libgda",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"libgda"
|
|
40
40
|
],
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gjsify/cli": "^0.7.
|
|
43
|
-
"@gjsify/unit": "^0.7.
|
|
42
|
+
"@gjsify/cli": "^0.7.3",
|
|
43
|
+
"@gjsify/unit": "^0.7.3",
|
|
44
44
|
"@types/node": "^25.9.2",
|
|
45
45
|
"typescript": "^6.0.3"
|
|
46
46
|
},
|