问题
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