-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
Attach databases #578
Comments
Hi. |
This sounds great. Thanks for the quick reply. |
Is the function implemented now or in the near future? |
It is not implemented now. I will be implemented soon. Also if anyone can provide any test case or usage example how you want to use it it would be great. You can describe it in abstract with no code. |
Would something like that work with sqlite_orm?
|
I mean what do you need this feature for? I'd like to see raw queries. Also I see API like this: struct StorageAttachTag : alias_tag {
static const std::string &get() {
static const std::string res = "storage2";
return res;
}
};
auto storage1 = make_storage(...);
auto storage2 = make_storage(...);
storage1.attach<StorageAttachTag>(storage2); next |
I would like to invent a concept auto storage1 = make_storage(...);
auto storage2 = make_storage(...);
auto storage3 = attatch(storage1, storage2,...); // combine several databases into one
storage3.select(combine(storage1,&Employee::id),.. |
@xiamr it can be achieved easily with the way I proposed before. All you need is to create a third empty storage right in memory and attach two other storages to it. |
The key difficulty is how to distinguish when two databases have tables use same schema. For example:
It is important to keep API as same as possible for both single storage and virtual storage. |
there will be no virtual storage. The third storage is the same storage that others so they will have the same API always. |
It is nice to implement this feature through alias. |
One problem: is attach will be a separated command like I wrote then we will be unable to make static check that class is mapped. But if we specify attached storages in |
It is better to use compile time check, especially with C++20 concept. Therefore, I perfer to use ways with more static check, although it may complicate code in some cases. |
Another advantage of the make_storage variant would be that you open only one database connection. Isn't the usual use case for attaching databases writing sql statements that affects all attached databases simultaneously? Those databases would be similar to multiple tables in one database then. Sqlite_orm already requires unique types for each table in a database. It is probably probably more intuitive if the same rules apply to attached databases too. This way it should be possible to use most of the remaining sqlite_orm API just as if it was one database. One exception would be the pragma API. Can you still call make_storage if you need an unique connection to one of the attached databases? |
Yes |
I don't understand quite right what it means. Can you please provide some examples? |
Something like:
"another_db" is attached to connection of "db". And other connection is opened via another make_storage call for "another_db". |
oh you mean that |
They are not connected at all. Each make_storage call opens a connection, right? So for storage we have a connection to database "db". Database "another_db" would be attached to this connection via the attach sqlite statement. "another_storage" is an optional distinctive connection. |
Yes they are not connected at all. Every storage C++ instance has its own database connection. Also of you copy an instance of any storage copied instance will have its own connection. |
I finally got an idea how to implement this feature with all static checks. auto storage1 = make_storage(...);
auto attachedStorage = storage1.attach("path", make_storage(...));
|
Hello @fnc12 , does it work now ? |
@spiritEcosse not yet =( |
Hey,
thank you for your cool library @fnc12.
Does sqlite_orm support the attach database feature of sqlite3? It don't seem to find any reference regarding that one in the code. It is explained there:
https://www.sqlite.org/lang_attach.html
My use case is related data in non volatile and volatile memory, therefore I must use 2 sqlite3 dbs.
The text was updated successfully, but these errors were encountered: