2026-02-14 18:05:11 +09:00
|
|
|
import { existsSync } from "node:fs"
|
|
|
|
|
import { join } from "node:path"
|
|
|
|
|
import { getDataDir } from "./data-path"
|
|
|
|
|
import { isOpenCodeVersionAtLeast, OPENCODE_SQLITE_VERSION } from "./opencode-version"
|
|
|
|
|
|
2026-02-14 19:24:30 +09:00
|
|
|
const NOT_CACHED = Symbol("NOT_CACHED")
|
|
|
|
|
let cachedResult: boolean | typeof NOT_CACHED = NOT_CACHED
|
2026-02-14 18:05:11 +09:00
|
|
|
|
|
|
|
|
export function isSqliteBackend(): boolean {
|
2026-02-14 19:24:30 +09:00
|
|
|
if (cachedResult !== NOT_CACHED) {
|
2026-02-14 18:05:11 +09:00
|
|
|
return cachedResult
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const versionOk = isOpenCodeVersionAtLeast(OPENCODE_SQLITE_VERSION)
|
|
|
|
|
const dbPath = join(getDataDir(), "opencode", "opencode.db")
|
|
|
|
|
const dbExists = existsSync(dbPath)
|
|
|
|
|
|
|
|
|
|
cachedResult = versionOk && dbExists
|
|
|
|
|
return cachedResult
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function resetSqliteBackendCache(): void {
|
2026-02-14 19:24:30 +09:00
|
|
|
cachedResult = NOT_CACHED
|
2026-02-14 18:05:11 +09:00
|
|
|
}
|