sequelize#Model TypeScript Examples
The following examples show how to use
sequelize#Model.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: nounindex.ts From sendight-backend with GNU General Public License v3.0 | 6 votes |
module.exports = (sequelize, DataTypes) => {
class NounIndex extends Model {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
static associate(_models: never) {}
}
NounIndex.init(
{
currentIndex: DataTypes.NUMBER,
},
{
sequelize,
modelName: 'NounIndex',
},
);
return NounIndex;
};
Example #2
Source File: base.ts From server with Apache License 2.0 | 6 votes |
export class Base extends Model {
public id!: number;
public tenantId!: string
public createdBy!: string;
public updatedBy!: string;
// timestamps!
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}
Example #3
Source File: user.ts From expresso with MIT License | 6 votes |
// class entity
class User
extends Model<UserAttributes, UserCreationAttributes>
implements UserAttributes
{
declare id: string
declare fullName: string
declare phone?: string | null | undefined
declare email: string
declare password?: string | null | undefined
declare isActive?: boolean | null | undefined
declare isBlocked?: boolean | null | undefined
declare tokenVerify?: string | null | undefined
declare picturePath?: string | null | undefined
declare RoleId: string
declare newPassword?: string | undefined
declare confirmNewPassword?: string | undefined
declare readonly createdAt: Date
declare readonly updatedAt: Date
declare readonly deletedAt: Date
comparePassword: (password: string) => Promise<boolean>
}
Example #4
Source File: sequelize.spec.ts From ucast with Apache License 2.0 | 6 votes |
function configureORM() {
const sequelize = new Sequelize('sqlite::memory:')
class User extends Model {}
class Project extends Model {}
User.init({
name: { type: DataTypes.STRING },
email: { type: DataTypes.STRING },
}, { sequelize, modelName: 'user' })
Project.init({
name: { type: DataTypes.STRING },
active: { type: DataTypes.BOOLEAN }
}, { sequelize, modelName: 'project' })
Project.belongsTo(User)
User.hasMany(Project)
return { User, Project }
}
Example #5
Source File: createModels.ts From sync-party with GNU General Public License v3.0 | 6 votes |
class User extends Model {
id!: string;
username!: string;
role!: string;
password!: string;
settings!: object;
readonly createdAt!: Date;
readonly updatedAt!: Date;
}
Example #6
Source File: upload.ts From expresso with MIT License | 6 votes |
// class entity
class Upload
extends Model<UploadAttributes, UploadCreationAttributes>
implements UploadAttributes
{
declare id: string
declare keyFile: string
declare filename: string
declare mimetype: string
declare size: number
declare signedUrl: string
declare expiryDateUrl: Date
declare readonly createdAt: Date
declare readonly updatedAt: Date
declare readonly deletedAt: Date
}
Example #7
Source File: schema.ts From akashlytics with GNU General Public License v3.0 | 6 votes |
export class Provider extends Model {
public owner: string;
public hostUri: string;
public createdHeight: number;
public email?: string;
public website?: string;
// Stats
public isOnline?: boolean;
public lastCheckDate?: Date;
public error?: string;
public deploymentCount?: number;
public leaseCount?: number;
public activeCPU?: number;
public activeMemory?: number;
public activeStorage?: number;
public pendingCPU?: number;
public pendingMemory?: number;
public pendingStorage?: number;
public availableCPU?: number;
public availableMemory?: number;
public availableStorage?: number;
public readonly providerAttributes?: ProviderAttribute[];
public readonly providerAttributeSignatures?: ProviderAttributeSignature[];
}
Example #8
Source File: adjectiveindex.ts From sendight-backend with GNU General Public License v3.0 | 6 votes |
module.exports = (sequelize, DataTypes) => {
class AdjectiveIndex extends Model {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
static associate(_models: never) {}
}
AdjectiveIndex.init(
{
currentIndex: DataTypes.NUMBER,
},
{
sequelize,
modelName: 'AdjectiveIndex',
},
);
return AdjectiveIndex;
};
Example #9
Source File: session.ts From expresso with MIT License | 6 votes |
// class entity
class Session
extends Model<SessionAttributes, SessionCreationAttributes>
implements SessionAttributes
{
declare id: string
declare UserId: string
declare token: string
declare ipAddress?: string | null | undefined
declare device?: string | null | undefined
declare platform?: string | null | undefined
declare latitude?: string | null | undefined
declare longitude?: string | null | undefined
declare readonly createdAt: Date
declare readonly updatedAt: Date
}
Example #10
Source File: adjectivelist.ts From sendight-backend with GNU General Public License v3.0 | 6 votes |
module.exports = (sequelize, DataTypes) => {
class AdjectiveList extends Model {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
static associate(_models: never) {}
}
AdjectiveList.init(
{
word: DataTypes.STRING,
},
{
sequelize,
modelName: 'AdjectiveList',
},
);
return AdjectiveList;
};
Example #11
Source File: ModelBuilder.ts From aloxide with Apache License 2.0 | 6 votes |
static mapField(
typeInterpreter: Interpreter<Field, DataType>,
fields: Field[],
key: string,
): ModelAttributes {
return fields.reduce((a, c) => {
const field: ModelAttributeColumnOptions<Model> = {
type: typeInterpreter.interpret(c),
};
if (c.name === key) {
field.primaryKey = true;
switch (field.type) {
case DataTypes.SMALLINT:
case DataTypes.INTEGER:
case DataTypes.BIGINT:
case DataTypes.NUMBER:
case DataTypes.DOUBLE:
field.autoIncrement = true;
break;
}
}
return Object.assign(a, {
[c.name]: field,
});
}, {});
}
Example #12
Source File: schema.ts From akashlytics with GNU General Public License v3.0 | 6 votes |
export class Message extends Model {
public id!: string;
public txId!: string;
public height!: number;
public type!: string;
public typeGroup!: string;
public index!: number;
public indexInBlock!: number;
public isInterestingType!: boolean;
public isProcessed!: boolean;
public shouldProcess!: boolean;
public relatedDeploymentId?: string;
public readonly transaction?: Transaction;
public static associations: {
transaction: Association<Message, Transaction>;
};
}
Example #13
Source File: role.ts From expresso with MIT License | 6 votes |
// class entity
class Role
extends Model<RoleAttributes, RoleCreationAttributes>
implements RoleAttributes
{
declare id: string
declare name: string
declare readonly createdAt: Date
declare readonly updatedAt: Date
declare readonly deletedAt: Date
}
Example #14
Source File: nounlist.ts From sendight-backend with GNU General Public License v3.0 | 6 votes |
module.exports = (sequelize, DataTypes) => {
class NounList extends Model {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
static associate(_models: never) {}
}
NounList.init(
{
word: DataTypes.STRING,
},
{
sequelize,
modelName: 'NounList',
},
);
return NounList;
};
Example #15
Source File: schema.ts From akashlytics with GNU General Public License v3.0 | 6 votes |
export class Deployment extends Model {
public id!: string;
public owner!: string;
public dseq!: number;
public state?: string;
public escrowAccountTransferredAmount?: number;
public createdHeight!: number;
public balance!: number;
public deposit!: number;
public readonly leases?: Lease[];
}
Example #16
Source File: fcmtoken.ts From expresso with MIT License | 6 votes |
// class entity
class FCMToken
extends Model<FCMTokenAttributes, FCMTokenCreationAttributes>
implements FCMTokenAttributes
{
declare id: string
declare UserId: string
declare token: string
declare readonly createdAt: Date
declare readonly updatedAt: Date
declare readonly deletedAt: Date
}
Example #17
Source File: adjectiveindex.ts From sendight-backend with GNU General Public License v3.0 | 5 votes |
class AdjectiveIndex extends Model {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
static associate(_models: never) {}
}
Example #18
Source File: attributes.ts From server with Apache License 2.0 | 5 votes |
export class GroupsAttributes extends Model {
// public createdBy!: string;
// public updatedBy!: string;
}
Example #19
Source File: getdb.ts From elec-sqlite-vue with GNU General Public License v3.0 | 5 votes |
// todo define models here, or use a separate file for defining models and import them here!!!
class User extends Model {
public firstName!: string | null;
public lastName!: string | null;
public id!: number | null
}
Example #20
Source File: sequelize.spec.ts From ucast with Apache License 2.0 | 5 votes |
class User extends Model {}
Example #21
Source File: createModels.ts From sync-party with GNU General Public License v3.0 | 5 votes |
class MediaItem extends Model {
id!: string;
owner!: string;
name!: string;
url!: string;
type!: 'web' | 'file';
settings!: object;
}
Example #22
Source File: ModelBuilder.ts From aloxide with Apache License 2.0 | 5 votes |
build(sequelize: Sequelize): ModelCtor<Model>[] {
return this.aloxideConfig.entities.map(entityConfig =>
ModelBuilder.makeModelFromEntityConfig(sequelize, this.typeInterpreter, entityConfig),
);
}
Example #23
Source File: adjectivelist.ts From sendight-backend with GNU General Public License v3.0 | 5 votes |
class AdjectiveList extends Model {
// eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
static associate(_models: never) {}
}
Example #24
Source File: MostVoted.ts From ZuraaaBot with GNU General Public License v3.0 | 5 votes |
class MostVoted extends Model {
id!: string
roleId!: string
}
Example #25
Source File: ModelBuilder.ts From aloxide with Apache License 2.0 | 5 votes |
static makeModelFromEntityConfig(
sequelize: Sequelize,
typeInterpreter: Interpreter<Field, DataType>,
entityConfig: EntityConfig,
): ModelCtor<Model> {
const { name, fields, key } = entityConfig;
return sequelize.define(name, ModelBuilder.mapField(typeInterpreter, fields, key));
}
Example #26
Source File: schema.ts From akashlytics with GNU General Public License v3.0 | 5 votes |
export class ProviderAttribute extends Model {
public provider: string;
public key: string;
public value: string;
}
Example #27
Source File: account.ts From community-repo with GNU General Public License v3.0 | 5 votes |
class Account extends Model {}
Example #28
Source File: Ban.ts From CSZ-Bot with MIT License | 5 votes |
export default class Ban extends Model<BanAttributes, BanCreationAttributes> implements BanAttributes {
declare id: string;
declare userId: string;
declare reason: string | null;
declare bannedUntil: Date | null;
declare isSelfBan: boolean;
declare readonly createdAt: Date;
declare readonly updatedAt: Date;
static persistOrUpdate = (user: GuildMember, until: Date | null, isSelfBan: boolean, reason: string | null = null): Promise<void> => {
log.debug(`Saving Ban for user ${user} until ${until} (Selfban: ${isSelfBan}, Reason: ${reason})`);
return Ban.upsert({
userId: user.id,
reason,
bannedUntil: until,
isSelfBan
}) as Promise<any>;
};
static remove = (user: User | GuildMember) => Ban.destroy({ where: { userId: user.id } });
static findExisting = (user: User | GuildMember) => Ban.findOne({ where: { userId: user.id } });
static findExpiredBans = (now: Date) => Ban.findAll({
where: {
bannedUntil: {
[Op.ne]: null,
[Op.lte]: now
}
}
});
static initialize(sequelize: Sequelize) {
this.init({
id: {
type: DataTypes.STRING(36),
defaultValue: () => uuidv4(),
primaryKey: true
},
userId: {
type: DataTypes.STRING(32),
allowNull: false
},
reason: {
type: DataTypes.STRING(255),
allowNull: true
},
bannedUntil: {
type: DataTypes.DATE,
allowNull: true
},
isSelfBan: {
type: DataTypes.BOOLEAN,
allowNull: false
}
}, {
sequelize,
indexes: [
{
unique: true,
fields: ["userId"]
},
{
using: "BTREE",
fields: [
{
name: "bannedUntil",
order: "ASC"
}
]
}
]
});
}
}
Example #29
Source File: SqlizeQuery.ts From expresso with MIT License | 5 votes |
/**
*
* @param includes
* @param onBuildInclude
* @returns
*/
export function transfromIncludeToQueryable(
includes: Includeable[],
onBuildInclude?: onBuildInclude
): CustomIncludeOptions[] {
const result = [] as CustomIncludeOptions[]
const _onBuildInclude =
onBuildInclude ??
function (value: CustomIncludeOptions) {
return value
}
/**
*
* @param includes
* @param parent
*/
function wrapFiltered(
includes: Includeable[],
parent?: IncludeOptions
): void {
for (let i = 0; i < includes.length; i += 1) {
const include = includes[i] as CustomIncludeOptions
const { model, key, include: oriInclude, ...restInclude } = include
// TODO: fix compare isTypeModel for better check typing
const isTypeModel = typeof Model === typeof include
const curModel = (isTypeModel ? include : model) as typeof Model
const defaultName = curModel.options.name?.singular
const data = _onBuildInclude({
...(isTypeModel ? {} : restInclude),
key: key ?? defaultName,
model: curModel,
} as unknown as IncludeOptions)
if (parent) {
// eslint-disable-next-line no-param-reassign
parent.include = parent.include ?? []
parent.include.push(data)
} else {
result.push(data)
}
if (include.include) {
wrapFiltered(include.include, data)
}
}
}
wrapFiltered(includes)
return result
}