Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Jul 6, 2024
1 parent 1e32338 commit 07cabf5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions dev-server-api/src/db/get-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ export type DbClient = Kysely<KyselyDatabaseSchema>
let globalDb: Kysely<KyselyDatabaseSchema> | undefined

export const getDbFilePath = () =>
process.env.TSCI_DEV_SERVER_DB ?? "./.tscircuit/dev-server.sqlite"
process.env.TSCI_DEV_SERVER_DB ?? "./.tscircuit/devdb.json"

export const getDb = async (): Promise<Kysely<KyselyDatabaseSchema>> => {
if (globalDb) return globalDb

const devServerDbPath = getDbFilePath()
// console.log(`Using dev server db at ${devServerDbPath}`)

mkdirSync(Path.dirname(devServerDbPath), { recursive: true })

Expand All @@ -77,7 +78,7 @@ export const getDb = async (): Promise<Kysely<KyselyDatabaseSchema>> => {
create: true,
}),
})
} catch (e) { }
} catch (e) {}
}

if (!dialect) {
Expand All @@ -87,7 +88,7 @@ export const getDb = async (): Promise<Kysely<KyselyDatabaseSchema>> => {
dialect = new SqliteDialect({
database: new BetterSqlite3.default(devServerDbPath),
})
} catch (e) { }
} catch (e) {}
}

if (!dialect) {
Expand All @@ -114,4 +115,4 @@ export const getDb = async (): Promise<Kysely<KyselyDatabaseSchema>> => {
globalDb = db

return db
}
}
2 changes: 2 additions & 0 deletions dev-server-api/tests/fixtures/get-test-server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { afterEach } from "bun:test"
import defaultAxios from "redaxios"
import { startServer } from "./start-server"
import { tmpdir } from "node:os"

interface TestFixture {
url: string
Expand All @@ -9,6 +10,7 @@ interface TestFixture {
}

export const getTestFixture = async (): Promise<TestFixture> => {
process.env.TSCI_DEV_SERVER_DB = tmpdir() + "/devdb.json"
const port = 3001 + Math.floor(Math.random() * 999)
const server = startServer({ port })
const url = `http://localhost:${port}`
Expand Down

0 comments on commit 07cabf5

Please sign in to comment.