From 068cc1980c650584758a3abd2826e9e9140c0443 Mon Sep 17 00:00:00 2001 From: Hamed Masafi Date: Thu, 12 May 2016 11:02:50 +0430 Subject: [PATCH] Readme --- README.md | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 23ea9cf..26bcf6a 100644 --- a/README.md +++ b/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 - Automatically create and update database - IDE auto complete support - Table join detect -Sample code for reading: ---- +## Sample Codes +### Read data from database: + ```cpp auto q = FROM(db.posts()) WHERE(Post::id() == %1) @@ -21,3 +21,35 @@ Sample code for reading: // now posts is a QList 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(); +``` + +### 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!"); + } +``` \ No newline at end of file