sails-mysql模式数据类型 [英] sails-mysql schema datatypes
问题描述
任何人都使用以mysql为数据库的节点的Sails框架( https://github.com/balderdashy/sails- mysql )?
anyone used node's sails framework using mysql as DB (https://github.com/balderdashy/sails-mysql)?
我被模型困住了,无法创建数据库结构.创建架构所需的数据类型不起作用.我到处都在寻找一些文档,但是找不到任何可以帮助我的东西.
I am stuck in models, I can't create the database structure.The datatypes that I need to use to create the schema doesn't work. I've searched everywhere for some documentation, but i can't find anything that can help me.
我想,帆的文件还不完整. http://sailsjs.org/#documentation/models
Sail's documentation is not yet complete, i guess. http://sailsjs.org/#documentation/models
任何人都可以帮助我创建模型.如果您能帮助我使用sails-mysql创建以下简单架构,将不胜感激.预先感谢!
Can anyone please help me in creating models. I would highly appreciate if you can help me create the simple schema below using sails-mysql. Thanks in advance!
module.exports = {
attributes: {
id: 'FLOAT',
social_network: {
type: 'ENUM',
defaultsTo : {'Facebook', 'twitter', 'vk','weibo'}
},
country: 'STRING',
message: 'TEXT',
link: 'STRING',
comments: 'TEXT',
userid: 'INT',
username: 'STRING',
image_link: 'STRING',
longitude: 'FLOAT',
latitude: 'FLOAT',
location_name: 'STRING',
updated_at: 'TIMESTAMP',
created_at: 'TIMESTAMP'
}
};
推荐答案
我是Waterline的作者,对不起,您在文档中找不到所需的内容,我们一直在努力添加并保持最新日期.
I am the author of Waterline, sorry you couldn't find what you needed in the docs, we are constantly working on adding to them and keeping them up to date.
您在架构上非常接近. Waterline当前不支持数据库级别的ENUM
类型,但是我们进行的验证可以使您最终得到相同的最终结果.
You are very close on your schema. Waterline currently doesn't support a database level ENUM
type but we have validations that will allow you to end up with the same end result.
module.exports = {
// Disables Automatic ID generation
// (allows you to use a FLOAT type for your ID)
autoPK: false,
// Disables Automatic Timestamps
// You will need to manually update your timestamps, usually best to leave this
// on and remove the updated_at and created_at attributes below to let Waterline
// keep these up to date for you
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
id: {
type: 'FLOAT',
primaryKey: true
}
// Proper ENUM types at the Database level are not yet supported
// but you can use validations to achieve the same end result.
// You can also add a default social_network with defaultsTo
social_network: {
type: 'STRING',
in: ['facebook', 'twitter', 'vk', 'weibo']
},
country: 'STRING',
message: 'TEXT',
link: 'STRING',
comments: 'TEXT',
userid: 'INTEGER',
username: 'STRING',
image_link: 'STRING',
longitude: 'FLOAT',
latitude: 'FLOAT',
location_name: 'STRING',
// Timestamp is not supported but Time, Date, and DateTime are
updated_at: 'DATETIME',
created_at: 'DATETIME'
}
};
这篇关于sails-mysql模式数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!