-
Notifications
You must be signed in to change notification settings - Fork 211
Associate Table Prefixes with DBs #991
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
Comments
Did you find a way to do this ? |
@ipolevoy I managed to use reflection to make it work and loaded it all into memory once (using reflection to change the @ Table annotation for load_prefix) and then changed the model's DB to the save DB also using reflection to change the @ Table (save_prefix) Annotation. Pretty much
|
@Articdive would something like this work for you: https://javalite.io/database_connection_management#multiple-database-example ? |
@ipolevoy unfortuantely that wouldn't work, I really need 1 Model (not 2 different ones) to be saved/loaded in 2 different DBs, I realized however that this does kind off defeat the purpose of ActiveJDBC. |
@Articdive actually, you can do this like this: public class Person extends Model{}
Base.open(driver, url1, user1, password1);
List<Person> people = Person..where(...);
Base.close();
Base.open(driver, url2, user2, password2);
for(Person p: people){
p.set("first_name", "John").saveIt();
}
Base.close(); so, what happens here, you read data from one database then modify it and write to another. The model only cares that there is an available default connection. Will this help? |
This is pretty much what I do, this simplifies the process I use by using the Base db (instead of reinit and stuffs) and stuff so that already helps a ton. Now it would be amazing if we could have a setTablePrefix("") or something so that we can set the table prefix, at the moment I use reflection to change the @ Table annotation and change the referenced table. So this ticket could be reopened for this exact case (a table prefix for a db)! |
@Articdive there is a way to fake it by using a sharding method, please see https://javalite.io/sharding. |
okay this seems to have worked thank you @ipolevoy! |
Awesome! |
Would be an amazing feature if we could give DBs custom Table prefixes (so 1 model has a different table prefix in different DBs e.g. in DB 1: HELLO_USERS and in DB 2: BYE_USERS), I'm currently working on a project and need to convert data from 1 DB to the other, but they have different table prefixes, I currently use a little reflection to make it somewhat possible but I could see this as a useful feature. Let me know if you would like some help with Impl..
The text was updated successfully, but these errors were encountered: