Skip to content

Commit

Permalink
model
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjrmy committed Jun 19, 2024
1 parent fb6124d commit 3c6e0ca
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Model, HasUniqueIds } from 'sutando';
import { v4 as uuid } from 'uuid';

const BaseModel = HasUniqueIds(Model) as typeof Model;

export class User extends BaseModel {
table = 'users';

id!: string;
name!: string;
email!: string;
created_at!: Date;
updated_at!: Date;

newUniqueId(): string {
return uuid();
}

relationPosts() {
return this.hasMany(Post, 'author_id');
}
}

export class Post extends BaseModel {
table = 'posts';

id!: string;
author_id!: number;
title!: string;
content!: string;
created_at!: Date;
updated_at!: Date;
published!: boolean;
views_count!: number;

casts = {
published: 'boolean'
}

newUniqueId(): string {
return uuid();
}

relationAuthor() {
return this.belongsTo(User, 'author_id');
}
}

0 comments on commit 3c6e0ca

Please sign in to comment.