37 lines
998 B
TypeScript
37 lines
998 B
TypeScript
import { Association, BelongsToGetAssociationMixin, CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, Sequelize, UUIDV4 } from "sequelize";
|
|
import { User } from "./User";
|
|
|
|
|
|
const sequelize = new Sequelize({
|
|
dialect: 'sqlite',
|
|
storage: 'db.sqlite'
|
|
});
|
|
|
|
|
|
export class Auth extends Model<InferAttributes<Auth>, InferCreationAttributes<Auth>> {
|
|
declare id: CreationOptional<number>;
|
|
declare token: CreationOptional<string>;
|
|
declare user_id:ForeignKey<User['id']>;
|
|
declare getUser: BelongsToGetAssociationMixin<User>;
|
|
declare static associations: {
|
|
user: Association<User, Auth>;
|
|
};
|
|
}
|
|
|
|
Auth.init({
|
|
id: {
|
|
allowNull: false,
|
|
autoIncrement: true,
|
|
type: DataTypes.INTEGER,
|
|
primaryKey: true,
|
|
unique: true,
|
|
},
|
|
token: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: UUIDV4
|
|
}
|
|
},
|
|
{
|
|
tableName: 'Auths',
|
|
sequelize // passing the `sequelize` instance is required
|
|
}); |