changes
This commit is contained in:
+15
-33
@@ -1,11 +1,9 @@
|
||||
import { Association, BelongsToGetAssociationMixin, CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";import { User } from "./User";
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
|
||||
import { Post } from "./Post";
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
export type ProjectAttributes = {
|
||||
id: number;
|
||||
title: string;
|
||||
@@ -20,37 +18,21 @@ export type ProjectCreationAttributes = {
|
||||
user_id:number;
|
||||
}
|
||||
export class Project extends Model<ProjectAttributes, ProjectCreationAttributes> {
|
||||
@Attribute(DataTypes.INTEGER) @PrimaryKey @Unique @AutoIncrement
|
||||
declare id: number;
|
||||
declare user:NonAttribute<User>;
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
declare getUser: BelongsToGetAssociationMixin<User>;
|
||||
@Attribute(DataTypes.STRING) @Unique
|
||||
declare readableIdentifier: string;
|
||||
@Attribute(DataTypes.STRING)
|
||||
declare name: string;
|
||||
|
||||
declare static associations: {
|
||||
user: Association<User, Project>;
|
||||
posts: Association<Post, Project>;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Project.init(
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
content: {
|
||||
type: DataTypes.STRING
|
||||
},
|
||||
title: {
|
||||
type: DataTypes.STRING
|
||||
},
|
||||
date: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
tableName: 'Projects',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
}
|
||||
);
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
models: [Project]
|
||||
})
|
||||
|
||||
+2
-4
@@ -10,12 +10,10 @@ export class Tag extends Model<InferAttributes<Tag>, InferCreationAttributes<Tag
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@Unique
|
||||
declare id: number;
|
||||
|
||||
/** Defined by {@link Post.postTags} */
|
||||
declare taggedPosts?:NonAttribute<Post[]>;
|
||||
|
||||
declare user_id:ForeignKey<Tag>;
|
||||
declare getPost: BelongsToManyGetAssociationsMixin<Tag>;
|
||||
declare getPosts: BelongsToManyGetAssociationsMixin<Post>;
|
||||
|
||||
declare static associations: {
|
||||
posts: Association<Post, Tag>;
|
||||
};
|
||||
|
||||
+3
-2
@@ -55,9 +55,10 @@ export class User extends Model<InferAttributes<User>, InferCreationAttributes<U
|
||||
/** Defined by {@link Post.user} */
|
||||
declare posts?:CreationOptional<Post[]>
|
||||
|
||||
|
||||
declare static associations: {
|
||||
perms: Association<UserPerms,User>;
|
||||
posts: Association<Post,User>
|
||||
perms: Association<UserPerms,User>;
|
||||
posts: Association<Post,User>
|
||||
authtokens: Association<Auth,User>;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user