Sailsjs - How to use mySQL

我的梦境 提交于 2020-01-01 07:04:42

问题


How to use mysql with Sails ? Also, if I change the database to a mySQL one, do I lose all my current model data ?

I spent some time looking for tutorials and demos but haven't found any.


回答1:


In order to use mySQL with sails, you will have to:

  • Define an adapter in config/adapters

Example adapters file:

    module.exports.adapters = {
            'default': 'disk', 
            disk: {
                    module: 'sails-disk'
            },
            'mysql-adapter': {
                    module: 'sails-mysql',
                    host: 'HOST',
                    user: 'USER',
                    password: 'PASSWORD',
                    database: 'DATABASE'
            }
    };
  • Make any model use the new mysql adapter (ex. api/models/Contact.js)

    module.exports = {
        tableName: 'contacts',
        adapter: 'mysql-adapter',
        migrate: 'safe',
        attributes: { ... }
    }
    

Then it should work.



来源:https://stackoverflow.com/questions/20521525/sailsjs-how-to-use-mysql

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