2024-04-21 05:26:29 +00:00
|
|
|
import { DataSource } from "typeorm";
|
2024-05-18 20:55:12 +00:00
|
|
|
import { Game, GameShopCache, Repack, UserPreferences } from "@main/entity";
|
|
|
|
import type { BetterSqlite3ConnectionOptions } from "typeorm/driver/better-sqlite3/BetterSqlite3ConnectionOptions";
|
2024-04-21 05:26:29 +00:00
|
|
|
|
|
|
|
import { databasePath } from "./constants";
|
2024-05-16 23:30:08 +00:00
|
|
|
import migrations from "./migrations";
|
2024-04-21 05:26:29 +00:00
|
|
|
|
2024-05-18 20:55:12 +00:00
|
|
|
export const createDataSource = (
|
|
|
|
options: Partial<BetterSqlite3ConnectionOptions>
|
|
|
|
) =>
|
2024-04-21 05:26:29 +00:00
|
|
|
new DataSource({
|
|
|
|
type: "better-sqlite3",
|
2024-05-18 20:55:12 +00:00
|
|
|
entities: [Game, Repack, UserPreferences, GameShopCache],
|
2024-05-14 16:12:19 +00:00
|
|
|
synchronize: true,
|
2024-05-18 20:55:12 +00:00
|
|
|
database: databasePath,
|
2024-04-21 05:26:29 +00:00
|
|
|
...options,
|
|
|
|
});
|
|
|
|
|
2024-05-17 02:54:27 +00:00
|
|
|
export const dataSource = createDataSource({
|
2024-05-18 20:55:12 +00:00
|
|
|
migrations,
|
2024-05-17 02:54:27 +00:00
|
|
|
});
|