Huge number of changes, upgrade to next 15, add loads of pages, auth, add ci, loads of clean up, a db for images etc
This commit is contained in:
32
src/data-source.ts
Normal file
32
src/data-source.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { DataSource } from "typeorm";
|
||||
import { Photo } from "./entity/photo";
|
||||
|
||||
const dataSource = new DataSource({
|
||||
type: "better-sqlite3",
|
||||
database: "db.sql",
|
||||
entities: [Photo],
|
||||
migrations: ["./migrations"],
|
||||
})
|
||||
|
||||
export default class PhotoDataSource {
|
||||
private static _dataSource: DataSource | null = null;
|
||||
|
||||
static get dataSource(): Promise<DataSource> {
|
||||
if (PhotoDataSource._dataSource === null) {
|
||||
return PhotoDataSource.initDataSource();
|
||||
} else {
|
||||
return Promise.resolve(PhotoDataSource._dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
static async initDataSource(): Promise<DataSource> {
|
||||
if (!PhotoDataSource._dataSource || !PhotoDataSource._dataSource.isInitialized) {
|
||||
const ds = await dataSource.initialize();
|
||||
console.log('Photo data source initialized')
|
||||
PhotoDataSource._dataSource = ds;
|
||||
}
|
||||
return PhotoDataSource._dataSource;
|
||||
}
|
||||
}
|
||||
|
||||
PhotoDataSource.initDataSource();
|
||||
Reference in New Issue
Block a user