Sailsjs-如何使用mySQL [英] Sailsjs - How to use mySQL
本文介绍了Sailsjs-如何使用mySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Sails中使用mysql?另外,如果将数据库更改为mySQL数据库,是否会丢失所有当前模型数据?
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.
推荐答案
为了在帆中使用mySQL,您将必须:
In order to use mySQL with sails, you will have to:
- 在 config/adapters 中定义适配器
- Define an adapter in config/adapters
示例适配器文件:
module.exports.adapters = {
'default': 'disk',
disk: {
module: 'sails-disk'
},
'mysql-adapter': {
module: 'sails-mysql',
host: 'HOST',
user: 'USER',
password: 'PASSWORD',
database: 'DATABASE'
}
};
-
使任何模型都使用新的mysql适配器(例如api/models/Contact.js)
module.exports = { tableName: 'contacts', adapter: 'mysql-adapter', migrate: 'safe', attributes: { ... } }
然后它应该可以工作.
这篇关于Sailsjs-如何使用mySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文