From ctarsoaga at hotmail.com Sat Sep 8 09:57:44 2018 From: ctarsoaga at hotmail.com (Cristian Tarsoaga) Date: Sat Sep 8 11:53:09 2018 Subject: [odb-users] maintained? Message-ID: Hi, I just wonder: are odb and xsd still maintained? I see the latest releases are from 2015/2014. Thanks Chris From boris at codesynthesis.com Sat Sep 8 11:51:59 2018 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sat Sep 8 11:58:47 2018 Subject: [odb-users] maintained? In-Reply-To: References: Message-ID: Cristian Tarsoaga writes: > I just wonder: are odb and xsd still maintained? Yes, it is, though the release is long overdue (and is coming). You can monitor the progress in the git repository: https://git.codesynthesis.com/cgit/odb/ Also if you want to try the latest "continously delivered" pre- relase, see: https://codesynthesis.com/products/odb/doc/install-build2.xhtml From lists at tinloaf.de Wed Sep 26 05:07:29 2018 From: lists at tinloaf.de (Lukas Barth) Date: Wed Sep 26 05:15:24 2018 Subject: [odb-users] Use a view to query many-to-many relationship Message-ID: <40fba53a-e5fa-1c64-cc50-66d22a8bfa43@tinloaf.de> Hi, I have a class (call it "MyObject"), each object of which holds an integer value and is associated with a "Config" object (possibly many MyObjects to one Config). Each Config object is associated to multiple "ObjectKV" objects, each containing one key-value mapping. The complete code is below for clarification. I want to create (for example) a query that returns all "MyObjects" which: - have value 42 - the associated config of which has exactly two Key-Value pairs, namely: - "Foo"->"Bar" - "Fuz"->"Baz" Obviously, I don't want to hard-code this query, but the value, the number of key-value pairs and the keys and values are dynamic in my program. I know I can use Views to load a MyObject together with its Config by saying #pragma db view object(MyObject) object(Config) struct my_view { ? }; However, now there's a to-many relationship to the ConfigKVs. How do I formulate a view / a query on a view that only selects the entries that have exactly the right ConfigKVs associated? Basically, I'd need a magic "contains" and "size" predicates in the query language like this: db->query(query::value == 42 && query::cfg->kvs->contains( query::key == 'foo' && query::value == 'bar') && query::cfg->kvs->contains( query::key == 'fuz' && query::value == 'baz') && query::cfg->kvs->size() == 2) Note that I modeled the 'exactly the two required KV mappings' by asking for both to be contained and then querying for the size to be exactly two. Are there any such predicates in the query language? Or is there a different way of formulating this? Here follows the complete definition of the three classes: ======================================================================= #include #include #include #include // Forward class MyObject; class Config; class ConfigKV; /* * An object has a value and one associated Config */ #pragma db object class MyObject { int value; std::shared_ptr cfg; private: #pragma db id auto unsigned long id_; friend class odb::access; }; /* * A Config object has multiple ConfigKV objects associated, each * of which contains one Key-Value mapping. */ #pragma db object class Config { public: std::string name; #pragma db inverse(cfg) std::vector> kvs; private: #pragma db id auto unsigned long id_; friend class odb::access; }; /* * One Key-Value mapping */ #pragma db object class ConfigKV { public: std::string key; std::string value; std::shared_ptr cfg; private: #pragma db id auto unsigned long id_; friend class odb::access; }; ======================================================================= Thanks a lot, Lukas From lists at tinloaf.de Wed Sep 26 07:37:06 2018 From: lists at tinloaf.de (Lukas Barth) Date: Wed Sep 26 07:44:54 2018 Subject: [odb-users] Use a view to query many-to-many relationship In-Reply-To: <40fba53a-e5fa-1c64-cc50-66d22a8bfa43@tinloaf.de> References: <40fba53a-e5fa-1c64-cc50-66d22a8bfa43@tinloaf.de> Message-ID: <2ca413c4-9093-35b0-fb28-c0b7d2d750c4@tinloaf.de> Hi, I figured out how to do what I want (see previous mail) in raw SQL, for reference. The example from my previous mail could be achieved like this: SELECT * FROM MyObject INNER JOIN ( SELECT * from ConfigKV WHERE key = 'foo' AND value = 'bar' ) as SQ1 on SQ1.cfg = MyObject.cfg INNER JOIN ( SELECT * from ConfigKV WHERE key = 'fuz' AND value = 'baz' ) as SQ2 on SQ2.cfg = MyObject.cfg WHERE MyObject.value = 42 AND NOT EXISTS ( SELECT 1 FROM ConfigKV WHERE ConfigKV.cfg = MyObject.cfg AND NOT ( key = 'foo' AND value = 'bar' OR key = 'fuz' AND value = 'baz' ) ) ; The query looks a bit intimidating, but is pretty easy: - One INNER JOIN per Key-Value pair to eliminate all MyObjects that don't have a required key-value mapping - The final "AND NOT EXISTS" to filter out everything that has extra Key-Value mappings. I know I can execute raw SQL using db::execute, but that doesn't allow me to retrieve the results. I know that I can have arbitrary SQL in views using pragma annotations, but that SQL needs to be known at compile time, right? I need to build the SQL dynamically, because the number of INNER JOINs required depends on the number of Key-Value pairs? Thanks again, Lukas From boris at codesynthesis.com Thu Sep 27 21:24:53 2018 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Sep 27 21:32:44 2018 Subject: [odb-users] Use a view to query many-to-many relationship In-Reply-To: <40fba53a-e5fa-1c64-cc50-66d22a8bfa43@tinloaf.de> References: <40fba53a-e5fa-1c64-cc50-66d22a8bfa43@tinloaf.de> Message-ID: Lukas Barth writes: > However, now there's a to-many relationship to the ConfigKVs. How do I > formulate a view / a query on a view that only selects the entries that > have exactly the right ConfigKVs associated? Basically, I'd need a magic > "contains" and "size" predicates in the query language like this: > > db->query(query::value == 42 && > query::cfg->kvs->contains( > query::key == 'foo' && > query::value == 'bar') && > query::cfg->kvs->contains( > query::key == 'fuz' && > query::value == 'baz') && > query::cfg->kvs->size() == 2) > > Note that I modeled the 'exactly the two required KV mappings' by asking > for both to be contained and then querying for the size to be exactly > two. Are there any such predicates in the query language? Or is there a > different way of formulating this? There is no query support for containers yet and whether it is actually doable is not clear (you used the word "magic" and that's pretty accurate -- the complexity will be significant). So currently the two ways to achieve this are: 1. With a raw SQL and a native view. 2. By re-formulating your containers in terms of objects and relationships (which are supported by the query language).