Readme
This commit is contained in:
parent
10e3ea18ad
commit
068cc1980c
46
README.md
46
README.md
|
|
@ -1,18 +1,18 @@
|
||||||
Nut
|
# Nut
|
||||||
===
|
|
||||||
|
|
||||||
Advanced, Powerful and easy to use ORM for Qt5
|
## Advanced, Powerful and easy to use ORM for Qt5
|
||||||
---
|
|
||||||
|
|
||||||
Features:
|
|
||||||
|
## Features:
|
||||||
|
|
||||||
- Easy to use
|
- Easy to use
|
||||||
- Automatically create and update database
|
- Automatically create and update database
|
||||||
- IDE auto complete support
|
- IDE auto complete support
|
||||||
- Table join detect
|
- Table join detect
|
||||||
|
|
||||||
Sample code for reading:
|
## Sample Codes
|
||||||
---
|
### Read data from database:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
auto q = FROM(db.posts())
|
auto q = FROM(db.posts())
|
||||||
WHERE(Post::id() == %1)
|
WHERE(Post::id() == %1)
|
||||||
|
|
@ -21,3 +21,35 @@ Sample code for reading:
|
||||||
// now posts is a QList<Post*> contain all posts in
|
// now posts is a QList<Post*> contain all posts in
|
||||||
// database that has id equal to postId variable
|
// database that has id equal to postId variable
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Adding to database:
|
||||||
|
```cpp
|
||||||
|
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();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Modify database data:
|
||||||
|
```cpp
|
||||||
|
auto q = FROM(db.posts())
|
||||||
|
WHERE(Post::id() == %1)
|
||||||
|
BIND(postId);
|
||||||
|
|
||||||
|
Post *post = q->first();
|
||||||
|
|
||||||
|
if(post = 0) {
|
||||||
|
post->setTitle("new name");
|
||||||
|
db.saveChanges();
|
||||||
|
} else {
|
||||||
|
qWarning("No post found!");
|
||||||
|
}
|
||||||
|
```
|
||||||
Loading…
Reference in New Issue