{"id":27625904,"url":"https://github.com/lastrada-software/lightweight","last_synced_at":"2025-04-23T12:31:26.607Z","repository":{"id":257830568,"uuid":"836404786","full_name":"LASTRADA-Software/Lightweight","owner":"LASTRADA-Software","description":"thin and lightweight, fast, ODBC API wrapper for modern C++ uses","archived":false,"fork":false,"pushed_at":"2025-04-18T10:51:31.000Z","size":5259,"stargazers_count":5,"open_issues_count":28,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-18T11:03:17.929Z","etag":null,"topics":["cplusplus","cplusplus-23","cplusplus-library","data-mapper","data-mapper-pattern","datamapper","library","migration-tool","odbc"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LASTRADA-Software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-31T19:22:19.000Z","updated_at":"2025-04-16T20:20:21.000Z","dependencies_parsed_at":"2024-12-05T18:25:24.067Z","dependency_job_id":"12329b62-848c-475a-9a29-ba781ec0c4a6","html_url":"https://github.com/LASTRADA-Software/Lightweight","commit_stats":{"total_commits":67,"total_committers":1,"mean_commits":67.0,"dds":0.0,"last_synced_commit":"9b830387a3d3aec9a0eca70be0b92647aa2106f8"},"previous_names":["christianparpart/lightweight","lastrada-software/lightweight"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LASTRADA-Software%2FLightweight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LASTRADA-Software%2FLightweight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LASTRADA-Software%2FLightweight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LASTRADA-Software%2FLightweight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LASTRADA-Software","download_url":"https://codeload.github.com/LASTRADA-Software/Lightweight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250434778,"owners_count":21430161,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cplusplus","cplusplus-23","cplusplus-library","data-mapper","data-mapper-pattern","datamapper","library","migration-tool","odbc"],"created_at":"2025-04-23T12:31:24.477Z","updated_at":"2025-04-23T12:31:26.562Z","avatar_url":"https://github.com/LASTRADA-Software.png","language":"C++","readme":"# Lightweight, an ODBC SQL API for C++23\n\n**Lightweight** is a thin and modern C++ ODBC wrapper for **easy** and **fast** raw database access.\n\nDocumentation is available at [https://lastrada-software.github.io/Lightweight/](https://lastrada-software.github.io/Lightweight/).\n\n## Goals\n\n- **Easy to use** - simple, expressive and intuitive API\n- **Production ready** - targeting production grade systems\n- **Performance** - do as little as possible, and as much as necessary - **Zero overhead abstraction** is a key design requirement.\n- **Extensible** - support for custom data types for writing to and reading from columns\n- **Resource aware** - efficient resource management and exception safety\n\n## Example: CRUD-style High level Data Mapping\n\n```cpp\n// Define a person structure, mapping to a table\n// The field members are mapped to the columns in the table,\n// and the Field\u003c\u003e template parameter specifies the type of the column.\n// Field\u003c\u003e is also used to track what fields are modified and need to be updated.\nstruct Person\n{\n    Field\u003cSqlGuid, PrimaryKey::AutoAssign\u003e id;\n    Field\u003cSqlAnsiString\u003c25\u003e\u003e name;\n    Field\u003cbool\u003e is_active { true };\n    Field\u003cstd::optional\u003cint\u003e\u003e age;\n};\n\nvoid CRUD(DataMapper\u0026 dm)\n{\n    // Creates the table if it does not exist\n    dm.CreateTable\u003cPerson\u003e();\n\n    // Create a new person\n    auto person = Person {};\n    person.name = \"John Doe\";\n    person.is_active = true;\n    dm.Create(person);\n\n    // Update the person\n    name.age = 25;\n    dm.Update(person);\n\n    // Query the person\n    if (auto const po = dm.QuerySingle\u003cPerson\u003e(person.id); po)\n        std::println(\"Person: {} ({})\", po-\u003ename, DataMapper::Inspect(*po));\n\n    // Query all persons\n    auto const persons = dm.Query\u003cPerson\u003e(); \n\n    // Delete the person\n    dm.Delete(person);\n}\n```\n\n## Example: Simple row retrieval via structs\n\nWhen only read access is needed, you can use a simple struct to represent the row,\nand also do not need to wrap the fields into `Field\u003c\u003e` template.\nThe struct must have fields that match the columns in the query. The fields can be of any type that can be converted from the column type. The struct can have more fields than the columns in the query, but the fields that match the columns must be in the same order as the columns in the query.\n\n```cpp\nstruct SimpleStruct\n{\n    uint64_t pkFromA;\n    uint64_t pkFromB;\n    SqlAnsiString\u003c30\u003e c1FromA;\n    SqlAnsiString\u003c30\u003e c2FromA;\n    SqlAnsiString\u003c30\u003e c1FromB;\n    SqlAnsiString\u003c30\u003e c2FromB;\n};\n\nvoid SimpleStructExample(DataMapper\u0026 dm)\n{\n    if (auto maybeObject = dm.Query\u003cSimpleString\u003e(\n        \"SELECT A.pk, B.pk, A.c1, A.c2, B.c1, B.c2 FROM A LEFT JOIN B ON A.pk = B.pk\"); maybeObject)\n    ))\n    {\n        for (auto const\u0026 obj : *maybeObject)\n            std::println(\"{}\", DataMapper::Inspect(obj));\n    }\n}\n```\n\n## Supported platforms\n\nOnly ODBC is supported, so it should work on any platform that has an ODBC driver and\na modern enough C++ compiler.\n\n- Windows (Visual Studio 2022, toolkit v143)\n- Linux (GCC 14, Clang 19)\n\n## Supported databases\n\n- Microsoft SQL\n- PostgreSQL\n- SQLite3\n- Oracle database (work in progress)\n\n## Using SQLite for testing on Windows operating system\n\nYou need to have the SQLite3 ODBC driver for SQLite installed.\n\n- ODBC driver download URL: http://www.ch-werner.de/sqliteodbc/\n- Example connection string: `DRIVER={SQLite3 ODBC Driver};Database=file::memory:`\n\n### SQLite ODBC driver installation on other operating systems\n\n```sh\n# Fedora Linux\nsudo dnf install sqliteodbc\n\n# Ubuntu Linux\nsudo apt install sqliteodbc\n\n# macOS\narch -arm64 brew install sqliteodbc\n```\n\n- sqliteODBC Documentation: http://www.ch-werner.de/sqliteodbc/html/index.html\n- Example connection string: `DRIVER=SQLite3;Database=file::memory:`\n\n\n## Generate example for the existing database\n\nYou can use `ddl2cpp` to generate header file for you database schema as well as an example file that you can compile\n\nFirst, configure cmake project and compile `ddl2cpp` target\n``` sh\ncmake --build build --target ddl2cpp \n```\n\nGenerate header file from the existing database by providing connection string to the tool \n``` sh\n ./build/src/tools/ddl2cpp --connection-string \"DRIVER=SQLite3;Database=test.db\" --make-aliases --naming-convention CamelCase  --output ./src/examples/example.hpp --generate-example\n```\n\nNow you can configure cmake to compile example\n\n``` sh\ncmake --preset linux-clang-debug -DLIGHWEIGHT_EXAMPLE=ON -B build\n```\n\nFinally, compile and run the example\n\n``` sh\ncmake --build build  \u0026\u0026 ./build/src/examples/example\n```\n\n`\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flastrada-software%2Flightweight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flastrada-software%2Flightweight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flastrada-software%2Flightweight/lists"}