Nut/README.md

56 lines
1.1 KiB
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
2016-05-24 14:47:37 +08:00
- IDE auto complete support, No hard-code nedded
2016-05-12 14:25:07 +08:00
- 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())
2016-05-21 16:09:03 +08:00
WHERE(Post::idField() == postId);
2016-05-12 14:41:57 +08:00
auto posts = q->toList();
// now posts is a QList<Post*> contain all posts in
// database that has id equal to postId variable
2016-05-21 16:09:03 +08:00
auto post = q->first();
// post is first row in database that its id is equal to postId
2016-05-12 14:25:07 +08:00
```
2016-05-12 14:32:50 +08:00
### Adding to database:
```cpp
2016-05-24 14:47:37 +08:00
Post *newPost = new Post;
2016-05-12 14:41:57 +08:00
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-21 16:09:03 +08:00
WHERE(Post::idField() == 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
```