Yea
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
import Gens from "@/gens";
|
||||
import { Sequelize, DataTypes, Association, UUIDV4 } from 'sequelize';
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
export const MPost = sequelize.define('Post', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true
|
||||
},
|
||||
title: DataTypes.STRING,
|
||||
content: DataTypes.STRING,
|
||||
// date: DataTypes.DATE,
|
||||
});
|
||||
export const MAuth = sequelize.define('Auth', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true
|
||||
},
|
||||
token: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: UUIDV4
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
key: "User"
|
||||
}
|
||||
// date: DataTypes.DATE,
|
||||
});
|
||||
export const MUser = sequelize.define('User', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true
|
||||
},
|
||||
username: DataTypes.STRING,
|
||||
password: DataTypes.STRING,
|
||||
// date: DataTypes.DATE,
|
||||
});
|
||||
|
||||
MAuth.hasOne(MUser)
|
||||
|
||||
|
||||
export type Post = {
|
||||
id: Number,
|
||||
title: String,
|
||||
content: String,
|
||||
date?: String,
|
||||
}
|
||||
|
||||
export const postPlaceholder:Post = {
|
||||
id: -1,
|
||||
title: 'Lorem Ipsum',
|
||||
content: Gens.loremipsum()
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
type Post = {
|
||||
id: Number,
|
||||
title: String,
|
||||
content: String,
|
||||
date?: String,
|
||||
}
|
||||
|
||||
export type { Post }
|
||||
@@ -1,41 +0,0 @@
|
||||
import { Sequelize, DataTypes, Optional, Model, UUIDV4 } from 'sequelize';
|
||||
import { MPost } from '@/model/sequelize/Post';
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
interface AttachmentAttributes{
|
||||
id: string;
|
||||
path: string;
|
||||
post_id: number;
|
||||
};
|
||||
interface AttachmentCreationAttributes extends Optional<AttachmentAttributes, 'id'>{};
|
||||
class AttachmentModel extends Model<AttachmentAttributes, AttachmentCreationAttributes>{
|
||||
id:string = "";
|
||||
path:string = "";
|
||||
post_id:number|undefined;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
// declare title
|
||||
}
|
||||
export const MAttachment = sequelize.define<AttachmentModel>(
|
||||
'Attachment',
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: false,
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: UUIDV4,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
path: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
post_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
key: "Post"
|
||||
}
|
||||
}
|
||||
);
|
||||
MAttachment.hasOne(MPost);
|
||||
@@ -1,73 +0,0 @@
|
||||
// import { Sequelize, DataTypes, Optional, Model, UUIDV4 } from 'sequelize';
|
||||
import {
|
||||
Association, DataTypes, HasManyAddAssociationMixin, HasManyCountAssociationsMixin,
|
||||
HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, HasManyHasAssociationMixin,
|
||||
HasManySetAssociationsMixin, HasManyAddAssociationsMixin, HasManyHasAssociationsMixin,
|
||||
HasManyRemoveAssociationMixin, HasManyRemoveAssociationsMixin, Model, ModelDefined, Optional,
|
||||
Sequelize, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ForeignKey, BelongsTo, BelongsToGetAssociationMixin, UUIDV4, UUID
|
||||
} from 'sequelize';
|
||||
|
||||
import { MUser, UserModel } from '@/model/sequelize/User';
|
||||
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
|
||||
// }
|
||||
class AuthModel extends Model<InferAttributes<AuthModel, { omit: 'user' }>, InferCreationAttributes<AuthModel, { omit: 'user' }>> {
|
||||
declare id: CreationOptional<number>;
|
||||
declare token: CreationOptional<string>;
|
||||
declare user_id: number;
|
||||
declare getUser: BelongsToGetAssociationMixin<UserModel>;
|
||||
declare user:NonAttribute<UserModel>;
|
||||
}
|
||||
export const MAuth = AuthModel.init(
|
||||
{
|
||||
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,
|
||||
},
|
||||
{
|
||||
tableName: 'Auths',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
}
|
||||
);
|
||||
|
||||
MAuth.belongsTo(MUser, {
|
||||
foreignKey:'user_id',
|
||||
targetKey:'id',
|
||||
as: 'user'
|
||||
})
|
||||
|
||||
MUser.hasMany(MAuth, {
|
||||
sourceKey: 'id',
|
||||
foreignKey: 'user_id',
|
||||
as: 'authtokens' // this determines the name in `associations`!
|
||||
});
|
||||
// MAuth.belongsTo(MUser, { targetKey: 'id' });
|
||||
// MAuth.sync();
|
||||
|
||||
export { AuthModel }
|
||||
@@ -0,0 +1,144 @@
|
||||
import {
|
||||
Association, DataTypes, HasManyAddAssociationMixin, HasManyCountAssociationsMixin,
|
||||
HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, HasManyHasAssociationMixin,
|
||||
HasManySetAssociationsMixin, HasManyAddAssociationsMixin, HasManyHasAssociationsMixin,
|
||||
HasManyRemoveAssociationMixin, HasManyRemoveAssociationsMixin, Model, ModelDefined, Optional,
|
||||
Sequelize, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ForeignKey, BelongsTo, BelongsToGetAssociationMixin, UUIDV4, UUID,
|
||||
VirtualDataType
|
||||
} from 'sequelize';
|
||||
|
||||
|
||||
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:NonAttribute<User>;
|
||||
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
|
||||
});
|
||||
|
||||
|
||||
export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<Post>> {
|
||||
declare id: number|null;
|
||||
declare title: string;
|
||||
declare content: string;
|
||||
declare date: number;
|
||||
declare user:NonAttribute<User>;
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
declare getUser: BelongsToGetAssociationMixin<User>;
|
||||
declare static associations: {
|
||||
user: Association<User, Post>;
|
||||
};
|
||||
}
|
||||
Post.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: 'Posts',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
}
|
||||
);
|
||||
export class User extends Model<InferAttributes<User>, InferCreationAttributes<User>>{
|
||||
declare id: number|null;
|
||||
declare username: string;
|
||||
declare password: string;
|
||||
declare getAuthTokens:HasManyGetAssociationsMixin<Auth>;
|
||||
declare getPosts:HasManyGetAssociationsMixin<Post>;
|
||||
}
|
||||
|
||||
User.init(
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
username: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
password: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
defaultScope: {
|
||||
attributes:{
|
||||
exclude:['password']
|
||||
}
|
||||
},
|
||||
tableName: 'Users',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
}
|
||||
);
|
||||
User.scope
|
||||
|
||||
Auth.belongsTo(User, {
|
||||
foreignKey:'user_id',
|
||||
targetKey:'id',
|
||||
as: 'user',
|
||||
})
|
||||
User.hasMany(Auth, {
|
||||
sourceKey: 'id',
|
||||
foreignKey: 'user_id',
|
||||
as: 'authtokens' // this determines the name in `associations`!
|
||||
});
|
||||
Post.belongsTo(User, {
|
||||
foreignKey:'user_id',
|
||||
targetKey:'id',
|
||||
as: 'user'
|
||||
})
|
||||
User.hasMany(Post, {
|
||||
sourceKey: 'id',
|
||||
foreignKey: 'user_id',
|
||||
as: 'posts' // this determines the name in `associations`!
|
||||
});
|
||||
|
||||
User.sync();
|
||||
Auth.sync();
|
||||
Post.sync();
|
||||
@@ -1,34 +0,0 @@
|
||||
import { Sequelize, DataTypes, Optional, Model } from 'sequelize';
|
||||
import { MAttachment } from '@/model/sequelize/Attachment';
|
||||
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,
|
||||
}
|
||||
);
|
||||
MPost.hasMany(MAttachment);
|
||||
@@ -1,73 +0,0 @@
|
||||
import { BelongsToGetAssociationMixin, UUIDV4 } from 'sequelize';
|
||||
import {
|
||||
Association, DataTypes, HasManyAddAssociationMixin, HasManyCountAssociationsMixin,
|
||||
HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, HasManyHasAssociationMixin,
|
||||
HasManySetAssociationsMixin, HasManyAddAssociationsMixin, HasManyHasAssociationsMixin,
|
||||
HasManyRemoveAssociationMixin, HasManyRemoveAssociationsMixin, Model, ModelDefined, Optional,
|
||||
Sequelize, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ForeignKey,
|
||||
} from 'sequelize';
|
||||
import { UserModel } from '@/model/sequelize/User';
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
class ResourceModel extends Model<InferAttributes<ResourceModel, { omit: 'owner' }>, InferCreationAttributes<ResourceModel, { omit: 'owner' }>>{
|
||||
declare id: CreationOptional<string>;
|
||||
declare path: string;
|
||||
declare owner: NonAttribute<UserModel>;
|
||||
declare getOwner: BelongsToGetAssociationMixin<UserModel>;
|
||||
|
||||
// user_id: number | undefined;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
// declare title
|
||||
declare static associations: {
|
||||
owner: Association<ResourceModel,UserModel>;
|
||||
};
|
||||
}
|
||||
|
||||
ResourceModel.init({
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: false,
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: UUIDV4,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
path: {
|
||||
type: DataTypes.STRING
|
||||
},
|
||||
createdAt: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
type: DataTypes.DATE
|
||||
}
|
||||
},{
|
||||
sequelize,
|
||||
tableName: 'Resource'
|
||||
});
|
||||
// export const MResource = sequelize.define<ResourceModel>(
|
||||
// 'Resource',
|
||||
// {
|
||||
// id: {
|
||||
// allowNull: false,
|
||||
// autoIncrement: false,
|
||||
// type: DataTypes.UUID,
|
||||
// defaultValue: UUIDV4,
|
||||
// primaryKey: true,
|
||||
// unique: true,
|
||||
// },
|
||||
// path: {
|
||||
// type: DataTypes.STRING,
|
||||
// },
|
||||
// user_id: {
|
||||
// type: DataTypes.INTEGER,
|
||||
// key: "User"
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// UserModel.hasMany(MResource);
|
||||
// ResourceModel.belongsTo(UserModel);
|
||||
@@ -1,60 +0,0 @@
|
||||
// import { Sequelize, DataTypes, Optional, Model } from 'sequelize';
|
||||
import {
|
||||
Association, DataTypes, HasManyAddAssociationMixin, HasManyCountAssociationsMixin,
|
||||
HasManyCreateAssociationMixin, HasManyGetAssociationsMixin, HasManyHasAssociationMixin,
|
||||
HasManySetAssociationsMixin, HasManyAddAssociationsMixin, HasManyHasAssociationsMixin,
|
||||
HasManyRemoveAssociationMixin, HasManyRemoveAssociationsMixin, Model, ModelDefined, Optional,
|
||||
Sequelize, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ForeignKey, BelongsTo, BelongsToGetAssociationMixin, UUIDV4, UUID
|
||||
} from 'sequelize';
|
||||
|
||||
import { AuthModel } from '@/model/sequelize/Auth';
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
// interface UserAttributes{
|
||||
// id: number;
|
||||
// username: string;
|
||||
// password: string;
|
||||
// };
|
||||
// interface UserCreationAttributes extends Optional<UserAttributes, 'id'>{};
|
||||
// export class UserModel extends Model<UserAttributes, UserCreationAttributes>{
|
||||
// createdAt?: Date;
|
||||
// updatedAt?: Date;
|
||||
// username: string = "";
|
||||
// password: string = "";
|
||||
// id?:number;
|
||||
// // declare title
|
||||
// }
|
||||
export class UserModel extends Model<InferAttributes<UserModel>, InferCreationAttributes<UserModel>>{
|
||||
declare id: number|null;
|
||||
declare username: string;
|
||||
declare password: string;
|
||||
declare getAuths:HasManyGetAssociationsMixin<AuthModel>;
|
||||
}
|
||||
|
||||
export const MUser = UserModel.init(
|
||||
{
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
username: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
password: {
|
||||
allowNull: false,
|
||||
type: DataTypes.STRING,
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'Users',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
}
|
||||
);
|
||||
MUser.sync();
|
||||
Reference in New Issue
Block a user