Wre*_*cks 7 mysql node.js sails.js
任何人使用mysql作为DB(https://github.com/balderdashy/sails-mysql)使用node的sails框架?
我被困在模型中,我无法创建数据库结构.我需要用来创建模式的数据类型不起作用.我到处寻找一些文档,但我找不到任何可以帮助我的东西.
我猜,赛尔的文档还没有完整. http://sailsjs.org/#documentation/models
任何人都可以帮我创建模型.如果你能帮助我使用sails-mysql创建下面的简单模式,我将不胜感激.提前致谢!
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'
}
};
Run Code Online (Sandbox Code Playgroud)
par*_*ana 27
我是Waterline的作者,抱歉,您无法在文档中找到所需内容,我们一直在努力添加它们并使它们保持最新状态.
您非常接近您的架构.Waterline目前不支持数据库级别ENUM类型,但我们有验证可以让您最终获得相同的最终结果.
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'
}
};
Run Code Online (Sandbox Code Playgroud)