sqlite_orm v1.4 Release Notes

Release Date: 2019-08-13 // over 4 years ago
  • ๐Ÿ‘ โญ CASE support

    // SELECT ID, NAME, MARKS,// CASE// WHEN MARKS \>=80 THEN 'A+'// WHEN MARKS \>=70 THEN 'A'// WHEN MARKS \>=60 THEN 'B'// WHEN MARKS \>=50 THEN 'C'// ELSE 'Sorry!! Failed'// END// FROM STUDENT;auto rows = storage.select(columns(&Student::id, &Student::name, &Student::marks, case\_\<std::string\>() .when(greater\_or\_equal(&Student::marks, 80), then("A+")) .when(greater\_or\_equal(&Student::marks, 70), then("A")) .when(greater\_or\_equal(&Student::marks, 60), then("B")) .when(greater\_or\_equal(&Student::marks, 50), then("C")) .else\_("Sorry!! Failed") .end()));// decltype(rows) is std::vector\<std::tuple\<decltype(Student::id), decltype(Student::name), decltype(Student::marks), std::string\>\>
    

    or

    // SELECT CASE country WHEN 'USA' THEN 'Dosmetic' ELSE 'Foreign' END// FROM usersauto rows = storage.select(columns(case\_\<std::string\>(&User::country) .when("USA", then("Dosmetic")) .else\_("Foreign") .end()), multi\_order\_by(order\_by(&User::lastName), order\_by(&User::firstName)));// decltype(rows) is std::vector\<std::string\>
    

    โญ Added core functions: COALESCE, ZEROBLOB, SUBSTR

    // SELECT coalesce(10,20);cout \<\< "coalesce(10,20) = " \<\< storage.select(coalesce\<int\>(10, 20)).front() \<\< endl;// SELECT substr('SQLite substr', 8);cout \<\< "substr('SQLite substr', 8) = " \<\< storage.select(substr("SQLite substr", 8)).front() \<\< endl;// SELECT substr('SQLite substr', 1, 6);cout \<\< "substr('SQLite substr', 1, 6) = " \<\< storage.select(substr("SQLite substr", 1, 6)).front() \<\< endl;// SELECT zeroblob(5);cout \<\< "zeroblob(5) = " \<\< storage.select(zeroblob(5)).front().size() \<\< endl;
    

    โญ Dynamic ORDER BY

    order_by and multi_order_by are strong typed so you cannot specify ORDER BY column type at runtime. dynamic_order_by solves this problem. dynamic_order_by is a multi_order_by that accepts order_by conditions at runtime. Example:

    auto orderBy = dynamic\_order\_by(storage);if(shouldOrderByNameAndId){ orderBy.push\_back(order\_by(&User::name)); orderBy.push\_back(order\_by(&User::id)); }else{ orderBy.push\_back(order\_by(&User::id)); }auto rows = storage.get\_all\<User\>(where(...), orderBy);
    

    โญ Added LIKE as a query result

    Now LIKE can also be used as a core function to retrieve a result:

    auto rows = storage.select(like(&User::name, "J%"));// decltype(rows) is std::vector\<bool\>
    

    ๐Ÿ‘ โญ Added LIKE ESCAPE option support

    LIKE has a third argument and now it is available in sqlite_orm:

    // SELECT name LIKE 'J%' ESCAPE '\_'// FROM usersauto rows = storage.select(like(&User::name, "J%").escape("\_"));
    

    or

    // SELECT LIKE(name, 'J%', '\_')// FROM usersauto rows = storage.select(like(&User::name, "J%", "\_"));
    
    • ๐Ÿฑ โš™๏ธ Added Catch2 unit tests framework into unit tests project
    • ๐Ÿ”ง โš™๏ธ Added unit tests configurations for even more platforms and compilers (thanks to @Farwaykorse)
    • ๐Ÿฑ โš™๏ธ Added contributing doc
    • ๐Ÿฑ ๐Ÿš€ Added nullptr binding to WHERE conditions
    • ๐Ÿฑ ๐Ÿš€ Reduced binary size
    • ๐Ÿฑ ๐Ÿš€ Added composite key support for storage_t::remove function
    • ๐Ÿฑ ๐Ÿš€ Reduces memory consumption ๐Ÿฑ ๐Ÿš€ Better error reporting

    ๐Ÿ‘ป Before once you get an exception thrown asking e.what() gave you a poor text like NOT NULL constraint failed. Now it is more detailed (thanks to sqlite3_errmsg function) like: NOT NULL constraint failed: users.age: constraint failed

    ๐Ÿฑ ๐Ÿž Bug fixes

    • ๐Ÿ›  Fixed GCC6 compilation bug
    • ๐Ÿ›  Fixed runtime error on ARM architecture
    • Fixed getter by value support for storage_t::replace and storage_t::update functions
    • ๐Ÿ›  Fixed bug with iterating over blob values
    • Fixed on_copy coping on storage_t copy
    • ๐Ÿ›  Fixed silencing binding failure - now exception is thrown
    • Fixed using std::unique_ptr in storage_t::update_all set arguments
    • ๐Ÿ›  Fixed incorrect (reverse) arguments order in GROUP BY