Nut/README.md

55 lines
1012 B
Markdown
Raw Normal View History

2016-05-12 14:32:50 +08:00
# Nut
2016-05-12 14:25:07 +08:00
2016-05-12 14:32:50 +08:00
## Advanced, Powerful and easy to use ORM for Qt5
2016-05-12 14:25:07 +08:00
2016-05-12 14:32:50 +08:00
## Features:
2016-05-12 14:25:07 +08:00
- Easy to use
- Automatically create and update database
- IDE auto complete support
- Table join detect
2016-05-12 14:32:50 +08:00
## Sample Codes
### Read data from database:
2016-05-12 14:25:07 +08:00
```cpp
2016-05-12 14:41:57 +08:00
autoq = FROM(db.posts())
WHERE(Post::id() == %1)
BIND(postId);
auto posts = q->toList();
// now posts is a QList<Post*> contain all posts in
// database that has id equal to postId variable
2016-05-12 14:25:07 +08:00
```
2016-05-12 14:32:50 +08:00
### Adding to database:
```cpp
2016-05-12 14:41:57 +08:00
Post*newPost = new Post;
newPost->setTitle("post title");
db.posts()->append(newPost);
for(int i = 0 ; i < 3; i++){
Comment *comment = new Comment;
comment->setMessage("comment #" + QString::number(i));
newPost->comments()->append(comment);
}
db.saveChanges();
2016-05-12 14:32:50 +08:00
```
### Modify database data:
```cpp
auto q = FROM(db.posts())
2016-05-12 14:41:57 +08:00
WHERE(Post::id() == %1)
BIND(postId);
2016-05-12 14:32:50 +08:00
2016-05-12 14:41:57 +08:00
Post *post = q->first();
2016-05-12 14:32:50 +08:00
2016-05-12 14:41:57 +08:00
if(post) {
post->setTitle("new name");
db.saveChanges();
} else {
qWarning("No post found!");
}
2016-05-12 14:32:50 +08:00
```