Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sqljs adapter #63

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "bgent",
"version": "0.1.2",
"version": "0.1.3",
"private": false,
"description": "bgent. because agent was taken.",
"type": "module",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"jsnext:main": "dist/index.esm.js",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"jsnext:main": "dist/index.mjs",
"types": "dist/index.d.ts",
"scripts": {
"build": "rimraf ./dist && rollup -c && tsc && npm run build:docs",
Expand All @@ -19,8 +19,7 @@
"shell:cloud": "node --no-warnings scripts/shell.mjs",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --runInBand",
"test:sqlite": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" TEST_DATABASE_CLIENT=sqlite jest --runInBand",
"test:failed": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest -f --runInBand",
"test:failed:sqlite": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" TEST_DATABASE_CLIENT=sqlite jest -f --runInBand",
"test:sqljs": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" TEST_DATABASE_CLIENT=sqljs jest --runInBand",
"test:coverage": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --coverage",
"reset-profile": "rimraf ~/.cjrc",
"deploy": "wrangler deploy",
Expand All @@ -30,8 +29,8 @@
"bgent": "./scripts/shell.mjs"
},
"exports": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"license": "MIT",
"devDependencies": {
Expand All @@ -44,6 +43,7 @@
"@types/better-sqlite3": "^7.6.9",
"@types/jest": "^27.5.2",
"@types/node": "20.9.4",
"@types/sql.js": "^1.4.9",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"dotenv": "^16.4.4",
Expand Down Expand Up @@ -72,6 +72,7 @@
"better-sqlite3": "^9.4.3",
"figlet": "^1.7.0",
"inquirer": "^9.2.14",
"sql.js": "^1.10.2",
"sqlite-vss": "^0.1.2",
"unique-names-generator": "^4.7.1"
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { addHeader, composeContext } from "./lib/context";
export { DatabaseAdapter } from "./lib/database";
export { SupabaseDatabaseAdapter } from "./lib/adapters/supabase";
export { SqliteDatabaseAdapter } from "./lib/adapters/sqlite";
export { SqlJsDatabaseAdapter } from "./lib/adapters/sqljs";

import wait from "./lib/actions/wait";
export { wait };
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adapters/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
Account,
} from "../types";

import { Database } from "better-sqlite3";
import { sqliteTables } from "./sqlite/sqliteTables";

import crypto from "crypto";
import { Database } from "better-sqlite3";

export class SqliteDatabaseAdapter extends DatabaseAdapter {
db: Database;
Expand Down
46 changes: 46 additions & 0 deletions src/lib/adapters/sqlite/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
interface RunResult {
changes: number;
lastInsertRowid: number | bigint;
}
interface Statement<BindParameters extends unknown[]> {
database: Database;
source: string;
reader: boolean;
readonly: boolean;
busy: boolean;

run(...params: BindParameters): RunResult;
get(...params: BindParameters): unknown;
all(...params: BindParameters): unknown[];
iterate(...params: BindParameters): IterableIterator<unknown>;
pluck(toggleState?: boolean): this;
expand(toggleState?: boolean): this;
raw(toggleState?: boolean): this;
bind(...params: BindParameters): this;
columns(): ColumnDefinition[];
safeIntegers(toggleState?: boolean): this;
}
interface ColumnDefinition {
name: string;
column: string | null;
table: string | null;
database: string | null;
type: string | null;
}

export interface Database {
memory: boolean;
readonly: boolean;
name: string;
open: boolean;
inTransaction: boolean;

// eslint-disable-next-line @typescript-eslint/ban-types
prepare<BindParameters extends unknown[] | {} = unknown[]>(
source: string,
): BindParameters extends unknown[]
? Statement<BindParameters>
: Statement<[BindParameters]>;
exec(source: string): this;
[key: string]: unknown;
}
Loading
Loading