{"id":13417971,"url":"https://github.com/rbock/sqlpp11","last_synced_at":"2025-05-14T00:07:39.181Z","repository":{"id":10044566,"uuid":"12091112","full_name":"rbock/sqlpp11","owner":"rbock","description":"A type safe SQL template library for C++","archived":false,"fork":false,"pushed_at":"2025-03-18T20:04:51.000Z","size":6678,"stargazers_count":2529,"open_issues_count":37,"forks_count":345,"subscribers_count":107,"default_branch":"main","last_synced_at":"2025-04-10T22:17:37.404Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rbock.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-08-13T19:49:34.000Z","updated_at":"2025-04-10T05:05:06.000Z","dependencies_parsed_at":"2023-10-15T07:40:51.766Z","dependency_job_id":"22e6aaff-6a1b-45fd-99bb-fe94961c0606","html_url":"https://github.com/rbock/sqlpp11","commit_stats":null,"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbock%2Fsqlpp11","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbock%2Fsqlpp11/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbock%2Fsqlpp11/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbock%2Fsqlpp11/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rbock","download_url":"https://codeload.github.com/rbock/sqlpp11/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043792,"owners_count":22005018,"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":[],"created_at":"2024-07-30T22:00:56.471Z","updated_at":"2025-05-14T00:07:39.162Z","avatar_url":"https://github.com/rbock.png","language":"C++","readme":"sqlpp11\n=======\nA type safe embedded domain specific language for SQL queries and results in C++.\n\n```diff\n!If you are a tenured user of sqlpp11, please note that\n!  - with 0.61 the connector libraries for mysql/sqlite/postgresql got merged into the main repo.\n!  - master has been renamed to main and is now the default branch\n```\n\nDocumentation is found in [docs](docs/Home.md).\n\nSo what is this about?\n----------------------\nSQL and C++ are both strongly typed languages. Still, most C/C++ interfaces to SQL are based on constructing queries as strings and on interpreting arrays or maps of strings as results.\n\nsqlpp11 is a templated library representing an embedded domain specific language (EDSL) that allows you to\n\n  * define types representing tables and columns,\n  * construct type safe queries checked at compile time for syntax errors, type errors, name errors and even some semantic errors,\n  * interpret results by iterating over query-specific structs with appropriately named and typed members.\n\nThis results in several benefits, e.g.\n\n  * the library user operates comfortably on structs and functions,\n  * the compiler reports many kinds of errors long before the code enters unit testing or production,\n  * the library hides the gory details of string construction for queries and interpreting results returned by select calls.\n\nThe library supports both static and dynamic queries. The former offers greater benefit in terms of type and consistency checking. The latter makes it easier to construct queries in flight.\n\nsqlpp11’s core is vendor-neutral.\nSpecific traits of databases (e.g. unsupported or non-standard features) are handled by connector libraries.\nConnector libraries can inform the developer of missing features at compile time.\nThey also interpret expressions specifically where needed.\nFor example, the connector could use the operator|| or the concat method for string concatenation without the developer being required to change the statement.\n\nConnectors for MariaDB, MySQL, PostgreSQL, sqlite3, sqlcipher are included in this repository.\n\nThe library is already used in production but it is certainly not complete yet. Feature requests, bug reports, contributions to code or documentation are most welcome.\n\nExamples:\n---------\nFor the examples, lets assume you have a table class representing something like\n\n```SQL\nCREATE TABLE foo (\n    id bigint,\n    name varchar(50),\n    hasFun bool\n);\n```\n\nAnd we assume to have a database connection object:\n\n```C++\nTabFoo foo;\nDb db(/* some arguments*/);\n\n// selecting zero or more results, iterating over the results\nfor (const auto\u0026 row : db(select(foo.name, foo.hasFun).from(foo).where(foo.id \u003e 17 and foo.name.like(\"%bar%\"))))\n{\n    if (row.name.is_null())\n        std::cerr \u003c\u003c \"name is null, will convert to empty string\" \u003c\u003c std::endl;\n    std::string name = row.name;   // string-like fields are implicitly convertible to string\n    bool hasFun = row.hasFun;          // bool fields are implicitly convertible to bool\n}\n\n// selecting ALL columns of a table\nfor (const auto\u0026 row : db(select(all_of(foo)).from(foo).where(foo.hasFun or foo.name == \"joker\")))\n{\n    int64_t id = row.id; // numeric fields are implicitly convertible to numeric c++ types\n}\n\n// selecting zero or one row, showing off with an alias:\nSQLPP_ALIAS_PROVIDER(cheese);\nif (const auto\u0026 row = db(select(foo.name.as(cheese)).from(foo).where(foo.id == 17)))\n{\n    std::cerr \u003c\u003c \"found: \" \u003c\u003c row.cheese \u003c\u003c std::endl;\n}\n\n// selecting a single row with a single result:\nreturn db(select(count(foo.id)).from(foo).unconditionally()).front().count;\n\nOf course there are joins and subqueries, more functions, order_by, group_by etc.\nThese will be documented soon.\n\n// A sample insert\ndb(insert_into(foo).set(foo.id = 17, foo.name = \"bar\", foo.hasFun = true));\n\n// A sample update\ndb(update(foo).set(foo.hasFun = not foo.hasFun).where(foo.name != \"nobody\"));\n\n// A sample delete\ndb(remove_from(foo).where(not foo.hasFun));\n```\n\nLicense:\n-------------\nsqlpp11 is distributed under the [BSD 2-Clause License](https://github.com/rbock/sqlpp11/blob/main/LICENSE).\n\nStatus:\n-------\nBranch / Compiler | clang,  gcc |  MSVC  | Test Coverage\n------------------|-------------|--------|---------------\nmaster | [![Build Status](https://travis-ci.com/rbock/sqlpp11.svg?branch=master)](https://travis-ci.com/rbock/sqlpp11?branch=master) | [![Build status](https://ci.appveyor.com/api/projects/status/eid7mwqgavo0h61h/branch/master?svg=true)](https://ci.appveyor.com/project/rbock/sqlpp11/branch/master) | [![Coverage Status](https://coveralls.io/repos/rbock/sqlpp11/badge.svg?branch=master)](https://coveralls.io/r/rbock/sqlpp11?branch=master)\ndevelop | [![Build Status](https://travis-ci.com/rbock/sqlpp11.svg?branch=develop)](https://travis-ci.com/rbock/sqlpp11?branch=develop) | [![Build status](https://ci.appveyor.com/api/projects/status/eid7mwqgavo0h61h/branch/develop?svg=true)](https://ci.appveyor.com/project/rbock/sqlpp11/branch/develop) | [![Coverage Status](https://coveralls.io/repos/rbock/sqlpp11/badge.svg?branch=develop)](https://coveralls.io/r/rbock/sqlpp11?branch=develop)\n\nAdditional information available:\n---------------------------------\nPast talks about sqlpp11 and some coding concepts used within the library:\n\n  * [CppCast:](http://cppcast.com)\n   * 2015-05-07: http://cppcast.com/2015/05/roland-bock/\n  * [CppCon:](http://cppcon.org)\n   * 2015-09-24: [Pruning Error Messages From Your C++ Template Code](https://www.youtube.com/watch?v=2ISqFW9fRws), with examples from sqlpp11\n   * 2014-09-11: [sqlpp11, An SQL Library Worthy Of Modern C++](https://www.youtube.com/watch?v=cJPAjhBm-HQ)\n  * [Meeting C++:](http://meetingcpp.com)\n   * 2014-12-05: [sqlpp11, An EDSL For Type-Safe SQL In C++11](https://www.youtube.com/watch?v=9Hjfg9IfzhU)\n  * [MUC++:](http://www.meetup.com/MUCplusplus/)\n   * 2014-02-27: [Selected C++11 Template Toffees From sqlpp11, Part1](https://www.youtube.com/watch?v=hXnGFYNbmXg), [Part2](https://www.youtube.com/watch?v=WPCV6dvxZ_U), [Part 3](https://www.youtube.com/watch?v=eB7hd_KjTig), [Part 4](https://www.youtube.com/watch?v=NBfqzcN0_EQ)\n\n\nRequirements:\n-------------\n__Compiler:__\nsqlpp11 makes heavy use of C++11 and requires a recent compiler and STL. The following compilers are known to compile the test programs:\n\n  * clang-3.4+ on Ubuntu-12.4\n  * g++-4.8+ on Ubuntu-12.4\n  * g++-4.8+ on cygwin 64bit\n  * g++-4.9+ on Debian Unstable\n  * Xcode-7 on OS X\n  * MSVC 2015 Update 1 on Windows Server 2012\n\n__Database Connector:__\nsqlpp11 requires a certain api in order to connect with the database, see database/api.h.\n\nThis repository includes the following connectors:\n\n* MySQL\n* MariaDB\n* SQLite3\n* SQLCipher\n* PostgreSQL\n\nOther connectors can be found here:\n\n  * ODBC: https://github.com/Erroneous1/sqlpp11-connector-odbc (experimental)\n\n__Date Library:__\nsqlpp11 requires [Howard Hinnant’s date library](https://github.com/HowardHinnant/date) for `date` and `date_time` data types. By default, sqlpp11 uses FetchContent to pull the library automatically in the project. If you want to use an already installed version of the library with `find_package`, set `USE_SYSTEM_DATE` option to `ON`.\n\nBuild and Install\n-----------------\n\n**Note**: Depending on how you use the lib, you might not need to install it (see Basic Usage)\n\n__Build from Source:__\n\nDownload and unpack the latest release from https://github.com/rbock/sqlpp11/releases or clone the repository. Inside the directory run the following commands:\n\n```bash\ncmake -B build\ncmake --build build --target install\n```\n\nThe last step will build the library and install it system wide, therefore it might need admins rights.\n\nBy default only the core library will be installed. To also install connectors set the appropriate variable to `ON`: \n\n* `BUILD_MYSQL_CONNECTOR`\n* `BUILD_MARIADB_CONNECTOR`\n* `BUILD_POSTGRESQL_CONNECTOR`\n* `BUILD_SQLITE3_CONNECTOR`\n* `BUILD_SQLCIPHER_CONNECTOR`\n\nThe library will check if all required dependencies are installed on the system. If connectors should be installed even if the dependencies are not yet available on the system, set `DEPENDENCY_CHECK` to `OFF`. \n\nExample: Install the core library, sqlite3 connector and postgresql connector. Don’t check if the dependencies such as Sqlite3 are installed and don’t build any tests:\n\n```bash\ncmake -B build -DBUILD_POSTGRESQL_CONNECTOR=ON -DBUILD_SQLITE3_CONNECTOR=ON -DDEPENDENCY_CHECK=OFF -DBUILD_TESTING=OFF\ncmake --build build --target install\n```\n\n__Install via Homebrew (MacOS):__\n\n```bash\nbrew install marvin182/zapfhahn/sqlpp11\n```\n\nSome connectors can be installed with the formula. See `brew info marvin182/zapfhahn/sqlpp11` for available options.\n\n__Build via vcpkg:__\n\nYou can download and install sqlpp11 using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:\n\n```bash\ngit clone https://github.com/Microsoft/vcpkg.git\ncd vcpkg\n./bootstrap-vcpkg.sh\n./vcpkg integrate install\n./vcpkg install 'sqlpp11[mysql]' # or other database feature\n```\n\nThe sqlpp11 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.\n\nBasic usage:\n-------------\n__Use with cmake__:\nThe library officially supports two ways how it can be used with cmake. \nYou can find examples for both methods in the examples folder. \n\n1. FetchContent (Recommended, no installation required)\n1. FindPackage (installation required, see above)\n\nBoth methods will provide the `sqlpp11::sqlpp11` target as well as targets for each connector: \n\n* sqlpp11::mysql\n* sqlpp11::mariadb\n* sqlpp11::sqlite3\n* sqlpp11::sqlcipher\n* sqlpp11::postgresql\n\nThese targets will make sure all required dependencies are available and correctly linked and include directories are set correctly.\n\n__Create DDL files__:\n``` \nmysql: 'show create table MyDatabase.MyTable' #or\nmysqldump --no-data MyDatabase \u003e MyDatabase.sql\n\n```\nCreate headers for them with provided Python script:\n```\n%sqlpp11_dir%/scripts/ddl2cpp ~/temp/MyTable.ddl  ~/temp/MyTable %DatabaseNamespaceForExample%\n```\n\nIn case you’re getting notes about unsupported column type consider:\n  - Take a look at the other datatypes in sqlpp11/data_types. They are not hard to implement.\n  - Use the `--datatype-file` command line argument as described below.\n\nInclude generated header (MyTable.h), that’s all.\n\nIf you prefer Ruby over Python, you might want to take a look at https://github.com/douyw/sqlpp11gen\n\nUnsupported column types:\n-------------\n__Map unsupported column types to supported column types with a csv file__:\n\nOne can use the `--datatype-file` command line argument for the ddl2cpp script to map unsupported column types to supported column types.\n\nThe format of the csv file is:\n```\n\u003cdataType\u003e, \u003ccol_type1\u003e, \u003ccol_type2\u003e\n\u003cdataType\u003e, \u003ccol_type3\u003e\n```\n\nWhere `\u003cdataType\u003e` is one or more of the following internal types:\n\n  - `Boolean`\n  - `Integer`\n  - `Serial`\n  - `FloatingPoint`\n  - `Text`\n  - `Blob`\n  - `Date`\n  - `DateTime`\n  - `Time`\n\nExample:\n\n```\nBoolean, one_or_zero\nText, url, uuid\n```\n\nContact:\n--------\n  * Issues at https://github.com/rbock/sqlpp11/issues\n  * email at rbock at eudoxos dot de\n","funding_links":[],"categories":["TODO scan for Android support in followings","Database","C++","Networking","Libraries"],"sub_categories":["Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbock%2Fsqlpp11","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frbock%2Fsqlpp11","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbock%2Fsqlpp11/lists"}