Created
January 6, 2015 10:50
-
-
Save pjc0247/5f499fae5dda4c2d0462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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