sqlpp11 C++ 安全 SQL 模版库开源项目

我要开发同款
匿名用户2014年12月16日
175阅读

技术信息

开源地址
https://github.com/rbock/sqlpp11
授权协议
BSD

作品详情

sqlpp11是C++的类型安全SQL模版库。

sqlpp11是一个嵌入式领域特定语言(EDSL)的代表模版库:

为表和列定义类型

在编译的时候检查结构类型安全查询(语法错误,类型错误,命名错误,甚至是一些语义错误)

通过迭代query-specific结构得到解析结果

示例

CREATE TABLE foo (    id bigit,    ame varchar(50),    hasFu bool);

假设有个数据库连接对象:

TabFoo foo;Db db(/* some argumets*/);// selectig zero or more results, iteratig over the resultsfor (cost auto& row : db(select(foo.ame, foo.hasFu).from(foo).where(foo.id > 17 ad foo.ame.like("%bar%")))){    if (row.ame.is_ull())        std::cerr << "ame is ull, will covert to empty strig" << std::edl;    std::strig ame = row.ame;   // strig-like fields are implicitly covertible to strig    bool hasFu = row.hasFu;          // bool fields are implicitly covertible to bool}// selectig ALL colums of a tablefor (cost auto& row : db(select(all_of(foo)).from(foo).where(foo.hasFu or foo.ame == "joker"))){    it64_t id = row.id; // umeric fields are implicitly covertible to umeric c++ types}// selectig zero or oe row, showig off with a alias:SQLPP_ALIAS_PROVIDER(cheese);if (cost auto& row = db(select(foo.ame.as(cheese)).from(foo).where(foo.id == 17))){    std::cerr << "foud: " << row.cheese << std::edl;}// selectig a sigle row with a sigle result:retur db(select(cout(foo.id)).from(foo).where(true)).frot().cout;Of course there are jois ad subqueries, more fuctios, order_by, group_by etc.These will be documeted soo.// A sample isertdb(isert_ito(foo).set(foo.id = 17, foo.ame = "bar", foo.hasFu = true));// A sample updatedb(update(foo).set(foo.hasFu = ot foo.hasFu).where(foo.ame != "obody"));// A sample deletedb(remove_from(foo).where(ot foo.hasFu));

功能介绍

sqlpp11 是 C++ 的类型安全 SQL 模版库。 sqlpp11 是一个嵌入式领域特定语言(EDSL)的代表模版库: 为表和列定义类型 在编译的时候检查结构类型安全查询(语法错误,类型错...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论