53 lines
950 B
TypeScript
53 lines
950 B
TypeScript
import { PrimaryKey, ForeignKey, HasMany, 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 type: string;
|
|
|
|
@Column
|
|
public content: string;
|
|
}
|
|
|
|
@Table
|
|
export class Exercise extends Model {
|
|
@PrimaryKey
|
|
@Column
|
|
public name: string;
|
|
|
|
@HasMany(() => Grader)
|
|
public graders: Grader[];
|
|
}
|
|
|
|
@Table
|
|
export class Grader extends Model {
|
|
@PrimaryKey
|
|
@ForeignKey(() => Exercise)
|
|
@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;
|
|
}
|