Added Sequelize based models
This commit is contained in:
parent
b1974ce50e
commit
c036418a87
@ -1,5 +1,5 @@
|
||||
import Gens from "@/gens";
|
||||
import { Sequelize, DataTypes, Association } from 'sequelize';
|
||||
import { Sequelize, DataTypes, Association, UUIDV4 } from 'sequelize';
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
@ -19,9 +19,13 @@ export const MAuth = sequelize.define('Auth', {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true
|
||||
},
|
||||
token: DataTypes.STRING,
|
||||
token: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: UUIDV4
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
key: "User"
|
||||
}
|
||||
// date: DataTypes.DATE,
|
||||
});
|
||||
|
||||
38
src/model/sequelize/Auth.ts
Normal file
38
src/model/sequelize/Auth.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { Sequelize, DataTypes, Optional, Model, UUIDV4 } from 'sequelize';
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
interface AuthAttributes{
|
||||
id: number;
|
||||
token: string;
|
||||
user_id: number;
|
||||
};
|
||||
interface AuthCreationAttributes extends Optional<Optional<AuthAttributes, 'id'>,'token'> {};
|
||||
class AuthModel extends Model<AuthAttributes, AuthCreationAttributes>{
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
token: any;
|
||||
// declare title
|
||||
}
|
||||
export const MAuth = sequelize.define<AuthModel>(
|
||||
'Auth',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
token: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: UUIDV4
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
key: "User"
|
||||
}
|
||||
// date: DataTypes.DATE,
|
||||
}
|
||||
);
|
||||
32
src/model/sequelize/Post.ts
Normal file
32
src/model/sequelize/Post.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { Sequelize, DataTypes, Optional, Model } from 'sequelize';
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
interface PostAttributes{
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
};
|
||||
interface PostCreationAttributes extends Optional<PostAttributes, 'id'>{};
|
||||
class PostModel extends Model<PostAttributes, PostCreationAttributes>{
|
||||
username:string = "";
|
||||
password:string = "";
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
// declare title
|
||||
}
|
||||
export const MPost = sequelize.define<PostModel>(
|
||||
'Post',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
title: DataTypes.STRING,
|
||||
content: DataTypes.STRING,
|
||||
}
|
||||
);
|
||||
Loading…
x
Reference in New Issue
Block a user