Skip to content

Instantly share code, notes, and snippets.

@pjc0247
Created January 6, 2015 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjc0247/5f499fae5dda4c2d0462 to your computer and use it in GitHub Desktop.
Save pjc0247/5f499fae5dda4c2d0462 to your computer and use it in GitHub Desktop.
/* SELECT * FROM account */
auto rows = accounts.all();
for(auto &row : rows)
cout<<row.get("level").as_int();
/* SELECT * FROM account WHERE user_id='pjc0247' AND user_pw='asdf1234' */
auto rows = accounts
.begin()
.match("user_id", "pjc0247")
.match("user_pw", "asdf1234")
.all();
auto rows = accounts
.n("post").all();
auto rows = accounts
.n("post")
.begin()
.like("body", "%hello%")
.all();
auto row = accounts
.n("post").create();
row.set("body", "hello world");
row.save();
int main(){
db::table accounts("account")
.property<db::serial>("id")
.property<string>("user_id")
.property<string>("user_pw")
.property<int>("level")
.property<db::datetime>("created_at")
.has_n("post")
.migrate();
db::table posts("post")
.property<db::serial>("id")
.property<string>("body")
.property<db::datetime>("created_at")
.belongs_to("account")
.migrate();
return 0;
}
auto rows = accounts
.begin() // db::query 리턴
.match("user_id", "pjc0247")
.match("user_pw", "asdf1234")
.all(); // vector<db::row> 리턴
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment