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


TypeScript Sequelize.define函数代码示例

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


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

示例1: createModels

function createModels(schemas) {
    const models: any = {};
    for (let key of Object.keys(schemas)) {
        schemas[key].id = UUID;
        const indexes = schemas[key].indexes;
        delete schemas[key].indexes;
        models[key] = DB.define(key.toLowerCase(), schemas[key], indexes);
    }
    return models
}
开发者ID:lanarts,项目名称:server,代码行数:10,代码来源:models-sql.ts

示例2: default

export default (sequelize: Sequelize, DataTypes: Sequelize.DataTypes) => {

    // Fields

    const Post = sequelize.define('post', {
        title: DataTypes.STRING,
        content: DataTypes.String,
    });



    // Associates
    Post.associate = (models) => {
        // 1 to many with comment
        Post.hasMany(models.Comment, {
            foreignKey: 'commentId',
        });
    };

    return Post;
};
开发者ID:baotaizhang,项目名称:fullstack-pro,代码行数:21,代码来源:post.model.ts

示例3: require

var password:string = require("../password");
var Sequelize = require("sequelize");

var sequelize:Sequelize = new Sequelize("sequelize-learning-01", "dev", password,
        {
            dialect: "mysql",
            port: 3306
        });

var User:UserStatic = sequelize.define("User",
    {
        userId: {
            type: Sequelize.INTEGER,
            primaryKey: true,
            autoIncrement: true
        },
        userName: Sequelize.STRING,
        email: Sequelize.STRING
    },
    {
        timestamps: false
    });

var users:Array<User> = [];
var tasks:Array<Task> = [];

var Task:TaskStatic = sequelize.define("Task",
    {
        taskId: {
            type: Sequelize.INTEGER,
            primaryKey: true,
开发者ID:samuelneff,项目名称:sequelize-learning,代码行数:31,代码来源:app.ts

示例4: default

export default (sequelize: Sequelize, DataTypes: Sequelize.DataTypes) => {
    const Count = sequelize.define('count', {
        name: DataTypes.STRING,
    });
};
开发者ID:baotaizhang,项目名称:fullstack-pro,代码行数:5,代码来源:counter.ts

示例5: zone_log

}

function zone_log(messages: string) {
    console.log(`[${Zone.current.name}]`, messages);
}

let db = new sequelize('sample', 'username', 'password', {
    dialect: 'sqlite',
    storage: 'database.sqlite',
    logging: function(message: string) {
        zone_log(message);
    }
});

let User = db.define('User', {
    name: sequelize.STRING
});

execute();
async function execute() {
    await Zone.current.fork({
        name: 'zone-init'
    }).run(async () => {
        zone_log('init');
        await db.transaction(async (t) => {
            zone_log('sync');
            await User.sync({ force: true });
        });
    });

    await Zone.current.fork({
开发者ID:takeshi,项目名称:sequelize-zone.js-sample,代码行数:31,代码来源:sample.ts

示例6:

        maxConnections: 5,
        minConnections: 0,
        maxIdleTime: 10000
    },
});

export var Operator = sequelize.define('operator', {
    id: {
        primaryKey: true,
        field: 'id_operator',
        type: Sequelize.NUMERIC
    },
    firstName: {
        type: Sequelize.STRING,
        field: 'first_name'
    },
    lastName: {
        type: Sequelize.STRING,
        field: 'last_name'

    }
}, {
    freezeTableName: true, // Model tableName will be the same as the model name
    timestamps: false
});

export var PasswordRule = sequelize.define('password_rule', {
    id: {
        primaryKey: true,
        field: 'id_password_rule',
        type: Sequelize.NUMERIC
开发者ID:MirekSz,项目名称:expressik,代码行数:31,代码来源:Models.ts

示例7: Sequelize

import Sequelize from 'sequelize';
import {IArticle, IArticleInstance} from './article';
import {dbPath} from '../config';

const sequelizeInstance =
    new Sequelize('articles', null, null, {
        dialect: 'sqlite',
        storage: process.env.DB_ENV !== 'test' ? dbPath : ':memory:',
        port: 3306,
        logging: false
    });

const article =
    sequelizeInstance.define<IArticleInstance, IArticle>('Article', {
        title: Sequelize.STRING,
        description: Sequelize.STRING,
        content: Sequelize.STRING,
        published: Sequelize.BOOLEAN,
        publishedAt: Sequelize.DATE
    });

/** ORM instance. */
export const sequelize = sequelizeInstance;

/** Article definition, used to query the database. */
export const Article = article;
开发者ID:get-focus,项目名称:focus-help-center,代码行数:26,代码来源:index.ts

示例8: Sequelize

const sequelize = new Sequelize('');

new Umzug({
    // The storage.
    // Possible values: 'json', 'sequelize', an object
    storage: 'sequelize',
    storageOptions: {
        // The configured instance of Sequelize.
        // Optional if `model` is passed.
        sequelize: sequelize,

        // The to be used Sequelize model.
        // Must have column name matching `columnName` option
        // Optional of `sequelize` is passed.
        model: sequelize.define<any, any>('model', {}),

        // The name of the to be used model.
        // Defaults to 'SequelizeMeta'
        modelName: 'Schema',

        // The name of table to create if `model` option is not supplied
        // Defaults to `modelName`
        tableName: 'Schema',

        // The name of table column holding migration name.
        // Defaults to 'name'.
        columnName: 'migration',

        // The type of the column holding migration name.
        // Defaults to `Sequelize.STRING`
开发者ID:Engineer2B,项目名称:DefinitelyTyped,代码行数:30,代码来源:umzug-tests.ts

示例9: Sequelize

import Sequelize from 'sequelize'
import * as path from 'path'

const sequelize = new Sequelize('leetcode', 'null', 'null', {
  dialect: 'sqlite',
  define: {
    timestamps: true,
    freezeTableName: true,
  },
  storage: path.normalize(`${__dirname}/leetcode.db`),
})

export const Problem = sequelize.define('leetcode', {
  id: { type: Sequelize.INTEGER, primaryKey: true },
  url: { type: Sequelize.STRING },
  urlContent: { type: Sequelize.STRING },
  title: { type: Sequelize.STRING },
  difficulty: { type: Sequelize.INTEGER },
  paidOnly: { type: Sequelize.BOOLEAN },
})

Problem.sync()

async function getQuestionDetail(title_slug: string) {
  const url = `https://leetcode.com/graphql`
  return await axios.post(
    url,
    {
      operationName: 'getQuestionDetail',
      variables: { titleSlug: title_slug },
      query: `
          query getQuestionDetail($titleSlug: String!) {
开发者ID:gengjiawen,项目名称:leetcode,代码行数:32,代码来源:crawl_leetcode.ts

示例10:

        },
        logging:false//关闭输出sql日志
    }
);

let ImgDb = sequelize.define('img', {
    'url': {
        'type': Sequelize.STRING(255),
        'allowNull': true,
        'unique': true // 字段是否UNIQUE
    },
    'time': {
        'type': Sequelize.DATE(10),
        'allowNull': true
    },
    'titleId': {
        'type': Sequelize.STRING(100),
        'allowNull': true
    }
}, {
    // 自定义表名
    'freezeTableName': true,
    'tableName': 'node_img',
    // 是否需要增加createdAt、updatedAt、deletedAt字段
    'timestamps': false,
});


let TitleDb = sequelize.define('title', {
    'title': {
        'type': Sequelize.STRING(255),
开发者ID:zcg331793187,项目名称:DownloadYouLike,代码行数:31,代码来源:SequelizeDb.ts


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