Added layer of abstraction for database connection
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { Database } from "@db/sqlite";
|
||||
|
||||
interface DatabaseConnection extends Disposable {
|
||||
database: Database;
|
||||
}
|
||||
|
||||
export default function connect(database: string): DatabaseConnection {
|
||||
const connection = new Database(`databases/data/${database}.db`, {
|
||||
create: false,
|
||||
});
|
||||
|
||||
connection.run("attach database 'databases/data/students.db' as students");
|
||||
|
||||
return {
|
||||
database: connection,
|
||||
[Symbol.dispose]: () => {
|
||||
connection.close();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,9 @@
|
||||
create table promotions (
|
||||
id integer primary key autoincrement,
|
||||
endyear integer,
|
||||
current integer
|
||||
);
|
||||
|
||||
create table students (
|
||||
userId text primary key,
|
||||
firstName text,
|
||||
@@ -5,10 +11,4 @@ create table students (
|
||||
mail text,
|
||||
promo integer,
|
||||
foreign key(promo) references promo(id)
|
||||
);
|
||||
|
||||
create table promo (
|
||||
id integer,
|
||||
endyear integer,
|
||||
current integer
|
||||
);
|
||||
Reference in New Issue
Block a user