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