-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for both wasm/ffi version of sqlite3
- Loading branch information
Showing
12 changed files
with
117 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
"@lit-labs/react/": "https://esm.sh/@lit-labs/[email protected]/", | ||
"bootstrap/": "https://esm.sh/[email protected]/", | ||
"filesize": "https://esm.sh/[email protected]", | ||
"pwn/": "https://deno.land/x/[email protected]/" | ||
"pwn/": "https://deno.land/x/[email protected]/", | ||
"sqlite3/": "https://deno.land/x/[email protected]/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Database, DatabaseOpenOptions } from "sqlite3/mod.ts"; | ||
import { QueryParameterSet, Row, RowObject } from "./db_interface.ts"; | ||
|
||
export class DbFfi { | ||
db; | ||
constructor(path: string, options?: DatabaseOpenOptions) { | ||
this.db = new Database(path, options); | ||
} | ||
|
||
close(_force?: boolean) { | ||
this.db.close(); | ||
} | ||
|
||
execute(sql: string) { | ||
this.db.exec(sql); | ||
} | ||
|
||
query<R extends Row = Row>( | ||
sql: string, | ||
params?: QueryParameterSet, | ||
): Array<R> { | ||
return this.db.prepare(sql).values(params); | ||
} | ||
|
||
queryEntries<O extends RowObject = RowObject>( | ||
sql: string, | ||
params?: QueryParameterSet, | ||
): Array<O> { | ||
return this.db.prepare(sql).all(params); | ||
} | ||
|
||
transaction<V>(fn: () => V): V { | ||
const re = this.db.transaction(fn); | ||
return re(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export type Row = Array<unknown>; | ||
export type RowObject = Record<string, unknown>; | ||
export type QueryParameter = | ||
| boolean | ||
| number | ||
| bigint | ||
| string | ||
| null | ||
| undefined | ||
| Date | ||
| Uint8Array; | ||
export type QueryParameterSet = | ||
| Record<string, QueryParameter> | ||
| Array<QueryParameter>; | ||
|
||
export interface Db { | ||
close(force?: boolean): void; | ||
execute(sql: string): void; | ||
query<R extends Row = Row>( | ||
sql: string, | ||
params?: QueryParameterSet, | ||
): Array<R>; | ||
queryEntries<O extends RowObject = RowObject>( | ||
sql: string, | ||
params?: QueryParameterSet, | ||
): Array<O>; | ||
transaction<V>(fn: () => V): V; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { DB, SqliteOptions } from "sqlite/mod.ts"; | ||
|
||
export class DbWasm extends DB { | ||
constructor(dbPath: string, options?: SqliteOptions) { | ||
super(dbPath, options); | ||
} | ||
} |