55 lines
917 B
TypeScript
55 lines
917 B
TypeScript
|
import { PrimaryKey, Sequelize, Column, Table, Model, DataType } from "sequelize-typescript";
|
||
|
|
||
|
@Table
|
||
|
export class Page extends Model {
|
||
|
@PrimaryKey
|
||
|
@Column
|
||
|
public slug: string;
|
||
|
|
||
|
@Column
|
||
|
public title: string;
|
||
|
|
||
|
@Column
|
||
|
public content: string;
|
||
|
}
|
||
|
|
||
|
@Table
|
||
|
export class Exercise extends Model {
|
||
|
@PrimaryKey
|
||
|
@Column
|
||
|
public page_slug: string;
|
||
|
|
||
|
@PrimaryKey
|
||
|
@Column
|
||
|
public name: string;
|
||
|
}
|
||
|
|
||
|
@Table
|
||
|
export class Grader extends Model {
|
||
|
@PrimaryKey
|
||
|
@Column
|
||
|
public page_slug: string;
|
||
|
|
||
|
@PrimaryKey
|
||
|
@Column
|
||
|
public exercise_name: string;
|
||
|
|
||
|
@PrimaryKey
|
||
|
@Column
|
||
|
public language: string;
|
||
|
|
||
|
@Column
|
||
|
public style: string;
|
||
|
|
||
|
@Column(DataType.JSON)
|
||
|
public props: any;
|
||
|
}
|
||
|
|
||
|
export async function init(path: string): Promise<Sequelize> {
|
||
|
let sequelize = new Sequelize(`sqlite:${path}`, {
|
||
|
models: [Page, Exercise, Grader],
|
||
|
});
|
||
|
await sequelize.sync({ force: true });
|
||
|
return sequelize;
|
||
|
}
|