refactor(server): inject database options
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { Argv } from "yargs"
|
||||
import { spawn } from "child_process"
|
||||
import { Database } from "@opencode-ai/core/database/database"
|
||||
import { InstallationDatabase } from "@/installation/database"
|
||||
import { Effect } from "effect"
|
||||
import { sql } from "drizzle-orm"
|
||||
import { effectCmd } from "../effect-cmd"
|
||||
@@ -35,7 +36,7 @@ const QueryCommand = effectCmd({
|
||||
}
|
||||
return
|
||||
}
|
||||
const child = spawn("sqlite3", [Database.path()], {
|
||||
const child = spawn("sqlite3", [InstallationDatabase.path()], {
|
||||
stdio: "inherit",
|
||||
})
|
||||
yield* Effect.promise(() => new Promise((resolve) => child.on("close", resolve)))
|
||||
@@ -47,7 +48,7 @@ const PathCommand = effectCmd({
|
||||
describe: "print the database path",
|
||||
instance: false,
|
||||
handler: Effect.fn("Cli.db.path")(function* () {
|
||||
console.log(Database.path())
|
||||
console.log(InstallationDatabase.path())
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
export * as InstallationDatabase from "./database"
|
||||
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
import { Global } from "@opencode-ai/core/global"
|
||||
import { InstallationChannel } from "@opencode-ai/core/installation/version"
|
||||
import { isAbsolute, join } from "node:path"
|
||||
|
||||
export function path() {
|
||||
if (Flag.OPENCODE_DB) {
|
||||
if (Flag.OPENCODE_DB === ":memory:" || isAbsolute(Flag.OPENCODE_DB)) return Flag.OPENCODE_DB
|
||||
return join(Global.Path.data, Flag.OPENCODE_DB)
|
||||
}
|
||||
if (
|
||||
["latest", "beta", "prod"].includes(InstallationChannel) ||
|
||||
process.env.OPENCODE_DISABLE_CHANNEL_DB === "1" ||
|
||||
process.env.OPENCODE_DISABLE_CHANNEL_DB === "true"
|
||||
)
|
||||
return join(Global.Path.data, "opencode.db")
|
||||
return join(Global.Path.data, `opencode-${InstallationChannel.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
|
||||
}
|
||||
Reference in New Issue
Block a user