auto create databse folder
This commit is contained in:
parent
b3dec297df
commit
f2f80dd2f7
2 changed files with 10 additions and 0 deletions
|
@ -36,6 +36,7 @@ The recommended Node.JS version is v21.5.0, others should also work.
|
||||||
* You may need to [enable Corepack](https://nodejs.org/api/corepack.html).
|
* You may need to [enable Corepack](https://nodejs.org/api/corepack.html).
|
||||||
3. Run `yarn start` to start the server.
|
3. Run `yarn start` to start the server.
|
||||||
* **Note:** The `asset-api` server **must** be running before this command is run. [More info](./docs/asset-implementation.md).
|
* **Note:** The `asset-api` server **must** be running before this command is run. [More info](./docs/asset-implementation.md).
|
||||||
|
* You may need to create an empty folder at `$/identity-api/.database`.
|
||||||
4. You're ready to go! You will need to restart the server manually when you make changed (unless you use something like [Nodemon](https://www.npmjs.com/package/nodemon)).
|
4. You're ready to go! You will need to restart the server manually when you make changed (unless you use something like [Nodemon](https://www.npmjs.com/package/nodemon)).
|
||||||
|
|
||||||
#### `asset-api`
|
#### `asset-api`
|
||||||
|
|
|
@ -20,6 +20,9 @@ import { SQLITE_PATH } from "./consts.js";
|
||||||
import { sqliteTable } from "drizzle-orm/sqlite-core";
|
import { sqliteTable } from "drizzle-orm/sqlite-core";
|
||||||
import { text, integer } from "drizzle-orm/sqlite-core";
|
import { text, integer } from "drizzle-orm/sqlite-core";
|
||||||
import { asc, desc, eq, sql } from "drizzle-orm";
|
import { asc, desc, eq, sql } from "drizzle-orm";
|
||||||
|
import { join } from "path";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
import { mkdir } from "fs/promises";
|
||||||
|
|
||||||
export type DatabaseInterface = Awaited<ReturnType<typeof startDatabase>>;
|
export type DatabaseInterface = Awaited<ReturnType<typeof startDatabase>>;
|
||||||
|
|
||||||
|
@ -32,6 +35,12 @@ export function fromDBList<T>(input: string): Array<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startDatabase() {
|
export async function startDatabase() {
|
||||||
|
let dir = join(SQLITE_PATH, "..");
|
||||||
|
if (!existsSync(dir)) {
|
||||||
|
console.warn("The database folder does not exist. It will be created.")
|
||||||
|
await mkdir(dir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
let sqlite = new Database(SQLITE_PATH);
|
let sqlite = new Database(SQLITE_PATH);
|
||||||
let database = drizzle(sqlite);
|
let database = drizzle(sqlite);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue