Made a sample app #810
Replies: 4 comments 3 replies
-
That is nice. Let me add some comments:
const V2::TodoItemRecord new_todo{
.id = old_todo.id,
.who_id = who_id,
.thing = old_todo.thing,
.status = status_v1_to_v2(old_todo.status)
};
db.replace(new_todo); or const V2::TodoItemRecord new_todo{
.id = old_todo.id,
.who_id = who_id,
.thing = old_todo.thing,
.status = status_v1_to_v2(old_todo.status)
};
db.insert(into<TodoItemRecord>(),
columns(&V2::TodoItemRecord::id, &V2::TodoItemRecord::who_id, &V2::TodoItemRecord::thing, &V2::TodoItemRecord::status),
values(new_todo.id, new_todo.who_id, new_todo.thing, new_todo.status)); |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I was thinking about more powerful migrations API. If you have ideas you are welcome. One of options is: // configure migrations
storage.register_migration(1, 2, [](auto oldConnection, auto &storage) {
struct OldType {
//..
};
auto oldStorage = make_storage(oldConnection, ...old schema with OldType(s)...;
// here select some important data from oldStorage and insert it into new storage (the second argument, the same as initial storage itself)
});
// call migration
storage.migrate(2); // this call gets current user_version pragma and runs callbacks provided for 1 to 2 migration, next it sets PRAGMA user_version to 2. If you want to migrate to 3, then you need to add migration callback for 1, 3 arguments or two migration callbacks for 1, 2 and for 2, 3 Of course this functionality will be better if storage |
Beta Was this translation helpful? Give feedback.
-
@define-private-public I'll convert this issue to discussion if you don't mind |
Beta Was this translation helpful? Give feedback.
-
https://gitlab.com/define-private-public/sqlite_orm_todo_sample
Right now I'm working on a much larger app, but I wanted to take some time to better learn how to use SQLite ORM (e.g. "how would I do a data migration?"). So I spent some time making a sample application. It's a very simple command line TODO list.
If you have any suggestions on how to make this a better sample for others, or design/architectural patterns that should be used instead I'm open to suggestions. If you think it might also be good for other users to look at, I would appreciate a link to it in the README. I'll be sure to keep this project up to date to match any changes in SQLite ORM.
Beta Was this translation helpful? Give feedback.
All reactions