From 7b330e8df6da7da930137e8e661a245b42bd8fd1 Mon Sep 17 00:00:00 2001 From: Ben Merckx Date: Wed, 11 Sep 2024 12:18:47 +0200 Subject: [PATCH] Remove @db/sqlite driver for now, see denodrivers/sqlite3#138 --- jsr.json | 3 +- src/core/Driver.ts | 1 - src/core/expr/Include.ts | 22 +++------ src/driver-jsr.ts | 1 - src/driver.ts | 1 - src/driver/denodrivers-sqlite.ts | 79 -------------------------------- 6 files changed, 7 insertions(+), 100 deletions(-) delete mode 100644 src/driver-jsr.ts delete mode 100644 src/driver/denodrivers-sqlite.ts diff --git a/jsr.json b/jsr.json index 41b0ed5..79cbb1b 100644 --- a/jsr.json +++ b/jsr.json @@ -8,7 +8,6 @@ ".": "./src/index.ts", "./sqlite": "./src/sqlite.ts", "./mysql": "./src/mysql.ts", - "./postgres": "./src/postgres.ts", - "./driver": "./src/driver-jsr.ts" + "./postgres": "./src/postgres.ts" } } diff --git a/src/core/Driver.ts b/src/core/Driver.ts index 911f404..1a3a050 100644 --- a/src/core/Driver.ts +++ b/src/core/Driver.ts @@ -9,7 +9,6 @@ export interface BatchQuery { } export interface DriverSpecs { parsesJson: boolean - parsesNestedJson?: boolean } export interface PrepareOptions { isSelection: boolean diff --git a/src/core/expr/Include.ts b/src/core/expr/Include.ts index c83a906..5a888d0 100644 --- a/src/core/expr/Include.ts +++ b/src/core/expr/Include.ts @@ -1,4 +1,4 @@ -import type { DriverSpecs } from '../Driver.ts' +import type {DriverSpecs} from '../Driver.ts' import { type HasData, type HasSql, @@ -6,18 +6,16 @@ import { internalData, internalSql } from '../Internal.ts' -import type { QueryMeta } from '../MetaData.ts' -import type { MapRowContext, RowOfRecord } from '../Selection.ts' -import { type Sql, sql } from '../Sql.ts' -import type { Select, SelectBase, SelectData } from '../query/Select.ts' +import type {QueryMeta} from '../MetaData.ts' +import type {MapRowContext, RowOfRecord} from '../Selection.ts' +import {type Sql, sql} from '../Sql.ts' +import type {Select, SelectBase, SelectData} from '../query/Select.ts' export interface IncludeData extends SelectData { first: boolean } -let isNested = false - export class Include implements HasData>, HasSql { @@ -30,17 +28,11 @@ export class Include #mapFromDriverValue = (value: any, specs: DriverSpecs): any => { const {select, first} = getData(this) - const {parsesJson, parsesNestedJson = parsesJson} = specs - const isPreParsed = isNested - ? parsesNestedJson - : parsesJson - const parsed = isPreParsed ? value : JSON.parse(value) + const parsed = specs.parsesJson ? value : JSON.parse(value) if (first) { - isNested = true const result = parsed ? select!.mapRow({values: parsed, index: 0, specs}) : null - isNested = false return result } if (!parsed) return [] @@ -50,13 +42,11 @@ export class Include index: 0, specs } - isNested = true for (let i = 0; i < rows.length; i++) { ctx.values = rows[i] ctx.index = 0 rows[i] = select!.mapRow(ctx) as Array } - isNested = false return rows ?? [] } diff --git a/src/driver-jsr.ts b/src/driver-jsr.ts deleted file mode 100644 index afa884d..0000000 --- a/src/driver-jsr.ts +++ /dev/null @@ -1 +0,0 @@ -export {connect as '@db/sqlite'} from './driver/denodrivers-sqlite.ts' diff --git a/src/driver.ts b/src/driver.ts index 75b2579..f709603 100644 --- a/src/driver.ts +++ b/src/driver.ts @@ -1,4 +1,3 @@ -export * from './driver-jsr.ts' export {connect as 'better-sqlite3'} from './driver/better-sqlite3.ts' export {connect as 'bun:sqlite'} from './driver/bun-sqlite.ts' export {connect as 'mysql2'} from './driver/mysql2.ts' diff --git a/src/driver/denodrivers-sqlite.ts b/src/driver/denodrivers-sqlite.ts deleted file mode 100644 index 676a9ee..0000000 --- a/src/driver/denodrivers-sqlite.ts +++ /dev/null @@ -1,79 +0,0 @@ -import type { - Database as Client, - RestBindParameters, - Statement -} from '@db/sqlite' -import {SyncDatabase, type TransactionOptions} from '../core/Database.ts' -import type {BatchQuery, SyncDriver, SyncStatement} from '../core/Driver.ts' -import {sqliteDialect} from '../sqlite.ts' -import {sqliteDiff} from '../sqlite/diff.ts' -import {execTransaction} from '../sqlite/transactions.ts' - -class PreparedStatement implements SyncStatement { - constructor(private stmt: Statement) {} - - all(params: RestBindParameters) { - return >this.stmt.all(...params) - } - - run(params: RestBindParameters) { - return this.stmt.run(...params) - } - - get(params: RestBindParameters) { - return this.stmt.get(...params) - } - - values(params: RestBindParameters) { - return this.stmt.values(...params) - } - - free() { - this.stmt.finalize() - } -} - -class DbSqliteDriver implements SyncDriver { - parsesJson = true - parsesNestedJson = false - - constructor( - private client: Client, - private depth = 0 - ) {} - - exec(query: string): void { - this.client.exec(query) - } - - close() { - this.client.close() - } - - prepare(sql: string) { - return new PreparedStatement(this.client.prepare(sql)) - } - - batch(queries: Array): Array> { - return this.transaction(tx => { - return queries.map(({sql, params}) => tx.prepare(sql).values(params)) - }, {}) - } - - transaction( - run: (inner: SyncDriver) => T, - options: TransactionOptions['sqlite'] - ): T { - return execTransaction( - this, - this.depth, - depth => new DbSqliteDriver(this.client, depth), - run, - options - ) - } -} - -export function connect(db: Client): SyncDatabase<'sqlite'> { - return new SyncDatabase(new DbSqliteDriver(db), sqliteDialect, sqliteDiff) -}