mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-21 08:15:12 +02:00
Added & configured typeorm for storing settings
This commit is contained in:
35
src/lib/db.ts
Normal file
35
src/lib/db.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'reflect-metadata';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { Settings } from './entities/Settings';
|
||||
|
||||
class TypeOrm {
|
||||
private static instance: Promise<DataSource | null> | null = null;
|
||||
|
||||
private constructor() {
|
||||
// Private constructor to prevent external instantiation
|
||||
}
|
||||
|
||||
public static getDb(): Promise<DataSource | null> {
|
||||
if (!TypeOrm.instance) {
|
||||
TypeOrm.instance = new DataSource({
|
||||
type: 'sqlite',
|
||||
database: 'config/reiverr.sqlite',
|
||||
synchronize: true,
|
||||
entities: [Settings],
|
||||
logging: true
|
||||
})
|
||||
.initialize()
|
||||
.then((fulfilled) => {
|
||||
console.info('Data Source has been initialized!');
|
||||
return fulfilled;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Error during Data Source initialization', err);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
return TypeOrm.instance;
|
||||
}
|
||||
}
|
||||
|
||||
export default TypeOrm;
|
||||
Reference in New Issue
Block a user