hydra/src/main/data-source.ts

28 lines
695 B
TypeScript
Raw Normal View History

2024-04-21 05:26:29 +00:00
import { DataSource } from "typeorm";
2024-06-03 01:12:05 +00:00
import {
DownloadSource,
Game,
GameShopCache,
Repack,
UserPreferences,
} from "@main/entity";
2024-05-18 20:55:12 +00:00
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-06-03 01:12:05 +00:00
entities: [Game, Repack, UserPreferences, GameShopCache, DownloadSource],
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,
});
export const dataSource = createDataSource({
2024-05-18 20:55:12 +00:00
migrations,
});