本文整理匯總了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
}
示例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;
};
示例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,
示例4: default
export default (sequelize: Sequelize, DataTypes: Sequelize.DataTypes) => {
const Count = sequelize.define('count', {
name: DataTypes.STRING,
});
};
示例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({
示例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
示例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;
示例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`
示例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!) {
示例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),