Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change db on the fly #83

Open
webfrank opened this issue Sep 19, 2014 · 3 comments
Open

Change db on the fly #83

webfrank opened this issue Sep 19, 2014 · 3 comments
Milestone

Comments

@webfrank
Copy link

How could be possible to switch db on the fly using Alloy Model?

@pegli
Copy link
Collaborator

pegli commented Sep 22, 2014

It sounds like you are asking for a method in the sync adapter to switch between two different databases after a model has been loaded. With the current Alloy sync adapter, this is not possible because the database is set the first time a model file is parsed.

Can you give me more details about the problem that you are trying to solve and perhaps put in some example code showing how you would like this feature to work?

@webfrank
Copy link
Author

Hi, I have multiple db replicated and I woul like to switch between them using Alloy models. Previously I recconnect to new db using API but with Alloy is different. In my model I required("alloy") to gain access to Alloy.CFG.dbname which is working correctly and I could configure db using config.json. If I could use Alloy.Globals I suppose I could change db on the fly but I think model is cached. On new sync adapter I found cache object and I disabled it but I cannot still gain access to new db after changing Alloy.Globals.dbname.

@webfrank
Copy link
Author

Hi, I managed to switch DB re-Init the adapter with this code:

function Sync(method, model, options) {
var opts = options || {};

if(model.config.adapter.dbname != Alloy.Globals.dbname) {
Ti.API.info('DB change detected: ' + model.config.adapter.dbname + ' -> ' + Alloy.Globals.dbname);
model.config.adapter.dbname = Alloy.Globals.dbname;
InitAdapter(model.config);
}
.......

But the the problem it relies on Alloy.Globals.dbname witch I set to change DB. Do you have any better idea to do it?

@pegli pegli added this to the 1.3 milestone Oct 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants