-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathknexfile.ts
52 lines (46 loc) · 1.4 KB
/
knexfile.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { join } from "path";
import type { Knex } from "knex";
import sqliteVec from "sqlite-vec";
import { app } from "electron";
export const getConfig = (filename: string): Knex.Config => {
const isProd = app?.isPackaged || false;
const migrationsPath = isProd
? join(process.resourcesPath, "migrations")
: join("./src", "main", "migrations");
console.log(`Using migrations from ${migrationsPath}`);
console.log(`Production mode: ${isProd}`);
let sqliteVecPath = sqliteVec.getLoadablePath().replace(/\.[^.]+$/, "");
if (sqliteVecPath.includes("app.asar")) {
sqliteVecPath = sqliteVecPath.replace("app.asar", "app.asar.unpacked");
}
console.log(`Loading sqlite-vec extension from ${sqliteVecPath}`);
return {
client: "better-sqlite3",
connection: {
filename,
driver: require("better-sqlite3"),
},
pool: {
afterCreate: (conn: any, cb: Function) => {
conn.loadExtension(sqliteVecPath);
cb();
},
},
useNullAsDefault: true,
migrations: {
directory: migrationsPath,
loadExtensions: [".js"],
extension: "js",
},
};
};
const defaultDbDir = join(
process.env.APPDATA ||
(process.platform == "darwin"
? join(process.env.HOME!, "Library", "Application Support")
: join(process.env.HOME!, ".local", "share")),
"delta",
"delta_data",
"delta.db",
);
export default getConfig(defaultDbDir);