|
- import {
- DataType,
- INTEGER,
- STRING,
- TEXT,
- DATE,
- DATEONLY,
- UUIDV4,
- } from 'sequelize'
-
- type ModelAttribute = {
- allowNull?: boolean,
- primaryKey?: boolean,
- type: DataType,
- }
-
- export type Model = {
- tableName?: string,
- modelName?: string,
- options?: {
- timestamps?: boolean,
- paranoid?: boolean,
- createdAt?: string | boolean,
- updatedAt?: string | boolean,
- deletedAt?: string | boolean,
- },
- attributes: Record<string, ModelAttribute>,
- }
-
- type IntegerType = typeof INTEGER | ReturnType<typeof INTEGER>
- type NumberType = IntegerType
-
- type VarcharType = typeof STRING
- type TextType = typeof TEXT | ReturnType<typeof TEXT>
- type StringType = VarcharType | TextType
-
- type DateTimeType = typeof DATE
- type DateOnlyType = typeof DATEONLY
- type DateType = DateTimeType | DateOnlyType
-
- type InferType<V extends DataType> = (
- V extends NumberType ? number :
- V extends StringType ? string :
- V extends DateType ? Date :
- V extends typeof UUIDV4 ? string :
- unknown
- )
-
- export type InferModel<M extends Model> = {
- [K in keyof M['attributes']]-?: InferType<M['attributes'][K]['type']>
- }
-
- export {
- INTEGER,
- STRING,
- TEXT,
- DATEONLY,
- DATE,
- UUIDV4,
- }
|