Skip to content

Commit

Permalink
Don't load sqlite-vss inside the adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Mar 20, 2024
1 parent 04e5588 commit 777981e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/lib/adapters/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ import {
} from "../types";

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

import crypto from "crypto";

export class SqliteDatabaseAdapter extends DatabaseAdapter {
private db: Database;
db: Database;

constructor(db: Database) {
super();
this.db = db;
load(this.db);
// sqliteTables is a string of SQL commands
this.db.exec(sqliteTables);
this.db.exec("PRAGMA foreign_keys = OFF;");

// Check if the 'accounts' table exists as a representative table
const tableExists = this.db
.prepare(
"SELECT name FROM sqlite_master WHERE type='table' AND name='accounts'",
)
.get();

if (!tableExists) {
// If the 'accounts' table doesn't exist, create all the tables
this.db.exec(sqliteTables);
}
}

async getAccountById(userId: UUID): Promise<Account | null> {
Expand Down
3 changes: 3 additions & 0 deletions src/test/createRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
TEST_PASSWORD,
} from "./constants";
import { User } from "./types";
import { load } from "../lib/adapters/sqlite/sqlite_vss";

export async function createRuntime({
env,
Expand All @@ -37,6 +38,8 @@ export async function createRuntime({
// SQLite adapter
adapter = new SqliteDatabaseAdapter(new Database(":memory:"));

// Load sqlite-vss
load((adapter as SqliteDatabaseAdapter).db);
// Create a test user and session
user = {
id: zeroUuid,
Expand Down

0 comments on commit 777981e

Please sign in to comment.