问题
I'm trying to use mysql as my database, but I can't figure out how to get my config/adapters.js to use mysql information in config/local.js to connect. What's the correct way to store the connection information so that sails-mysql can connect?
回答1:
config/local.js is merged on top of all other configuration. So you can just put your own adapters
key in there:
{
adapters: {
default: 'myLocalAdapter',
myLocalAdapter: {
module: 'sails-mysql',
host: 'localhost',
user: 'root',
password: 'password',
database: 'database'
}
}
}
and it'll be picked up and used by Sails.
EDIT In sails v0.10.x, use the key connections
instead of adapters
as the two are now differentiated and connections now hold authentication info. The original answer was for an earlier version of sails.
回答2:
As of latest version of sails (i.e 0.12), while writing this answer, there is no Adapters.js
. The list of connections are specified in the config/connections.js
and default connection to use for all models are specified under config/models.js
. So, going by this change the way to override the database configuration for local is specifying as below in config.local.js
.
module.exports = {
connections: {
localMongoServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: 'YOUR_DB_USER',
password: 'YOUR_DB_PASSWORD',
database: 'YOUR_DB_NAME'
}
},
models: {
connection: 'localMongoServer'
}
}
NOTE: As in accepted answer, just changing adapters
to connections
won't work, since there is no default
attribute under connections
.
来源:https://stackoverflow.com/questions/24460920/using-local-js-to-store-sails-mysql-password