Many Changes
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { Association, CreationOptional, DataTypes, HasManyGetAssociationsMixin, HasOneCreateAssociationMixin, HasOneGetAssociationMixin, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
|
||||
import {
|
||||
PrimaryKey,
|
||||
Attribute,
|
||||
AutoIncrement,
|
||||
NotNull,
|
||||
BelongsTo,
|
||||
Unique,
|
||||
HasMany,
|
||||
HasOne,
|
||||
UpdatedAt,
|
||||
CreatedAt,
|
||||
} from '@sequelize/core/decorators-legacy';
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
|
||||
|
||||
export class APIKey extends Model<InferAttributes<APIKey>, InferCreationAttributes<APIKey>>{
|
||||
// Attributes
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Unique
|
||||
declare id: number;
|
||||
@Attribute(DataTypes.UUID)
|
||||
declare key: string;
|
||||
@Attribute(DataTypes.BOOLEAN)
|
||||
declare isAdminKey: boolean
|
||||
|
||||
// Date thingies
|
||||
@CreatedAt
|
||||
declare createdAt: CreationOptional<Date>;
|
||||
@UpdatedAt
|
||||
declare updatedAt: CreationOptional<Date>;
|
||||
|
||||
}
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite',
|
||||
models: [APIKey]
|
||||
});
|
||||
+41
-24
@@ -1,37 +1,54 @@
|
||||
import { Association, BelongsToGetAssociationMixin, CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, Sequelize, UUIDV4 } from "sequelize";
|
||||
import {
|
||||
Sequelize,
|
||||
DataTypes,
|
||||
Model,
|
||||
InferAttributes,
|
||||
InferCreationAttributes,
|
||||
CreationOptional,
|
||||
sql,
|
||||
BelongsToGetAssociationMixin,
|
||||
Association,
|
||||
NonAttribute,
|
||||
} from '@sequelize/core';
|
||||
|
||||
import { User } from "./User";
|
||||
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, BelongsTo, Default, NotNull, PrimaryKey, Table, Unique } from "@sequelize/core/decorators-legacy";
|
||||
|
||||
@Table({
|
||||
tableName: 'Auths'
|
||||
})
|
||||
export class Auth extends Model<InferAttributes<Auth>, InferCreationAttributes<Auth>> {
|
||||
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Unique
|
||||
declare id: CreationOptional<number>;
|
||||
|
||||
@Attribute(DataTypes.UUIDV4)
|
||||
@Default(sql.uuidV4)
|
||||
declare token: CreationOptional<string>;
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@NotNull
|
||||
declare user_id:number;
|
||||
|
||||
@BelongsTo( ()=>User, { foreignKey: 'user_id', inverse: { type: 'hasMany', as: 'authtokens' } } )
|
||||
declare user?: NonAttribute<User>
|
||||
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite',
|
||||
models: [Auth]
|
||||
});
|
||||
|
||||
+12
-17
@@ -1,20 +1,15 @@
|
||||
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,
|
||||
HasOneGetAssociationMixin,
|
||||
HasOneCreateAssociationMixin
|
||||
} from 'sequelize';
|
||||
|
||||
import { UserPerms } from './UserPerms';
|
||||
import { Auth } from './Auth';
|
||||
import { Post } from './Post';
|
||||
import { User } from './User';
|
||||
import { Auth } from './Auth';
|
||||
import { UserPerms } from './UserPerms';
|
||||
import { Post } from './Post';
|
||||
import { Tag } from './Tag';
|
||||
import { PostTag } from './PostTag';
|
||||
|
||||
User.sync();
|
||||
Auth.sync();
|
||||
UserPerms.sync();
|
||||
PostTag.sync();
|
||||
Tag.sync();
|
||||
Post.sync();
|
||||
|
||||
|
||||
|
||||
export { User, Auth, Post, UserPerms }
|
||||
export { User, Auth, UserPerms, Post, Tag, PostTag }
|
||||
+44
-47
@@ -1,56 +1,53 @@
|
||||
import { Association, BelongsToGetAssociationMixin, DataTypes, ForeignKey, Model, NonAttribute, Sequelize } from "sequelize";
|
||||
import { User } from "./User";
|
||||
import { Association, BelongsToGetAssociationMixin, CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";import { User } from "./User";
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, BelongsTo, BelongsToMany, CreatedAt, HasMany, NotNull, PrimaryKey, Unique, UpdatedAt } from "@sequelize/core/decorators-legacy";
|
||||
import { Tag } from "./Tag";
|
||||
import { PostTag } from "./PostTag";
|
||||
|
||||
export type PostAttributes = {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
date: number;
|
||||
user_id:ForeignKey<User['id']>;
|
||||
}
|
||||
export type PostCreationAttributes = {
|
||||
title: string;
|
||||
content: string;
|
||||
date: number;
|
||||
user_id:number;
|
||||
}
|
||||
export class Post extends Model<PostAttributes, PostCreationAttributes> {
|
||||
declare id: number;
|
||||
declare user:NonAttribute<User>;
|
||||
export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<Post>> {
|
||||
|
||||
|
||||
// Attributes
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Unique
|
||||
declare id: CreationOptional<number>;
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@NotNull
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
@Attribute(DataTypes.STRING)
|
||||
declare title:string
|
||||
@Attribute(DataTypes.STRING)
|
||||
declare content:string
|
||||
|
||||
// Date thingies
|
||||
@CreatedAt
|
||||
declare createdAt: CreationOptional<Date>;
|
||||
@UpdatedAt
|
||||
declare updatedAt: CreationOptional<Date>;
|
||||
|
||||
|
||||
|
||||
// Associatoins
|
||||
|
||||
@BelongsTo(()=>User, { foreignKey: 'user_id', inverse: { type: 'hasMany', as: 'posts' } })
|
||||
declare user:NonAttribute<User>;
|
||||
|
||||
@BelongsToMany(()=>Tag, { through: { model: ()=>PostTag, unique: false}, inverse: {as: 'taggedPosts'} })
|
||||
declare postTags?:NonAttribute<Tag[]>;
|
||||
|
||||
declare getUser: BelongsToGetAssociationMixin<User>;
|
||||
|
||||
declare static associations: {
|
||||
user: Association<User, Post>;
|
||||
postTags: Association<Tag, 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
|
||||
}
|
||||
);
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite',
|
||||
models: [Post]
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
import Sequelize, { Association, DataTypes, InferAttributes, InferCreationAttributes, Model, NonAttribute } from "@sequelize/core";
|
||||
import { Attribute, AutoIncrement, NotNull, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
|
||||
import { Post } from "./Post";
|
||||
import { Tag } from "./Tag";
|
||||
import { SqliteDialect } from "@sequelize/sqlite3";
|
||||
|
||||
|
||||
class PostTag extends Model<InferAttributes<PostTag>,InferCreationAttributes<PostTag>>
|
||||
{
|
||||
declare postId:number;
|
||||
declare tagId:number;
|
||||
}
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite',
|
||||
models: [PostTag]
|
||||
})
|
||||
|
||||
export { PostTag }
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Association, BelongsToGetAssociationMixin, CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";import { User } from "./User";
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
export type ProjectAttributes = {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string;
|
||||
date: number;
|
||||
user_id:ForeignKey<User['id']>;
|
||||
}
|
||||
export type ProjectCreationAttributes = {
|
||||
title: string;
|
||||
description: string;
|
||||
date: number;
|
||||
user_id:number;
|
||||
}
|
||||
export class Project extends Model<ProjectAttributes, ProjectCreationAttributes> {
|
||||
declare id: number;
|
||||
declare user:NonAttribute<User>;
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
declare getUser: BelongsToGetAssociationMixin<User>;
|
||||
declare static associations: {
|
||||
user: Association<User, 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
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Association, BelongsToGetAssociationMixin, BelongsToManyGetAssociationsMixin, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
|
||||
import { Post } from "./Post";
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, BelongsToMany, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
|
||||
|
||||
export class Tag extends Model<InferAttributes<Tag>, InferCreationAttributes<Tag>> {
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@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 static associations: {
|
||||
posts: Association<Post, Tag>;
|
||||
};
|
||||
}
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite',
|
||||
models: [Tag]
|
||||
})
|
||||
+64
-70
@@ -1,91 +1,85 @@
|
||||
import { Association, DataTypes, HasManyGetAssociationsMixin, HasOneCreateAssociationMixin, HasOneGetAssociationMixin, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "sequelize";
|
||||
import { Association, Attributes, CreationAttributes, CreationOptional, DataTypes, HasManyGetAssociationsMixin, HasOneCreateAssociationMixin, HasOneGetAssociationMixin, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
|
||||
import { Post } from "./Post";
|
||||
import { UserPerms } from "./UserPerms";
|
||||
import { Auth } from "./Auth";
|
||||
import {
|
||||
PrimaryKey,
|
||||
Attribute,
|
||||
AutoIncrement,
|
||||
NotNull,
|
||||
BelongsTo,
|
||||
Unique,
|
||||
HasMany,
|
||||
HasOne,
|
||||
UpdatedAt,
|
||||
CreatedAt,
|
||||
} from '@sequelize/core/decorators-legacy';
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
});
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
|
||||
type UserCreationAttributes = {
|
||||
username:string;
|
||||
password:string;
|
||||
perms?:Partial<InferAttributes<UserPerms>>
|
||||
}
|
||||
|
||||
export class User extends Model<InferAttributes<User>, InferCreationAttributes<User>>{
|
||||
declare id: number|null;
|
||||
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Unique
|
||||
declare id: CreationOptional<number>;
|
||||
@Attribute(DataTypes.STRING)
|
||||
declare username: string;
|
||||
@Attribute(DataTypes.STRING)
|
||||
declare password: string;
|
||||
|
||||
// Date thingies
|
||||
|
||||
@CreatedAt
|
||||
declare createdAt: CreationOptional<Date>;
|
||||
@UpdatedAt
|
||||
declare updatedAt: CreationOptional<Date>;
|
||||
|
||||
// Associations
|
||||
declare getAuthTokens:HasManyGetAssociationsMixin<Auth>;
|
||||
declare getPosts:HasManyGetAssociationsMixin<Post>;
|
||||
declare getPerms:HasOneGetAssociationMixin<UserPerms>;
|
||||
declare createPerms:HasOneCreateAssociationMixin<UserPerms>;
|
||||
declare perms?:NonAttribute<UserPerms>
|
||||
|
||||
/** Defined by {@link Auth.user} */
|
||||
declare authtokens?:NonAttribute<Auth[]>
|
||||
/** Defined by {@link UserPerms.user} */
|
||||
declare perms?:CreationOptional<Partial<CreationAttributes<UserPerms>>>
|
||||
/** Defined by {@link Post.user} */
|
||||
declare posts?:CreationOptional<Post[]>
|
||||
|
||||
declare static associations: {
|
||||
perms: Association<UserPerms,User>;
|
||||
posts: Association<Post,User>
|
||||
authtokens: Association<Auth,User>;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
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'],
|
||||
},
|
||||
include: [{ association: 'perms' }],
|
||||
},
|
||||
tableName: 'Users',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
const sequelize = new Sequelize({
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite',
|
||||
models: [User]
|
||||
});
|
||||
|
||||
|
||||
User.addScope('defaultScope',{
|
||||
attributes: {
|
||||
exclude: ['password', 'createdAt', 'updatedAt'],
|
||||
}
|
||||
);
|
||||
|
||||
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`!
|
||||
});
|
||||
UserPerms.belongsTo(User, {
|
||||
foreignKey:'user_id',
|
||||
targetKey:'id',
|
||||
as: 'user'
|
||||
})
|
||||
User.hasOne(UserPerms, {
|
||||
sourceKey: 'id',
|
||||
foreignKey: 'user_id',
|
||||
as: 'perms'
|
||||
|
||||
User.addScope('withPerms',{
|
||||
include: [{association: 'perms' }]
|
||||
})
|
||||
|
||||
|
||||
User.sync();
|
||||
Auth.sync();
|
||||
Post.sync();
|
||||
UserPerms.sync();
|
||||
User.addScope('withAuthtokens',{
|
||||
include: [{association: 'authtokens'}]
|
||||
})
|
||||
+39
-25
@@ -1,32 +1,46 @@
|
||||
import { CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "sequelize";
|
||||
import { CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
|
||||
import { User } from "./User";
|
||||
|
||||
import { SqliteDialect } from '@sequelize/sqlite3';
|
||||
import { Attribute, AutoIncrement, BelongsTo, CreatedAt, PrimaryKey, Table, Unique, UpdatedAt } from "@sequelize/core/decorators-legacy";
|
||||
|
||||
@Table({
|
||||
tableName: "Perms"
|
||||
})
|
||||
export class UserPerms extends Model<InferAttributes<UserPerms>, InferCreationAttributes<UserPerms>> {
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
@PrimaryKey
|
||||
@AutoIncrement
|
||||
@Unique
|
||||
declare id: CreationOptional<number>;
|
||||
@BelongsTo(()=>User, { foreignKey: 'user_id', inverse: { as: 'perms', type: 'hasOne' } })
|
||||
declare user:NonAttribute<User>;
|
||||
@Attribute(DataTypes.INTEGER)
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
@Attribute(DataTypes.BOOLEAN)
|
||||
declare isAdmin:CreationOptional<boolean>;
|
||||
@CreatedAt
|
||||
declare createdAt: CreationOptional<Date>;
|
||||
@UpdatedAt
|
||||
declare updatedAt: CreationOptional<Date>;
|
||||
|
||||
}
|
||||
|
||||
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'db.sqlite'
|
||||
dialect: SqliteDialect,
|
||||
storage: 'db.sqlite',
|
||||
models: [UserPerms],
|
||||
});
|
||||
|
||||
export class UserPerms extends Model<InferAttributes<UserPerms>, InferCreationAttributes<UserPerms>> {
|
||||
declare id: CreationOptional<number>;
|
||||
declare user:NonAttribute<User>;
|
||||
declare user_id:ForeignKey<User['id']>;
|
||||
declare isAdmin:CreationOptional<boolean>;
|
||||
}
|
||||
UserPerms.init({
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
},
|
||||
isAdmin: {
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
type: DataTypes.BOOLEAN
|
||||
|
||||
UserPerms.addScope('defaultScope',{
|
||||
attributes: {
|
||||
exclude: ['createdAt', 'updatedAt'],
|
||||
}
|
||||
});
|
||||
UserPerms.addScope('withTimestamps',{
|
||||
attributes: {
|
||||
include: ['createdAt', 'updatedAt'],
|
||||
}
|
||||
},
|
||||
{
|
||||
tableName: 'Perms',
|
||||
sequelize // passing the `sequelize` instance is required
|
||||
});
|
||||
Reference in New Issue
Block a user