sails-mysql schema datatypes

喜夏-厌秋 提交于 2019-11-30 19:40:59

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.

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'
  }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!