Skip to content

Instantly share code, notes, and snippets.

@cgmartin
Created January 10, 2014 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgmartin/8346950 to your computer and use it in GitHub Desktop.
Save cgmartin/8346950 to your computer and use it in GitHub Desktop.
Separate mysql db adapter test with Sails.js
module.exports = {
adapter: 'mysqlDb1',
attributes: {
name: 'string'
}
};
module.exports = {
adapter: 'mysqlDb2',
attributes: {
name: 'string'
}
};
module.exports.adapters = {
'default': 'disk',
disk: {
module: 'sails-disk'
},
mysqlDb1: {
module: 'sails-mysql',
host: 'localhost',
user: 'root',
password: '',
database: 'sailsDb1',
pool: false
},
mysqlDb2: {
module: 'sails-mysql',
host: 'localhost',
user: 'root',
password: '',
database: 'sailsDb2',
pool: false
}
};
module.exports.bootstrap = function (cb) {
function createMysqlTestData(done) {
async.parallel([
function(done) {
var modelA = [{ "name": "testA" }];
ModelA.count().exec(function(err, count) {
if (err) return done(err);
if (count > 0) return done();
ModelA.create(modelA).exec(done);
});
},
function(done) {
var modelB = [{ "name": "testB" }];
ModelB.count().exec(function(err, count) {
if (err) return done(err);
if (count > 0) return done();
ModelB.create(modelB).exec(done);
});
}
], done);
}
createMysqlTestData(cb);
};
@cgmartin
Copy link
Author

This worked for me.

I successfully saw a modela table created in sailsDb1 containing a row with the 'testA' name. Likewise with modelb in sailsDb2 with 'testB' name.

@sirinibin
Copy link

Is there is any particular way to switch amongs different Db's prgramatically?
Im planning to give Separate Db's for each of my Signed up users.

@sirinibin
Copy link

Is there is any particular way to switch amongs different Db's prgramatically?
Im planning to give Separate Db's for each of my Signed up users.

@vishnumishra
Copy link

vishnumishra commented Jun 13, 2016

Is there a way to create FK in the different DB using the mySql-adapter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment