eduproj/compile-database/db.ts

24 lines
473 B
TypeScript
Raw Normal View History

2021-08-28 18:03:38 +00:00
import { PrimaryKey, Sequelize, Column, Table, Model } from "sequelize-typescript";
2021-08-28 10:52:47 +00:00
2021-08-28 18:03:38 +00:00
@Table
export class Page extends Model {
@PrimaryKey
@Column
public slug: string;
2021-08-28 10:52:47 +00:00
2021-08-28 18:03:38 +00:00
@Column
public title: string;
}
2021-08-28 10:52:47 +00:00
2021-08-28 18:03:38 +00:00
@Table
export class Exercise extends Model {
}
2021-08-28 10:52:47 +00:00
2021-08-28 18:03:38 +00:00
export async function init(path: string): Promise<Sequelize> {
let sequelize = new Sequelize(`sqlite:${path}`, {
models: [Page, Exercise],
});
await sequelize.sync({ force: true });
2021-08-28 10:52:47 +00:00
return sequelize;
}