sqlpp23 is a type safe embedded domain specific language for SQL queries and results in C++. It allows you to write SQL in the form of C++ expressions:
from()
insert_into()
sqlpp23’s core is vendor-neutral.
Specific traits of databases (e.g. unsupported or non-standard features) are handled by connector libraries. Connector libraries can inform you and your IDE of missing features at compile time. They also interpret expressions specifically where needed. For example, the connector could use the operator||
or the concat
method for string concatenation without your being required to change the statement.
Connectors for MariaDB, MySQL, PostgreSQL, sqlite3, sqlcipher are included in this repository.
Documentation is found in docs.
If you are coming from sqlpp11, you might be interested in differences.
Let's assume we have a database connection object db
and a table object foo
representing something like
CREATE TABLE foo ( id bigint NOT NULL, name varchar(50), hasFun bool NOT NULL );
db(insert_into(foo).set(foo.id = 17, foo.name = "bar", foo.hasFun = true));
db(update(foo).set(foo.name = std::nullopt).where(foo.name != "nobody"));
db(delete_from(foo).where(not foo.hasFun));
// selecting zero or more results, iterating over the results for (const auto& row : db(select(foo.id, foo.name, foo.hasFun) .from(foo) .where(foo.id > 17 and foo.name.like("%bar%")))) { std::cout << row.id << '\n'; // int64_t std::cout << row.name.value_or("NULL") << '\n'; // std::optional<std::string_view> std::cout << row.hasFun() << '\n'; // bool }
for (const auto &row : db(sql::insert_into(foo) .set(foo.id = 7, foo.name = std::nullopt, foo.hasFun = false) .on_conflict(foo.id) .do_update(foo.name = "updated") .where(foo.id > 17) .returning(foo.name))) { std::cout << row.name.value_or("NULL") << '\n'; }
Compiler: sqlpp23 makes use of C++23 and requires a recent compiler and standard library.
License:
sqlpp23 is distributed under the BSD 2-Clause License.
Feature requests, bug reports, contributions to code or documentation are most welcome.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4