@gjsify/sqlite 0.54.0 → 0.55.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,2 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{executeStatement as e,integerColumns as t}from"./execution.js";import{parseSql as n}from"./parse-sql.js";import r from"@girs/gio-2.0";const i=new Set,a=new Map;function keyOf(e){return`${e.readOnly?`ro`:`rw`}\u0000${e.path}`}function fileIdentity(e){let t=r.File.new_for_path(e);try{return t.query_info(r.FILE_ATTRIBUTE_ID_FILE,r.FileQueryInfoFlags.NONE,null).get_attribute_string(r.FILE_ATTRIBUTE_ID_FILE)}catch{return null}}function exec(t,r){let[i]=n(t,r);e(t,i,null,()=>void 0)}function query(r,i,a){let[o]=n(r,i);return e(r,o,null,e=>{if(!e)return[];let t=[];for(let n=0;n<e.get_n_rows();n++){let r=[];for(let t=0;t<e.get_n_columns();t++)r.push(String(e.get_value_at(t,n)));t.push(r)}return t},t(a))}const o={table:`TABLE`,view:`VIEW`,index:`INDEX`,trigger:`TRIGGER`};function userObjects(e,t){return query(e,`SELECT type, name FROM ${t} WHERE name NOT LIKE 'sqlite_%'
2
+ ORDER BY CASE type WHEN 'trigger' THEN 0 WHEN 'view' THEN 1 WHEN 'index' THEN 2 ELSE 3 END`,2)}function wipeMemory(e){for(let t of[`sqlite_master`,`sqlite_temp_master`])for(;;){let n=userObjects(e,t);if(n.length===0)break;let r=0;for(let[t,i]of n){let n=o[t];if(n)try{exec(e,`DROP ${n} IF EXISTS "${i.replace(/"/g,`""`)}"`),r++}catch{}}if(r===0)break}exec(e,`PRAGMA user_version = 0`),exec(e,`PRAGMA application_id = 0`)}function isPristine(e){for(let t of[`sqlite_master`,`sqlite_temp_master`])if(query(e,`SELECT name FROM ${t}`,1).length>0)return!1;for(let t of[`pragma_user_version()`,`pragma_application_id()`]){let[n]=query(e,`SELECT * FROM ${t}`,1);if(!n||n[0]!==`0`)return!1}return!0}function rollbackIfNeeded(e){e.get_transaction_status()&&exec(e,`ROLLBACK`)}function acquire(e,t){let n=a.get(keyOf(e)),r=e.isMemory?null:fileIdentity(e.path);for(;n&&n.length>0;){let t=n.pop();if(e.isMemory||r!==null&&t.fileId===r)return t.connection}let o=t();return i.add(o),o}function release(e,t){try{if(rollbackIfNeeded(t),e.isMemory&&(wipeMemory(t),!isPristine(t)))return;let n=keyOf(e),r=a.get(n)??[];r.push({connection:t,fileId:e.isMemory?null:fileIdentity(e.path)}),a.set(n,r)}catch{}}export{acquire,release};
@@ -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{convertParameterSyntax as c}from"./parameter-syntax.js";import{parseSql as l}from"./parse-sql.js";import{sqlRegions as u}from"./sql-regions.js";import{rewriteExistsSubqueries as d}from"./exists-subquery.js";import{StatementSync as f}from"./statement-sync.js";import p from"@girs/gda-6.0";import{lastPathSeparatorIndex as m}from"@gjsify/utils/core";const h=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[h](){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=p.Connection.new_from_string(`SQLite`,`DB_DIR=;DB_NAME=:memory:`,null,p.ConnectionOptions.NONE);else{let e=m(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?p.ConnectionOptions.READ_ONLY:p.ConnectionOptions.NONE;this.#e=p.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.#c(e);for(let e of t){let[t]=this.#o(d(e));s(this.#e,t,null,()=>void 0)}}catch(e){throw a(e)?e:new i(o(e))}this.#l(e)}prepare(e,n){if(this.#a(),typeof e!=`string`)throw new t(`The "sql" argument must be a string.`);let[r,s]=c(e);try{this.#o(d(r))}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 f._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(e){return l(this.#e,e)}#s(){let runPragma=e=>{let[t]=this.#o(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}`)}#c(e){let t=[],n=``,flush=()=>{let e=n.trim();e.length>0&&t.push(e),n=``};for(let t of u(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}#l(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};
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{StatementSync as m}from"./statement-sync.js";import h from"@girs/gda-6.0";import{lastPathSeparatorIndex as g}from"@gjsify/utils/core";const _=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[_](){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=h.Connection.new_from_string(`SQLite`,`DB_DIR=;DB_NAME=:memory:`,null,h.ConnectionOptions.NONE);else{let t=g(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?h.ConnectionOptions.READ_ONLY:h.ConnectionOptions.NONE;e=h.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]=this.#s(p(e));s(this.#e,t,null,()=>void 0)}}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,s]=d(e);try{this.#s(p(r))}catch(e){throw a(e)?e:new i(o(e))}let c={readBigInts:this.#n.readBigInts??!1,returnArrays:this.#n.returnArrays??!1,allowBareNamedParameters:this.#n.allowBareNamedParameters??!0,allowUnknownNamedParameters:this.#n.allowUnknownNamedParameters??!1};return m._create(this.#e,e,c,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(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};
@@ -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{readAllRows as o,readFirstRow as s}from"./data-model-reader.js";import{ColumnTypes as c,executeStatement as l,integerColumns as u}from"./execution.js";import{convertParameterSyntax as d}from"./parameter-syntax.js";import{parseSql as f}from"./parse-sql.js";import{rewriteExistsSubqueries as p}from"./exists-subquery.js";import{bindStringHolders as m}from"./param-binding.js";const h=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 g=class StatementSync{#e;#t;#n;#r;#i;#a;#o;#s=new c;constructor(t,n,r,i,a){if(t!==h)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(h,e,t,n,r)}get sourceSQL(){return this.#t}get expandedSQL(){return this.#t}#c(e){return{readBigInts:this.#r,returnArrays:this.#i,textColumns:e}}#l(){let e=-1;for(let t of this.#n)t.position>e&&(e=t.position);return e}#u(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.#l())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.#l()+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]=d(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}}#d(e,t,n){let{sql:o,strings:s}=this.#u(e);try{let[e,r]=f(this.#e,p(o));return m(r,s),l(this.#e,e,r,t,n)}catch(e){throw i(e)?e:new r(a(e))}}run(...e){this.#d(e,()=>void 0);let[t]=f(this.#e,`SELECT changes(), last_insert_rowid()`),[n,i]=l(this.#e,t,null,e=>{if(!e||e.get_n_rows()===0)throw new r(`SELECT changes(), last_insert_rowid() returned no row`);return[BigInt(e.get_value_at(0,0)),BigInt(e.get_value_at(1,0))]},u(2));return this.#r?{changes:n,lastInsertRowid:i}:{changes:Number(n),lastInsertRowid:Number(i)}}get(...e){return this.#d(e,(e,t)=>{if(!(!e||e.get_n_rows()===0))return s(e,this.#c(t))},this.#s)}all(...e){return this.#d(e,(e,t)=>e?o(e,this.#c(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{g 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{ColumnTypes as o,executeStatement as s,integerColumns as c}from"./execution.js";import{parseSql as l}from"./parse-sql.js";import{readAllRows as u,readFirstRow as d}from"./data-model-reader.js";import{convertParameterSyntax as f}from"./parameter-syntax.js";import{rewriteExistsSubqueries as p}from"./exists-subquery.js";import{bindStringHolders as m}from"./param-binding.js";const h=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 g=class StatementSync{#e;#t;#n;#r;#i;#a;#o;#s=new o;constructor(t,n,r,i,a){if(t!==h)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(h,e,t,n,r)}get sourceSQL(){return this.#t}get expandedSQL(){return this.#t}#c(e){return{readBigInts:this.#r,returnArrays:this.#i,textColumns:e}}#l(){let e=-1;for(let t of this.#n)t.position>e&&(e=t.position);return e}#u(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.#l())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.#l()+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]=f(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}}#d(e,t,n){let{sql:o,strings:c}=this.#u(e);try{let[e,r]=l(this.#e,p(o));return m(r,c),s(this.#e,e,r,t,n)}catch(e){throw i(e)?e:new r(a(e))}}run(...e){this.#d(e,()=>void 0);let[t]=l(this.#e,`SELECT changes(), last_insert_rowid()`),[n,i]=s(this.#e,t,null,e=>{if(!e||e.get_n_rows()===0)throw new r(`SELECT changes(), last_insert_rowid() returned no row`);return[BigInt(e.get_value_at(0,0)),BigInt(e.get_value_at(1,0))]},c(2));return this.#r?{changes:n,lastInsertRowid:i}:{changes:Number(n),lastInsertRowid:Number(i)}}get(...e){return this.#d(e,(e,t)=>{if(!(!e||e.get_n_rows()===0))return d(e,this.#c(t))},this.#s)}all(...e){return this.#d(e,(e,t)=>e?u(e,this.#c(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{g as StatementSync};
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import type Gda from '@girs/gda-6.0';
2
+ export interface PoolKey {
3
+ /** The database path as the caller gave it — `:memory:` or a file path. */
4
+ path: string;
5
+ isMemory: boolean;
6
+ readOnly: boolean;
7
+ }
8
+ /**
9
+ * A connection for `key` — a parked one proven equivalent to a fresh one, or a new one
10
+ * from `create`.
11
+ *
12
+ * The caller's `create` is what knows the connection string; this module only owns the
13
+ * lifetime. A connection it returns is registered before it is handed out, so even a
14
+ * caller that drops it on the floor cannot let the garbage collector finalize it.
15
+ */
16
+ export declare function acquire(key: PoolKey, create: () => Gda.Connection): Gda.Connection;
17
+ /**
18
+ * Take a connection back from a `DatabaseSync` that is done with it.
19
+ *
20
+ * Never closes it (see the note at the top of this file). A `:memory:` connection is
21
+ * wiped and parked only if it verifies as pristine afterwards; a file connection is parked
22
+ * with the identity of the file it is attached to.
23
+ */
24
+ export declare function release(key: PoolKey, connection: Gda.Connection): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/sqlite",
3
- "version": "0.54.0",
3
+ "version": "0.55.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,18 @@
40
40
  "libgda"
41
41
  ],
42
42
  "devDependencies": {
43
- "@gjsify/cli": "^0.54.0",
43
+ "@gjsify/cli": "^0.55.0",
44
44
  "@gjsify/node-gi": "file:../../../packages/node-gi/node-gi",
45
- "@gjsify/unit": "^0.54.0",
45
+ "@gjsify/unit": "^0.55.0",
46
46
  "@types/node": "^25.9.2",
47
47
  "typescript": "^6.0.3"
48
48
  },
49
49
  "dependencies": {
50
50
  "@girs/gda-6.0": "5.4.0",
51
+ "@girs/gio-2.0": "5.4.0",
51
52
  "@girs/glib-2.0": "5.4.0",
52
53
  "@girs/gobject-2.0": "5.4.0",
53
- "@gjsify/utils": "^0.54.0"
54
+ "@gjsify/utils": "^0.55.0"
54
55
  },
55
56
  "gjsify": {
56
57
  "runtimes": {