sqlpp11
=======
A type safe embedded domain specific language for SQL queries and results in C++.
```diff
!If you are a tenured user of sqlpp11, please note that
! - with 0.61 the connector libraries for mysql/sqlite/postgresql got merged into the main repo.
! - master has been renamed to main and is now the default branch
```
Documentation is found in [docs](docs/Home.md).
So what is this about?
----------------------
SQL 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.
sqlpp11 is a templated library representing an embedded domain specific language (EDSL) that allows you to
* define types representing tables and columns,
* construct type safe queries checked at compile time for syntax errors, type errors, name errors and even some semantic errors,
* interpret results by iterating over query-specific structs with appropriately named and typed members.
This results in several benefits, e.g.
* the library user operates comfortably on structs and functions,
* the compiler reports many kinds of errors long before the code enters unit testing or production,
* the library hides the gory details of string construction for queries and interpreting results returned by select calls.
The 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.
sqlpp11’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 the developer 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 the developer being required to change the statement.
Connectors for MariaDB, MySQL, PostgreSQL, sqlite3, sqlcipher are included in this repository.
The 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.
Examples:
---------
For the examples, lets assume you have a table class representing something like
```SQL
CREATE TABLE foo (
id bigint,
name varchar(50),
hasFun bool
);
```
And we assume to have a database connection object:
```C++
TabFoo foo;
Db db(/* some arguments*/);
// selecting zero or more results, iterating over the results
for (const auto& row : db(select(foo.name, foo.hasFun).from(foo).where(foo.id > 17 and foo.name.like("%bar%"))))
{
if (row.name.is_null())
std::cerr << "name is null, will convert to empty string" << std::endl;
std::string name = row.name; // string-like fields are implicitly convertible to string
bool hasFun = row.hasFun; // bool fields are implicitly convertible to bool
}
// selecting ALL columns of a table
for (const auto& row : db(select(all_of(foo)).from(foo).where(foo.hasFun or foo.name == "joker")))
{
int64_t id = row.id; // numeric fields are implicitly convertible to numeric c++ types
}
// selecting zero or one row, showing off with an alias:
SQLPP_ALIAS_PROVIDER(cheese);
if (const auto& row = db(select(foo.name.as(cheese)).from(foo).where(foo.id == 17)))
{
std::cerr << "found: " << row.cheese << std::endl;
}
// selecting a single row with a single result:
return db(select(count(foo.id)).from(foo).unconditionally()).front().count;
Of course there are joins and subqueries, more functions, order_by, group_by etc.
These will be documented soon.
// A sample insert
db(insert_into(foo).set(foo.id = 17, foo.name = "bar", foo.hasFun = true));
// A sample update
db(update(foo).set(foo.hasFun = not foo.hasFun).where(foo.name != "nobody"));
// A sample delete
db(remove_from(foo).where(not foo.hasFun));
```
License:
-------------
sqlpp11 is distributed under the [BSD 2-Clause License](https://github.com/rbock/sqlpp11/blob/master/LICENSE).
Status:
-------
Branch / Compiler | clang, gcc | MSVC | Test Coverage
------------------|-------------|--------|---------------
master | [![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)
develop | [![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)
Additional information available:
---------------------------------
Past talks about sqlpp11 and some coding concepts used within the library:
* [CppCast:](http://cppcast.com)
* 2015-05-07: http://cppcast.com/2015/05/roland-bock/
* [CppCon:](http://cppcon.org)
* 2015-09-24: [Pruning Error Messages From Your C++ Template Code](https://www.youtube.com/watch?v=2ISqFW9fRws), with examples from sqlpp11
* 2014-09-11: [sqlpp11, An SQL Library Worthy Of Modern C++](https://www.youtube.com/watch?v=cJPAjhBm-HQ)
* [Meeting C++:](http://meetingcpp.com)
* 2014-12-05: [sqlpp11, An EDSL For Type-Safe SQL In C++11](https://www.youtube.com/watch?v=9Hjfg9IfzhU)
* [MUC++:](http://www.meetup.com/MUCplusplus/)
* 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)
Requirements:
-------------
__Compiler:__
sqlpp11 makes heavy use of C++11 and requires a recent compiler and STL. The following compilers are known to compile the test programs:
* clang-3.4+ on Ubuntu-12.4
* g++-4.8+ on Ubuntu-12.4
* g++-4.8+ on cygwin 64bit
* g++-4.9+ on Debian Unstable
* Xcode-7 on OS X
* MSVC 2015 Update 1 on Windows Server 2012
__Database Connector:__
sqlpp11 requires a certain api in order to connect with the database, see database/api.h.
This repository includes the following connectors:
* MySQL
* MariaDB
* SQLite3
* SQLCipher
* PostgreSQL
Other connectors can be found here:
* ODBC: https://github.com/Erroneous1/sqlpp11-connector-odbc (experimental)
__Date Library:__
sqlpp11 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`.
Build and Install
-----------------
**Note**: Depending on how you use the lib, you might not need to install it (see Basic Usage)
__Build from Source:__
Download and unpack the latest release from https://github.com/rbock/sqlpp11/releases or clone the repository. Inside the directory run the following commands:
```bash
cmake -B build
cmake --build build --target install
```
The last step will build the library and install it system wide, therefore it might need admins rights.
By default only the core library will be installed. To also install connectors set the appropriate variable to `ON`:
* `BUILD_MYSQL_CONNECTOR`
* `BUILD_MARIADB_CONNECTOR`
* `BUILD_POSTGRESQL_CONNECTOR`
* `BUILD_SQLITE3_CONNECTOR`
* `BUILD_SQLCIPHER_CONNECTOR`
The library will check if all required dependencies are i
没有合适的资源?快使用搜索试试~ 我知道了~
用于 C++ 的类型安全 SQL 模板库大全
共555个文件
h:341个
cpp:131个
txt:30个
需积分: 5 0 下载量 120 浏览量
2024-05-16
11:57:13
上传
评论
收藏 774KB ZIP 举报
温馨提示
在现代C++开发中,类型安全的SQL模板库能够极大地简化数据库交互,同时提供编译时检查,减少运行时错误。以下是一些著名的类型安全SQL模板库,它们广泛应用于C++项目中,旨在提供高效、安全和便捷的数据库操作支持。 ### 1. **SOCI** SOCI (The C++ Database Access Library) 是一个灵活的C++库,提供了对多种数据库的支持。它的设计目标是简化数据库访问,提供类似于嵌入式SQL的体验。 - **主要特点**: - 支持多种数据库,包括 SQLite、MySQL、PostgreSQL、Oracle等。 - 提供类型安全的绑定,减少SQL注入风险。 - 支持自定义类型的序列化和反序列化。 - **资源**: - 官方网站:[SOCI](http://soci.sourceforge.net/) - GitHub:[SOCI on GitHub](https://github.com/SOCI/soci) ### 2. **sqlpp11** sqlpp11 是一个现代的C++11/14库,专注于类型安全的SQL查询构建
资源推荐
资源详情
资源评论
收起资源包目录
用于 C++ 的类型安全 SQL 模板库大全 (555个子文件)
.clang-format 2KB
FindSQLCipher.cmake 5KB
Sqlpp11Config.cmake 3KB
FindMySQL.cmake 3KB
Sqlpp11TargetHelper.cmake 3KB
FindMariaDB.cmake 2KB
Sqlpp11PostgreSQLConfig.cmake 61B
Sqlpp11SQLCipherConfig.cmake 60B
Sqlpp11SQLite3Config.cmake 58B
Sqlpp11MariaDBConfig.cmake 58B
Sqlpp11MySQLConfig.cmake 56B
coveralls 883B
SelectType.cpp 23KB
Function.cpp 22KB
join.cpp 13KB
result_row.cpp 12KB
DateTimeParser.cpp 12KB
circular_buffer.cpp 10KB
having.cpp 9KB
insert.cpp 8KB
Interpret.cpp 8KB
Sample.cpp 8KB
Sample.cpp 8KB
from.cpp 7KB
Select.cpp 7KB
where.cpp 7KB
Select.cpp 7KB
Select.cpp 6KB
DateTime.cpp 6KB
TimeZone.cpp 6KB
From.cpp 6KB
case.cpp 6KB
aggregates.cpp 6KB
Select.cpp 6KB
update_list.cpp 6KB
Prepared.cpp 6KB
Insert.cpp 5KB
text.cpp 5KB
DateTime.cpp 5KB
Date.cpp 5KB
Integral.cpp 5KB
Blob.cpp 5KB
CustomQuery.cpp 5KB
DateTime.cpp 5KB
FloatingPoint.cpp 5KB
Type.cpp 4KB
CustomQuery.cpp 4KB
Transaction.cpp 4KB
unwrapped_bool.cpp 4KB
date_time.cpp 4KB
date.cpp 4KB
DateTime.cpp 4KB
no_self_compare.cpp 4KB
in.cpp 4KB
Blob.cpp 4KB
Transaction.cpp 3KB
Truncated.cpp 3KB
Exceptions.cpp 3KB
Ppgen.cpp 3KB
Prepared.cpp 3KB
DynamicLoadingTest.cpp 3KB
Where.cpp 3KB
DynamicSelect.cpp 3KB
Update.cpp 3KB
MoveConstructor.cpp 3KB
CustomQuery.cpp 3KB
InsertOnConflict.cpp 3KB
Union.cpp 3KB
Float.cpp 3KB
Json.cpp 3KB
With.cpp 3KB
DynamicSelect.cpp 3KB
Result.cpp 3KB
As.cpp 3KB
Attach.cpp 3KB
Remove.cpp 3KB
Over.cpp 3KB
Blob.cpp 3KB
Union.cpp 2KB
With.cpp 2KB
In.cpp 2KB
Remove.cpp 2KB
Update.cpp 2KB
AutoIncrement.cpp 2KB
Union.cpp 2KB
Insert.cpp 2KB
Operator.cpp 2KB
ConnectionPool.cpp 2KB
ReturningEmptyAssert.cpp 2KB
Count.cpp 2KB
Max.cpp 2KB
Min.cpp 2KB
Avg.cpp 2KB
Sum.cpp 2KB
ForUpdate.cpp 2KB
IsNotNull.cpp 2KB
BasicConstConfig.cpp 2KB
Returning.cpp 2KB
IsNull.cpp 2KB
Execute.cpp 2KB
共 555 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
编程资源宝库
- 粉丝: 2934
- 资源: 152
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于HTML的旅游网页制作源码设计.zip
- 基于HTML的旅游网页制作源码设计.zip
- 大数据揭秘京沪程序员的爱情代码 WIFIPIX(PDF格式).rar
- 大数据实战Demo系统-MaxCompute数据仓库数据转换实践(PDF格式).rar
- 六一儿童节代码祝福六一儿童节代码祝福六一儿童节代码祝福.txt
- sql语句sql语句sql语句sql语句.txt
- ubuntu20.04安装教程ubuntu20.04安装教程.txt
- imgcache.0
- 高分项目基于faster-rcnn知识蒸馏的目标检测模型增量深度学习方法源码.zip
- 基于python和图数据库neo4j构建电影应用(高分毕设项目)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功