thin and lightweight, fast, ODBC API wrapper for modern C++ uses
Lightweight is a thin and modern C++ ODBC wrapper for easy and fast raw database access.
auto sqlStatement = SqlStatement();
auto const& queryFormatter = sqlStatemnt.Connection().QueryFormatter();
// SELECT "employee_id", "first_name", "last_name"
// FROM "employees"
// WHERE "employee_id" = 100
// ORDER BY "last_name" ASC LIMIT 5 OFFSET 10
SqlQueryBuilder::FromTable("employees")
.Select()
.Fields("employee_id", "first_name", "last_name")
.Where("employee_id", "=", 100)
.OrderBy("last_name", SqlQueryBuilder::Ascending)
.Range(5, 10)
.ToSql(queryFormatter);
// UPDATE "employees"
// SET "first_name" = 'John', "last_name" = 'Doe'
// WHERE "employee_id" = 100
SqlQueryBuilder::FromTable("employees")
.Update()
.Set("first_name", "John")
.Set("last_name", "Doe")
.Where("employee_id", "=", 100)
.ToSql(queryFormatter);
// INSERT INTO "employees" ("employee_id", "first_name", "last_name")
// VALUES (100, 'John', 'Doe')
SqlQueryBuilder::FromTable("employees")
.Insert()
.Values("employee_id", 100)
.Values("first_name", "John")
.Values("last_name", "Doe")
.ToSql(queryFormatter);
// DELETE FROM "employees"
// WHERE "employee_id" = 100
SqlQueryBuilder::FromTable("employees")
.Delete()
.Where("employee_id", "=", 100)
.ToSql(queryFormatter);
This library a little bit of more modern C++ language and library features in order to be more expressive and efficient.
std::expected
, std::stacktrace
, lambda templates expressions)std::source_location
, std::error_code
, operator<=>
, std::format()
, designated initializers, concepts, ranges)std::string_view
, std::optional
, std::variant
, std::apply
)You need to have the SQLite3 ODBC driver for SQLite installed.
DRIVER={SQLite3 ODBC Driver};Database=file::memory:
# Fedora Linux
sudo dnf install sqliteodbc
# Ubuntu Linux
sudo apt install sqliteodbc
# macOS
arch -arm64 brew install sqliteodbc
DRIVER=SQLite3;Database=file::memory: