当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Sequelize.define方法代码示例

本文整理汇总了TypeScript中Sequelize.Sequelize.define方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Sequelize.define方法的具体用法?TypeScript Sequelize.define怎么用?TypeScript Sequelize.define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sequelize.Sequelize的用法示例。


在下文中一共展示了Sequelize.define方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

export default function (sequelize: Sequelize, DataTypes: DataTypes) {
  let Map = sequelize.define('Map', {
    uid: {
      type: DataTypes.STRING,
      allowNull: false
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    author: {
      type: DataTypes.STRING,
      allowNull: false
    },
    environment: {
      type: DataTypes.STRING,
      allowNull: false
    }
  }, {
    tableName: 'core__map',
    charset: 'utf8'
  });

  return Map;
}
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:25,代码来源:Map.ts

示例2: function

export default function (sequelize: Sequelize, DataTypes: DataTypes) {
  let Setting = sequelize.define('Setting', {
    context: {
      type: DataTypes.STRING,
      allowNull: false
    },
    key: {
      type: DataTypes.STRING,
      allowNull: false
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    type: {
      type: DataTypes.STRING,
      allowNull: false
    },
    enumeration: {
      type: DataTypes.TEXT,
      allowNull: true
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true
    },
    value: {
      type: DataTypes.TEXT,
      allowNull: true
    },
    category: {
      type: DataTypes.STRING,
      allowNull: true
    },
    visible: {
      type: DataTypes.BOOLEAN,
      defaultValue: true
    }
  }, {
    tableName: 'core__setting',
    charset: 'utf8',
    indexes: [
      {
        unique: true,
        fields: ['context', 'key']
      }
    ],
    hooks: {
      beforeValidate (setting: any, options) {
        if (setting.value && typeof setting.value !== 'string')
          setting.value = JSON.stringify({value: setting.value});
        if (setting.enumeration && Array.isArray(setting.enumeration))
          setting.enumeration = JSON.stringify(setting.enumeration);
      }
    }
  });

  return Setting;
}
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:59,代码来源:Setting.ts

示例3: lockModel

 private lockModel() {
     return this.sequelize.define<LockInstance, LockAttribute>('Lock', {
         workerName: {
             type: this.sequelize.Sequelize.STRING,
             allowNull: false,
             validate: {
                 notEmpty: true,
             },
         },
     }, {timestamps: true});
 }
开发者ID:CodeZavod,项目名称:scheduler,代码行数:11,代码来源:Models.ts

示例4: initCourseModel

export function initCourseModel(sequelize: Sequelize) {
    return sequelize.define("Course", {
        description: ORM.STRING,
        url: ORM.STRING,
        longDescription: ORM.TEXT,
        iconUrl: ORM.STRING,
        courseListIcon: ORM.STRING,
        seqNo: ORM.STRING,
        comingSoon: ORM.BOOLEAN,
        isNew: ORM.BOOLEAN,
        isOngoing: ORM.BOOLEAN,
    });
}
开发者ID:vvscode,项目名称:code-notes,代码行数:13,代码来源:initCourseModel.ts

示例5: function

export default function(sequelize: Sequelize, dataTypes: DataTypes):
  SequelizeStatic.Model<ProductInstance, ProductAttributes> {
  let Product = sequelize.define<ProductInstance, ProductAttributes>("Product", {
    name: {type: dataTypes.STRING, allowNull: false, primaryKey: true},
    description: {type: dataTypes.TEXT, allowNull: true}
  }, {
    indexes: [],
    classMethods: {},
    timestamps: false
  });

  return Product;
}
开发者ID:natarajanmca11,项目名称:sequelize-typescript-examples,代码行数:13,代码来源:product-model.ts

示例6: schema

  static schema(sequelize: Sequelize, dataTypes: DataTypes): any {
    let schemaUser: DefineAttributes = {
      username: { 
        type: dataTypes.STRING,
        unique: true
      },
      password: { 
        type: dataTypes.STRING 
      },
      displayName: { 
        type: dataTypes.STRING 
      }
    };

    return sequelize.define("Users", schemaUser);
  }
开发者ID:pmatam,项目名称:nodejs,代码行数:16,代码来源:user_schema.ts

示例7: initLessonModel

export function initLessonModel(sequelize: Sequelize) {
    return sequelize.define("Lesson", {
        id: {
            type: ORM.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },

        url: ORM.STRING,
        description: ORM.STRING,
        duration: ORM.STRING,
        seqNo: ORM.INTEGER,
        courseId: ORM.INTEGER,
        pro: ORM.BOOLEAN,
        tags: ORM.STRING,
        gitHubUrl: ORM.STRING,
    });
}
开发者ID:vvscode,项目名称:code-notes,代码行数:18,代码来源:initLessonModel.ts

示例8: function

export default function (sequelize: Sequelize, DataTypes: DataTypes) {
  let Player = sequelize.define('Player', {
    login: {
      type: DataTypes.STRING,
      allowNull: false
    },
    nickname: {
      type: DataTypes.STRING,
      allowNull: false
    },
    level: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    }
  }, {
    tableName: 'core__player',
    charset: 'utf8'
  });

  return Player;
}
开发者ID:tomvlk,项目名称:ManiaJS,代码行数:22,代码来源:Player.ts

示例9: taskModel

    private taskModel() {
        const Task = this.sequelize.define<TaskInstance, TaskAttribute>('Task', {
            name: {
                type: this.sequelize.Sequelize.STRING,
                allowNull: false,
                validate: {
                    notEmpty: true,
                },
            },
            data: {
                type: this.sequelize.Sequelize.JSONB,
                defaultValue: {},
            },
            interval: {
                type: this.sequelize.Sequelize.INTEGER,
            },
            nextRunAt: {
                type: this.sequelize.Sequelize.DATE,
            },
            startAt: {
                type: this.sequelize.Sequelize.DATE,
            },
            endAt: {
                type: this.sequelize.Sequelize.DATE,
            },
            concurrency: {
                type: this.sequelize.Sequelize.INTEGER,
                defaultValue: 1,
            },
            priority: {
                type: this.sequelize.Sequelize.INTEGER,
                defaultValue: 0,
            },
            timeout: {
                type: this.sequelize.Sequelize.INTEGER,
                defaultValue: (1000 * 60 * 10), // 10 minutes
            },
            failsCount: {
                type: this.sequelize.Sequelize.INTEGER,
                defaultValue: 0,
            },
            runAtTime: {
                type: this.sequelize.Sequelize.TIME,
            },
            repeatOnError: {
                type: this.sequelize.Sequelize.BOOLEAN,
                defaultValue: false,
            },
        }, {
            timestamps: true,
        });

        (Task as any).prototype.checkEmitter = function(this: TaskInstance) {
            if (!this.emitter) {
                this.emitter = new EventEmitter();
            }
        };

        (Task as any).prototype.on = function(this: TaskInstance, ...args: any[]) {
            this.checkEmitter();
            (this.emitter.on as any)(...args);
        };

        (Task as any).prototype.removeListener = function(this: TaskInstance, ...args: any[]) {
            this.checkEmitter();
            (this.emitter.removeListener as any)(...args);
        };

        (Task as any).prototype.emit = function(this: TaskInstance, ...args: any[]) {
            this.checkEmitter();
            (this.emitter.emit as any)(...args);
        };

        (Task as any).prototype.touch = async function(this: TaskInstance) {
            debug(`${process.pid} '.touch()' called for task ${this.name} (${this.id})`);
            this.emit('touch');

            await this.sequelize.query(`UPDATE "Locks" SET "updatedAt" = NOW() WHERE "TaskId" = :task_id`, {
                replacements: {
                    task_id: this.id,
                },
                type: QueryTypes.UPDATE,
            });
        };

        return Task;
    }
开发者ID:CodeZavod,项目名称:scheduler,代码行数:87,代码来源:Models.ts


注:本文中的Sequelize.Sequelize.define方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。