-
Notifications
You must be signed in to change notification settings - Fork 354
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
Database Synchronization only Reading #635
Comments
Did you run into problems with the copy-and-sync files approach? You could open two databases at once using |
Thank you for the discussion, I think I need to give you more information:
So, I can encrypt and upload the file every time, it shouldn't even be so heavy, but I would run it only once a day or so. What I thought to do was to create an empty copy of the DB, catch every event of the main DB, and insert into it the copy of the updated row after every change. If this is the best way, there is a method to catch every change, after executing it, so I can get the table_name and id and create the entry in the second DB? |
Your approach sounds like it could work. Moor doesn't have a builtin hook to get notified about statements before they are sent. // Inside your database or dao
Future<int> insertForBackup<T extends Table, D extends DataClass>(
TableInfo<T, D> table, Insertable<D> row) async {
await super.into(table).insert(row);
// Add to backup
} And then use |
How can I open a second database, with the same tables, but empty? |
Do you write data in your |
It is not clear to me how to create multiple instances of the database. I am using the same class, but passing now the name of the file in the constructor: But when I call it with the second fileName I get:
There is not much information on the link and I don't know what I am doing if I set
Not knowing better, I did: Future insertAllForBackup<T extends Table, D extends DataClass>(TableInfo<T, D> table, List<Insertable<D>> rows) async {
for (final row in rows) {
super.into(table).insert(row);
}
// Add to backup
}
Future deleteForBackup<T extends Table, D extends DataClass>(TableInfo<T, D> table, Insertable<D> row) {
super.delete(table).delete(row);
// Add to backup
} But I am not sure how to do a generic |
In earlier moor versions, I got many reports from users seeing that their tables didn't get created. It turned out that this problem happens when creating multiple database classes (on the same file), as that can break the migration. I added that warning to inform users that they probably want to only have one database class. Having two database classes that point to different files is perfectly safe, so you can disable ignore that warning.
You can use
You can use Future<void> deleteById<T extends Table, D extends DataClass>(
TableInfo<T, D> table, int id) async {
final idColumn = table.columnsByName['id'] as GeneratedIntColumn;
await (delete(table)..where((tbl) => idColumn.equals(id))).go();
// Add to backup
} |
Hello @simolus3, Our database size is getting huge. like after a year database size is arround 10MB Now. We need an approach to upload a new database file with
So we can send couples of KB of the new database file to the server and marge it with the new database can you please tell us how we can achieve this and which approach we can use? |
There are a number of possible solutions that come to mind. For new and updated rows, you could have a column to describe their state (e.g. whether the row was created or modified since the last synchronization). For a synchronization, you could go through all tables and check those flags to see whether the row needs to be uploaded. Alternatively, you could have a single "backlog" table storing all pending writes (so each row would be a tuple of the table, the primary key and a flag of what needs to be uploaded). Then you could define triggers to automatically insert into that table for each other write to the database perhaps. |
I would like to be able to synchronize 2 databases. The second database is read-only, so there is no problem with conflicts.
What I want to achieve can be seen as a differential backup.
Right now the easier method I have is to copy and sync the entire database.
Implement a database's recorder that stores the changes and updates only those seem pretty time-consuming.
Any suggestion is appreciated! : )
Useful discussion: #136
The text was updated successfully, but these errors were encountered: