@kubun/db-expo 0.5.0 → 0.6.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.
Files changed (2) hide show
  1. package/lib/driver.js +1 -1
  2. package/package.json +2 -2
package/lib/driver.js CHANGED
@@ -1 +1 @@
1
- import*as e from"expo-sqlite";import{SqliteAdapter as t,SqliteIntrospector as n,SqliteQueryCompiler as i}from"kysely";import{serialize as s}from"./serialize.js";export class ExpoDialect{config;constructor(e){this.config={...e,disableStrictModeCreateTable:!0}}createDriver(){return new ExpoDriver(this.config)}createQueryCompiler(){return new i}createAdapter(){return new t}createIntrospector(e){return new n(e)}}export class ExpoDriver{#e=new o;#t;constructor(e){this.#t=new r(e)}async releaseConnection(){this.#e.unlock()}async init(){}async acquireConnection(){return await this.#e.lock(),this.#t}async beginTransaction(e){await e.directQuery("begin transaction")}async commitTransaction(e){await e.directQuery("commit")}async rollbackTransaction(e){await e.directQuery("rollback")}async destroy(){this.#t.closeConnection()}async getDatabaseRuntimeVersion(){try{return(await this.#t.directQuery("select sqlite_version() as version;"))[0].version}catch(e){return console.error(e),"unknown"}}}class r{sqlite;debug;config;constructor(t){this.sqlite=e.openDatabaseSync(t.database),this.debug=t.debug??!1,this.config=t,this.config.disableForeignKeys?this.sqlite.execSync("PRAGMA foreign_keys = OFF;"):this.sqlite.execSync("PRAGMA foreign_keys = ON;")}async closeConnection(){return this.sqlite.closeAsync()}async executeQuery(e){let{sql:t,parameters:n,query:i}=e;"CreateTableNode"!==i.kind||t.includes("kysely_migration")||t.includes("kysely_migration_lock")||t.includes("STRICT")||this.config.disableStrictModeCreateTable||(t+=" STRICT");let r="SelectQueryNode"===i.kind||"RawNode"===i.kind,o=s([...n]);if(this.debug&&console.debug(`${i.kind}${r?" (readonly)":""}: ${t}`),r)return{rows:await this.sqlite.getAllAsync(t,o)};let c=await this.sqlite.runAsync(t,o),a={numAffectedRows:BigInt(c.changes),insertId:BigInt(c.lastInsertRowId),rows:[]};return this.debug&&console.log("queryResult",a),a}async directQuery(e){return await this.sqlite.getAllAsync(e,[])}streamQuery(e,t){throw Error("Expo SQLite driver does not support iterate on prepared statements")}}class o{#n;#i;async lock(){for(;this.#n;)await this.#n;this.#n=new Promise(e=>{this.#i=e})}unlock(){let e=this.#i;this.#n=void 0,this.#i=void 0,e?.()}}
1
+ import*as e from"expo-sqlite";import{SqliteAdapter as t,SqliteIntrospector as n,SqliteQueryCompiler as i}from"kysely";import{serialize as s}from"./serialize.js";export class ExpoDialect{config;constructor(e){this.config={...e,disableStrictModeCreateTable:!0}}createDriver(){return new ExpoDriver(this.config)}createQueryCompiler(){return new i}createAdapter(){return new t}createIntrospector(e){return new n(e)}}export class ExpoDriver{#e=new o;#t;constructor(e){this.#t=new r(e)}async releaseConnection(){this.#e.unlock()}async init(){}async acquireConnection(){return await this.#e.lock(),this.#t}async beginTransaction(e){await e.directQuery("begin transaction")}async commitTransaction(e){await e.directQuery("commit")}async rollbackTransaction(e){await e.directQuery("rollback")}async destroy(){this.#t.closeConnection()}async getDatabaseRuntimeVersion(){try{return(await this.#t.directQuery("select sqlite_version() as version;"))[0].version}catch(e){return console.error(e),"unknown"}}}class r{sqlite;debug;config;constructor(t){this.sqlite=e.openDatabaseSync(t.database),this.debug=t.debug??!1,this.config=t,this.config.disableForeignKeys?this.sqlite.execSync("PRAGMA foreign_keys = OFF;"):this.sqlite.execSync("PRAGMA foreign_keys = ON;")}async closeConnection(){return this.sqlite.closeAsync()}async executeQuery(e){let{sql:t,parameters:n,query:i}=e;"CreateTableNode"!==i.kind||t.includes("kysely_migration")||t.includes("kysely_migration_lock")||t.includes("STRICT")||this.config.disableStrictModeCreateTable||(t+=" STRICT");let r="SelectQueryNode"===i.kind||"RawNode"===i.kind,o=!r&&t.includes(" returning "),c=s([...n]);if(this.debug&&console.debug(`${i.kind}${r?" (readonly)":""}${o?" (returning)":""}: ${t}`),r||o)return{rows:await this.sqlite.getAllAsync(t,c)};let a=await this.sqlite.runAsync(t,c),l={numAffectedRows:BigInt(a.changes),insertId:BigInt(a.lastInsertRowId),rows:[]};return this.debug&&console.log("queryResult",l),l}async directQuery(e){return await this.sqlite.getAllAsync(e,[])}streamQuery(e,t){throw Error("Expo SQLite driver does not support iterate on prepared statements")}}class o{#n;#i;async lock(){for(;this.#n;)await this.#n;this.#n=new Promise(e=>{this.#i=e})}unlock(){let e=this.#i;this.#n=void 0,this.#i=void 0,e?.()}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/db-expo",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "expo-sqlite": "~16.0.10",
19
19
  "kysely": "^0.28.11",
20
- "@kubun/db-adapter": "^0.5.0"
20
+ "@kubun/db-adapter": "^0.6.0"
21
21
  },
22
22
  "scripts": {
23
23
  "build:clean": "del lib",