Nut/README.md

65 lines
1.5 KiB
Markdown
Raw Normal View History

2016-05-12 14:32:50 +08:00
# Nut
2016-05-12 14:25:07 +08:00
2018-01-15 22:24:11 +08:00
## Build result
| Brancc name | Icon |
| ------------- |:-------------:|
| master | [![Build Status](https://travis-ci.org/HamedMasafi/Nut.svg?branch=master)](https://travis-ci.org/HamedMasafi/Nut) |
| dev | [![Build Status](https://travis-ci.org/HamedMasafi/Nut.svg?branch=dev)](https://travis-ci.org/HamedMasafi/Nut) |
2018-01-08 17:35:26 +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
2017-02-01 18:01:21 +08:00
- Support PosgtreSQL, MySQL, SQLite and Microsoft Sql Server
2016-05-12 14:25:07 +08:00
- 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
2017-02-01 18:01:21 +08:00
auto q = db.posts()->createQuery();
q->setWhere(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
2017-02-01 18:01:21 +08:00
auto q = db.posts()->createQuery();
q->setWhere(Post::idField() == postId);
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-24 14:59:29 +08:00
```
2018-01-08 17:35:26 +08:00
For more information read [Wiki](wiki).