【问题标题】:sails-mysql schema datatypesSails-mysql 模式数据类型
【发布时间】:2013-07-08 00:56:30
【问题描述】:

有人使用过node的sails框架,使用mysql作为数据库(https://github.com/balderdashy/sails-mysql)?

我卡在模型中,无法创建数据库结构。我需要用于创建架构的数据类型不起作用。我到处搜索了一些文档,但找不到任何可以帮助我的东西。

我猜,Sail 的文档还没有完成。 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'
    }
};

【问题讨论】:

    标签: mysql node.js sails.js


    【解决方案1】:

    我是 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'
      }
    };
    

    【讨论】:

    • 我发现如果你更改sails中的架构,数据库架构会改变,这是真的吗?在连接现有数据库之前备份您的数据库。
    • 这个答案有更新,还是没有db native ENUM?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 2010-11-12
    • 2013-05-20
    相关资源
    最近更新 更多