當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。