Nut/README.md

79 lines
2.0 KiB
Markdown
Raw Normal View History

2019-02-13 00:03:22 +08:00
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
2019-02-28 16:10:41 +08:00
| Branch | Status |
2018-01-15 22:24:11 +08:00
| ------------- |:-------------:|
| 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) |
2019-03-10 00:09:33 +08:00
[![GitLicense](https://gitlicense.com/badge/hamedmasafi/nut)](https://gitlicense.com/license/hamedmasafi/nut)
2019-03-10 00:06:28 +08:00
[![Codacy
Badge](https://api.codacy.com/project/badge/Grade/f3802610beb946068f6cd2c2b6608a8b)](https://www.codacy.com/app/HamedMasafi/Nut?utm_source=github.com&utm_medium=referral&utm_content=HamedMasafi/Nut&utm_campaign=Badge_Grade)
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
- Supported types: [Full list](doc/datatypes.md)
2019-02-13 00:03:22 +08:00
2016-05-12 14:25:07 +08:00
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-10-15 22:34:50 +08:00
### Donate
Butcoin address: 1Dn1WHKkaxanXe4cTGDk4cFRRABxLUpEVj
2018-10-15 22:34:50 +08:00
![Wallet addresst](btc-qr.png)
2018-01-08 17:35:26 +08:00
For more information read [Wiki](wiki).