Readme
This commit is contained in:
parent
068cc1980c
commit
84fa41942a
54
README.md
54
README.md
|
|
@ -14,42 +14,42 @@
|
|||
### Read data from database:
|
||||
|
||||
```cpp
|
||||
auto q = 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
|
||||
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
|
||||
```
|
||||
|
||||
### 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();
|
||||
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);
|
||||
WHERE(Post::id() == %1)
|
||||
BIND(postId);
|
||||
|
||||
Post *post = q->first();
|
||||
Post *post = q->first();
|
||||
|
||||
if(post = 0) {
|
||||
post->setTitle("new name");
|
||||
db.saveChanges();
|
||||
} else {
|
||||
qWarning("No post found!");
|
||||
}
|
||||
if(post) {
|
||||
post->setTitle("new name");
|
||||
db.saveChanges();
|
||||
} else {
|
||||
qWarning("No post found!");
|
||||
}
|
||||
```
|
||||
Loading…
Reference in New Issue