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
andmulti_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 amulti_order_by
that acceptsorder_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 insqlite_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 likeNOT NULL constraint failed
. Now it is more detailed (thanks tosqlite3_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
andstorage_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
instorage_t::update_all
set arguments - ๐ Fixed incorrect (reverse) arguments order in GROUP BY