Added Sequelize based models

This commit is contained in:
2023-06-12 05:02:26 +02:00
parent b1974ce50e
commit c036418a87
3 changed files with 76 additions and 2 deletions
+38
View 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,
}
);