ccORM是本人的一次c++对sql查询的完美实践,写起来得心应手,效率非常之高,值得推荐。
#include "ccORM.hh"
auto d = crow::D("127.0.0.1","test","root","",3306,"utf8");//D_();//或者可以直接用宏(已经配置好的方式)
int main() {
using namespace crow; using namespace std;
auto q = d.conn();//创建一个连接
q("DROP table if exists users_test;");//跟写sql语句一样,后面即将支持orm
q("CREATE TABLE users_test (id int,name TEXT,age int);");
//可以使用变量方便地获取sql返回的值
int i = 0; q("SELECT 200+2").r__(i);
std::string s; q("SELECT 'hello world'").r__(s);
//使用stmt批量执行,这里使用string包装是为方便后面实现orm时进行拼接
auto add = q.query(string("INSERT into users_test(id, name, age) values (?,?,?);"));
add(1,"Alex",44);
add(2,"Boom",23);
add(3,"Flux",21);
//下面这行是使用stmt的方式执行一次插入语句。
q.query(string("INSERT into users_test(id, name, age) values