Giter Site home page Giter Site logo

hamedmasafi / nut Goto Github PK

View Code? Open in Web Editor NEW
286.0 286.0 73.0 4.98 MB

Advanced, Powerful and easy to use ORM for Qt

License: GNU Lesser General Public License v3.0

C 2.23% QMake 2.56% C++ 82.63% CMake 12.58%
database mysql orm orm-library postgresql qt sql sql-server sqlite

nut's Introduction

Hamed Masafi's github stats Hamed Masafi's github stats

Technologies & Languages I use

c++ Qt QML

nut's People

Contributors

amreisa avatar bodhi369 avatar hamedmasafi avatar jacklilhammers avatar martonmiklos avatar nickaein avatar soyoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nut's Issues

class not registered with qt meta object

when I cop unittest tst_datetime's db and sampletable class to an simple demo, it cause fatal
for sampletable
qFatal("The class %s is not registered with qt meta object", qPrintable(name));

code snippet :
DB db;
db.setDriver("QSQLITE");
db.setDatabaseName("hello.db");
auto bOpen = db.open();

Can add some additional demos for how to use it?

Lack in docs

Automatically create and update database

When, how?

multiple select

how can make custom select "SELECT filed1,filed2,filed3 FROM table"

Foreign key objects in Nut::Row

Hi, I see that Nut::Row sharedpointers have fields related to their foreign keys. But they are always null. I want to be able to access those objects directly from the child table. Is this possible? Am I doing something wrong?

For example I have two tables, posts and comments:
"Comment" class has "Post" as foreign key. And "Post" class has "comments" as child table. Now, when I get a comment row with;
Nut::Row c = db.comments()->query()->first();

Here pointer "c" contains fields as postId and post. postId shows the related post's id. It is fine. BUT field "post" is always null. However it would be awesome if I could access to object post like this:
QString pn = c->post->postname(); // currently this line throws error, the app crashes, because c->post is nullptr.

I tried "join" but result is the same. post is always null.
Nut::Row c = db.comments()->query()->join()->first();
QString pn = c->post->postname(); // result is same as above.

Development platform:
OS: ubuntu 18.04
Qt creator 4.13.0, based on Qt 5.15.0
Compiler GCC 5.3.1
Nut commit hash: Commit 6ce50e2 by Jack Lilhammers, 07/07/2020 05:50 PM // this is the commit you used in OrmTest repo.
Serializer commit hash: Commit b0194da3 by Miklós Márton, 06/13/2020 12:00 AM // this is the commit you used in OrmTest repo.

Thank you in advance.

Problem of Table Inheritance.

If the table is inherited and find by the field of the parent, it doesn't work.

class Person : public Nut::Table {
Q_OBJECT
NUT_PRIMARY_AUTO_INCREMENT(id)
NUT_DECLARE_FIELD(int, id, getId, setId)
}

class Student : public Person {
Q_OBJECT
NUT_DECLARE_FIELD(QString, name, getName, setName)
}

db.student()->query()->where(Student::idField()==1)->first();

Error Message: Error executing sql command: no such column: Person.id

Lots of errors in tst_benchmark

Hi again.
when i run it, tests fail and in application output, i see 9 errors:

:-1: error: post.o: in function `Post::scoresTable()':
/mnt/D/Document/WorkSpace/Qt/Forked/Nut/test/common/post.cpp:15: error: undefined reference to `Score::Score(QObject*)'
:-1: error: post.o: in function `Nut::TableSet<Score>::TableSet(Nut::Table*)':`
/mnt/D/Document/WorkSpace/Qt/Forked/Nut/src/tableset.h:69: error: undefined reference to `Score::staticMetaObject'`
:-1: error: weblogdatabase.o: in function `Nut::TableSet<User>::TableSet(Nut::Database*)':`
/mnt/D/Document/WorkSpace/Qt/Forked/Nut/src/tableset.h:63: error: undefined reference to `User::staticMetaObject'`
:-1: error: weblogdatabase.o: in function `Nut::TableSet<Score>::TableSet(Nut::Database*)':
/mnt/D/Document/WorkSpace/Qt/Forked/Nut/src/tableset.h:63: error: undefined reference to `Score::staticMetaObject'
:-1: error: collect2: error: ld returned 1 exit status

add options methods to new version

on DatabasePrivate::open (File : database.cpp)
when called if not find database it direct make db.exec("CREATE DATABASE " + databaseName);
but some time we just want to return just error only
so if you can make options methods to that like
void Database::setCrateDatabase(bool default)
void Database::setCrateTables(bool default)

thanx and sorry for my bad English 😄

QFATAL exception in tst_basic subproject

Hi. i wanted to run tests in tst_basic. but this error appeared:

Test for project "tst_basic" crashed.
Command line: /mnt/D/Document/WorkSpace/Qt/Forked/Nut/test/build-tst_basic-Desktop_Qt_5_11_1_GCC_64bit-Debug/tst_nut -xml
PATH: /mnt/E/QtLinux/5.11.1/gcc_64/bin:/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/opt/android-ndk:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/opt/android-sdk/tools/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
LD_LIBRARY_PATH: /mnt/E/QtLinux/5.11.1/gcc_64/lib:/mnt/E/QtLinux/5.11.1/gcc_64/lib
Run configuration:  "tst_basic"

And in application output i see:

QDEBUG : MainTest::join() "Elapsed time: 0ms for join"
QFATAL : MainTest::join() ASSERT: "comments.length()" in file ../basic/maintest.cpp, line 231
FAIL!  : MainTest::join() Received a fatal error.
   Loc: [Unknown file(0)]
Totals: 6 passed, 1 failed, 0 skipped, 0 blacklisted, 3803ms
********* Finished testing of MainTest *********
12:37:26: The program has unexpectedly finished.
12:37:26: The process was ended forcefully.
12:37:26: /mnt/D/Document/WorkSpace/Qt/Forked/Nut/test/build-tst_basic-Desktop_Qt_5_11_1_GCC_64bit-Debug/tst_nut crashed.

Find a better way for join

In current state join can make between two table(master to child and vice versa) with related properties.
There are limitations like:

  • Can not be more than one relation between two tables
  • Can not join to master of master of child of childs

Wiki request for pages Status, Getting Started, and Example

I Forked it to help out with the Project in terms of Documentation, but quickly ran into issues, the first is obvious, its failing for both Travis and AppVoyer, by itself would not be an issue, but I am also having issues, for example, I can open the project(s) in Qt Creator, not sure which *.pro file I should use is the first obstacle, nut.pro compiles but does not make a library, this is an Open Issue #97, and both nut-dynamic.pro, Nut.pro fail to compile, so the Status page will help out users like myself, that do not like to have to ask questions like this, and with no update on #97, I am not sure what I am missing, for example, is this a Library, or do I just include it in my project, and compile it in, if so, the Getting Started Page should reflect that, as it is, I have no clue, and #97 is also in the same position, not understanding the basics.

Example of Status page: https://github.com/Light-Wizzard/Nut/wiki/1.Status

Getting Started should show users how to use this project, my issue is the same as #97, it makes no Library.

Example of Getting Started Page: https://github.com/Light-Wizzard/Nut/wiki/2.Getting.Started

I can only help out if I understand your workflow, if you give me some basic answers, I can update my Wiki pages to reflect that, and you can just copy and paste them into your Wiki, and edit them as you wish.

If you give me a link to a working demo or example app that I can use for an example, I can probably figure out the rest and make an example page, maybe you can just make an examples folder and post them there to point to, so the Examples Page will be a tutorial on how to use it, so the examples or demo code should do something simple, like a task list and a contact manager that shows off all the features.

I think its the lack of any examples that is the root of my not understanding how to use it with full example code, with *.pro file, and some type of tutorial would be nice, if you can help me get through this process, I can make a slide show style video to help out promoting the project on YouTube, just make a Nut Account, I will upload to my account for you to watch, if you like it, I will zip up the files I used to make it, along with the video itself, and give you the download link, I will use Blender in 4k with Audio explaining, so you do not have to read it, the words are there to translate into other languages, that is better to do in subtitles, so you need to know what languages you want to support, English is the only one I know, so the only one I can support, computer translations are not hard to do, I can even write bash scripts to automate that.

If you need to fund the project, YouTube is a better option, not only if you can get over 1,000 subscribers you can monetize for ads, but you can link to a donation page.

If you are interested in this type of help, let me know, otherwise, I hope you take these as suggestions and feature requests.

In fact, I would make it a feature to have users make videos for you to upload to YouTube, to get the word out about the project.

At this point, I have no idea if it even works, since I just started using it today, and ran into the issues above, but I figured that the ratings you have mean something, its how I pick this project over the French QxOrm https://www.qxorm.com/qxorm_en/home.html, not that I have anything against the French, I am married to one, that was a joke, English Humor, I picked it because of code you wrote, not because of who wrote it, good code is hard to find, the code is normally in English, but not so much the comments, and with no translations to go along with them, its not easy to follow the code, so I am checking out this project also, even if I need to get my wife to translate for me, so my question to you is, can you compete with that project, pros and cons would help out with a Getting Started page, why use one over the other, and something you need to do if you want to compete but to compare is also great, a benchmark even better, so how serious are you is a question that I want to write about on those pages, and put into those videos, but only you can answer them.

People coming to your page need to know if it works for the first thing and having two red marks without any reason why makes most people shy away, at least write a reason for the failure, maybe someone can help out.

Benchmarks are not the most important, being the fastest should never be your goal, ease of use across multiple databases should, so instead of comparisons, just show your own benchmark test.

You also need to consider a stage of development, and goals, as well as Status, your Readme is too short, and your Wiki's only show stubs, so full examples should be a priority, as well as workflow diagrams.

I currently need an ORM that is working or has a timeline to one that will work at some point in time, so what you really need is a project manager that can update status, like most people, our support is normally limited to our interest or need for a project, my interest is long term, I will look for short term solutions that work now, but still focus on the long term, but I also need to know what is how there, so I know for myself, all the pros and cons, and ultimately what project I pick for the long term, all depends upon what I determine to be the best for my needs, and I need to know the answers to my questions just to get started.

Thanks, Flesh

MSSql and PostgreSql dose not support "`"

QWARN : MainTest::selectPublicts() Error executing sql command: [Microsoft][ODBC SQL Server Driver][SQL Server]'' ???????? QODBC3: Unable to execute statement; Command=SELECT COUNT(*) FROM posts WHERE posts`.isPublic = 1
test\basic\maintest.cpp, line 153

in sqlgeneratorbase.cpp file #745

Cannot remove from database

Hi. i have a favorites table(for a music app) and i want to remove some items from it. i wrote this method:

virtual void removeFromFavorites(QString title, QString path) override
    {
        Query<Favorites>* q = db.favorites()->query()->setWhere(Favorites::titleField() == title && Favorites::pathField() == path);

        q->toList();

        Favorites* fav = q->first();
        db.favorites()->remove(fav);
        db.saveChanges();
    }

but q is null. and subsequently the application crashes. although in db, i have a record like this:
Marshall-Bruce Mathers. III | /home/linarcx/Music/06.justlikeit.mp3
why?

Support for column alias in the toModel

Hi @HamedMasafi

Having a toModel method is very conveinent for creating queries which is displayed in a QTableView.
However I think having ability to customize the column headers is necessary in the most cases.

I am thinking about implementing an intermediate class (derived from the QSqlQueryModel) which would override the headerData method, and the overridden header data could be set through the Query::setColumnName(Field, alias).

How does this sounds for you?

Composite keys

In my project I have tools and protocols. A tool can communicate with different protocols and a protocol can be used by different tools. Tools and protocols have their tables.
I tried to manually create a relationship [n: m] by adding a third tool_protocol table but without composite keys the only way that comes to mind to do this would be to have a third column with an ID that should be some kind of hash of the other 2 columns.
I looked into the primary key implementation, but I think that it would be better to have a COMPOSITE_KEY macro.
What do you think?

Examples?

Any "serious" or "real world" examples of Nut?

qstrings can cause sql errors depending on contents

When a QString has a single quote in it, it breaks the sql statements because the raw commands use single quotes to contain content. There should be something handling this case, like escaping them.

ex:

Error executing sql command: near "s": syntax error Unable to execute statement; Command=UPDATE purchases SET humanname='Sid Meier's Civilization® III: Complete', type='storefront', intname='civilization3_complete_storefront', humbleid='' WHERE id=1

Code generation from database schema

Hi @HamedMasafi

First of all thank you for your great work, I am not using it yet, but it looks very promising!

I was wondering if it would be useful to create a code generator which would generate the database/table code automatically from a given database schema.

I am thinking about something similar what is called scaffolding in CakePHP (more exactly only the model generation of that).

The table connections (hasMany, belongsTo in CakePHP terminology) could be detected by detecting the naming convention of the fields (if post table has an user_id key then post belongsTo User).

If you like this idea I can work on it and submit a PR or we can develop this tool even in a separate repository.

Thanks in advance and happy new year!

QByteArray not stored correctly

Hello, I am trying to store an image in a sqlite database.
I generate a QByteArray from pixmap. The resultant byte array has 10000 elements in it. Then I create a nut row, set image column, append new row to table and lastly save changes. None of them return any errors. The code I use is given below:

db.open();
QByteArray bArray;
QBuffer buffer(&bArray);
buffer.open(QIODevice::WriteOnly);
ui->lblGelCardImage->pixmap()->save(&buffer, "PNG");
auto newReport = Nut::create<Report>();
newReport->setImage(bArray);
// set other columns as well...
db.tblReports()->append(newReport);
bool ok = db.saveChanges();

BUT, my database doesn't increase in size AND when I try to retrieve the data back, it only returns 10 bytes. The code I use in order to retrieve the image is given below:

db.open();
QByteArray ba = db.tblReports()->query()->first().data()->Image();

Byte array "ba" only has 10 bytes of data in it. It should have contained 10000 bytes of data. What is the problem here? Am I doing something wrong? Every other column is stored and retrieved correctly.

tblReport class has the line below regarding Image field.
NUT_DECLARE_FIELD(QByteArray, Image, Image, setImage)

I used Nut version that you used in OrmTest repo. Actually that is the only version i was able to use after hours of trying. I am kinda newbie to qt.

Development platform:

  • OS: ubuntu 18.04
  • Qt creator 4.13.0, based on Qt 5.15.0
  • Compiler GCC 5.3.1
  • Nut commit hash: Commit 6ce50e2 by Jack Lilhammers, 07/07/2020 05:50 PM
  • Serializer commit hash: Commit b0194da3 by Miklós Márton, 06/13/2020 12:00 AM

File missing - sqlserializer.h

Theres a file missing while trying to build on Windows with MSVC2015 / Qt5.12

D:\Projetos\Nut....\Nut\src\generators\sqlgeneratorbase.cpp:34: error: C1083: NÆo ‚ poss¡vel abrir arquivo incluir: 'sqlserializer.h': No such file or directory

Linking problem (undefined reference)

Hi,

First of all I'd like to thank you a lot for the great project. Today I tried to create a tiny example for testing Nut but I faced a problem with linking Nut in my project so I get many undefined reference messages.

May you please guide me how to fix this error?

OrmTest.pri

win32 {
        CONFIG(debug,debug|release):   LIBDIR = $$absolute_path($$OUT_PWD/../libs/Nut/src/debug)
        CONFIG(release,debug|release): LIBDIR = $$absolute_path($$OUT_PWD/../libs/Nut/src/release)
} else {
        LIBDIR = $$absolute_path($$OUT_PWD/../libs/Nut/src/)
}

LIBS += -L$$LIBDIR -lnut
INCLUDEPATH += $$PWD/../libs/Nut/src/

DEFINES += NUT_SHARED_POINTER

Project's structure:

OrmTest
├── libs
│   └── Nut (submodule)
├── LICENSE
├── OrmTest.pro
└── src
    ├── companyemployees.cpp
    ├── companyemployees.h
    ├── main.cpp
    ├── mainwindow.cpp
    ├── mainwindow.h
    ├── mainwindow.ui
    ├── OrmTest.pri
    ├── OrmTest.pro
    ├── user.cpp
    └── user.h

notnull is handled wrong?!

I noticed that the NUT_NOT_NULL macro doesn't work as it's supposed to. After some digging I found out that it's probably handled wrong in tablemodel.cpp#L228.

The statement should be

f->notNull = true;

right?

ERROR with make

when I try to make ,
generators\sqlgeneratorbase.cpp:34:10: fatal error: sqlserializer.h: No such file or directory #include "sqlserializer.h"

Lots of errors in test files

Hi. i want to see the features of your library. so run them in qt creator. for example open the tst_command sample. when it run the tests, i'v got some errors like this:

/mnt/E/Downloads/Nut-master/test/commands/maintest.cpp:40: error: ‘class WeblogDatabase’ has no member named ‘posts’; did you mean ‘post’?
     Query<Post>* q = db.posts()->query()->setWhere(Post::titleField() == "test" && Post::idField() < 4 + 5);
                         ^~~~~
                         post

or:

/mnt/E/Downloads/Nut-master/test/commands/maintest.cpp:49: error: no member named 'posts' in 'WeblogDatabase'

Getting joins working

Hello @HamedMasafi

I have had some trouble of getting a join working properly.

According to the commented out test for this I assume this feature is broken/not yet implemented.

I got to a point when would be able to bind together a row ( Row<Table> ) for a related model with the row of the main table:
https://github.com/martonmiklos/Nut/blob/qtrafik/src/query.h#L312

At this point I am a bit lost, and as I seen you are more on the edge in the Qt metaobject hacks, so I would like to ask for some hints on this topic.

So I would like to assign a Row<Table> to an Row<Table> member of an another Table object specified by a string.

My first idea was to use QObject::setProperty but I cannot get it to set a Table* member.

Any hint, idea is warmly welcome!

about __change_logs.

hi, it's log always crash when reopen the database.
Databse is new
Error executing sql command CREATE TABLE __change_logs (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT, version INT), table __change_logs already exists Unable to execute statement

Purpose of the NUT_FOREIGN_KEY macro?

Hello @HamedMasafi

May I ask what was the intention with the NUT_FOREIGN_KEY:

#define NUT_FOREIGN_KEY(type, keytype, name, read, write) \

Is it left in accidentally or it was the start of something? I have not found any reference in the code to it.

I am working on upstreaming my join fix so I will poke around the NUT_FOREIGN_KEY_DECLARE/IMPLEMENT and if I am there it might be useful to remove it to remove confusion.

Table with same struct.

class IDatabase : public Nut::Database
{
Q_OBJECT

NUT_DB_VERSION(1)

NUT_DECLARE_TABLE(Network, a)
NUT_DECLARE_TABLE(Network, b)
NUT_DECLARE_TABLE(Network, c)
NUT_DECLARE_TABLE(Network, d)

};

It seems that if tables have the same table struct, a()、b()、c() will always operate on the table 'a'.

if have multi condition for where, how to write?

auto posts = db.posts().query()
->whete(Post::idField() == 1 && Post::readFile()==false)
->orderBy(!Post::idField())
->toList();

like above write two condition where is null. how to resolve

Use QUuid as Primary key

Hi.
Can I use QUuid as table primary key?

NUT_PRIMARY_AUTO_INCREMENT(id)
NUT_DECLARE_FIELD(QUuid, id, id, setId)

How about auto generating QUuids ? Is it handled by database? or I should add id manually?

Thanks :-)

Programmatic ConditionalPhrase

Hi, I need to generate ConditionalPhrase dynamically for filtering the database entries.
For example the user might use "name" field only to filter results. Also the user might want to use "date" field to filter results at the same time. Like these two cases, I have many filtering options. And user may use any combination of those. So when I generate my query with:
_db.tbl.query()->where( _myConditionalPhrase)->toList();

I want to generate "_myConditionalPhrase" object in my code dynamically by checking if individual filtering options are filled by user. Is this possible and if yes how? Can you give an example?

Add optional parent argument to Query::toModel

Hi @HamedMasafi

During the usage of the Query::toModel I was wondering if it would be helpful to pass a QObject *parent = nullptr argument to it to make that object to be the parent of the created model here:
https://github.com/HamedMasafi/Nut/blob/master/src/query.h#L592

This would make the created model destruction easily manageable through the QObject destruction process.
What do you think about this idea?
If you like it I can came up with a PR.

Not building under mingw

Windows 10, Qt 5.5.1 mingw 4.9.2
Build output:
In file included from generators\../database.h:30:0, from generators\sqlgeneratorbase.cpp:30: generators\../tableset.h: In member function 'Nut::Row<T> Nut::TableSet<T>::at(int) const': generators\../tableset.h:105:30: error: invalid use of incomplete type 'const class QSharedPointer<Nut::Table>' return data->childs.at(i).template objectCast<T>(); ^ In file included from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qobject.h:48:0, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qiodevice.h:39, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qtextstream.h:37, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/qdebug.h:42, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/QDebug:1, from generators\sqlgeneratorbase.cpp:22: C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:207:7: error: declaration of 'const class QSharedPointer<Nut::Table>' F(QSharedPointer) \ ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1317:30: note: in definition of macro 'QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER' template <class T> class Name; \ ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1319:1: note: in expansion of macro 'QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER' QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER) ^ In file included from generators\../database.h:30:0, from generators\sqlgeneratorbase.cpp:30: generators\../tableset.h: In member function 'Nut::Row<T> Nut::TableSet<T>::operator[](int) const': generators\../tableset.h:115:30: error: invalid use of incomplete type 'const class QSharedPointer<Nut::Table>' return data->childs.at(i).template objectCast<T>(); ^ In file included from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qobject.h:48:0, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qiodevice.h:39, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qtextstream.h:37, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/qdebug.h:42, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/QDebug:1, from generators\sqlgeneratorbase.cpp:22: C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:207:7: error: declaration of 'const class QSharedPointer<Nut::Table>' F(QSharedPointer) \ ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1317:30: note: in definition of macro 'QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER' template <class T> class Name; \ ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1319:1: note: in expansion of macro 'QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER' QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER) ^ In file included from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qglobal.h:1098:0, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qchar.h:37, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qstring.h:41, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/qdatetime.h:37, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/QDate:1, from generators\sqlgeneratorbase.cpp:21: C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qtypeinfo.h: In instantiation of 'class QTypeInfo<QSharedPointer<Nut::Table> >': C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:462:31: required from 'void QList<T>::node_destruct(QList<T>::Node*, QList<T>::Node*) [with T = QSharedPointer<Nut::Table>]' C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:835:68: required from 'void QList<T>::dealloc(QListData::Data*) [with T = QSharedPointer<Nut::Table>]' C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:796:18: required from 'QList<T>::~QList() [with T = QSharedPointer<Nut::Table>]' generators\../tablesetbasedata.h:35:40: required from here C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qtypeinfo.h:58:26: error: invalid application of 'sizeof' to incomplete type 'QSharedPointer<Nut::Table>' isLarge = (sizeof(T)>sizeof(void*)), ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qtypeinfo.h:60:24: error: invalid application of 'sizeof' to incomplete type 'QSharedPointer<Nut::Table>' sizeOf = sizeof(T) ^ In file included from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qhash.h:40:0, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qshareddata.h:39, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/qdatetime.h:39, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/QDate:1, from generators\sqlgeneratorbase.cpp:21: C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h: In instantiation of 'void QList<T>::node_destruct(QList<T>::Node*, QList<T>::Node*) [with T = QSharedPointer<Nut::Table>]': C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:835:68: required from 'void QList<T>::dealloc(QListData::Data*) [with T = QSharedPointer<Nut::Table>]' C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:796:18: required from 'QList<T>::~QList() [with T = QSharedPointer<Nut::Table>]' generators\../tablesetbasedata.h:35:40: required from here C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:463:31: warning: possible problem detected in invocation of delete operator: [-Wdelete-incomplete] while(from != to) --to, delete reinterpret_cast<T*>(to->v); ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:463:31: warning: invalid use of incomplete type 'class QSharedPointer<Nut::Table>' In file included from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qobject.h:48:0, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qiodevice.h:39, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qtextstream.h:37, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/qdebug.h:42, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/QDebug:1, from generators\sqlgeneratorbase.cpp:22: C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:207:7: warning: declaration of 'class QSharedPointer<Nut::Table>' F(QSharedPointer) \ ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1317:30: note: in definition of macro 'QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER' template <class T> class Name; \ ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1319:1: note: in expansion of macro 'QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER' QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER) ^ In file included from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qhash.h:40:0, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qshareddata.h:39, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/qdatetime.h:39, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/QDate:1, from generators\sqlgeneratorbase.cpp:21: C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:463:31: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined while(from != to) --to, delete reinterpret_cast<T*>(to->v); ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qlist.h:465:32: error: invalid use of incomplete type 'class QSharedPointer<Nut::Table>' while (from != to) --to, reinterpret_cast<T*>(to)->~T(); ^ In file included from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qobject.h:48:0, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qiodevice.h:39, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qtextstream.h:37, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/qdebug.h:42, from C:\Qt\Qt5.5.1\5.5\mingw492_32\include\QtCore/QDebug:1, from generators\sqlgeneratorbase.cpp:22: C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:207:7: error: declaration of 'class QSharedPointer<Nut::Table>' F(QSharedPointer) \ ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1317:30: note: in definition of macro 'QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER' template <class T> class Name; \ ^ C:\Qt\Qt5.5.1\5.5\mingw492_32\include/QtCore/qmetatype.h:1319:1: note: in expansion of macro 'QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER' QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(QT_FORWARD_DECLARE_SHARED_POINTER_TYPES_ITER)

Ambiguous in doc

Hi. and thank you for this greate job. i want to use nut in my app but i;m a bit confused about docs. see:

Read data from database:

auto q = db.posts()->createQuery();
q->setWhere(Post::idField() == postId);
auto posts = q->toList();
// now posts is a QList<Post*> contain all posts in
//  database that has id equal to postId variable
auto post = q->first();
// post is first row in database that its id is equal to postId

where db defined?
or in update sample:

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();

The Post Object comes from where?!
and how db knows that it has a posts() method?

Build failure QJsonValue::QJsonValue(const *) is private

Hello
On trying to build both the tests , basic example and attempting to use it in my example , i get this error ,

/usr/include/qt5/QtCore/qjsonvalue.h: In member function ‘QJsonObject TableModel::toJson() const’:
/usr/include/qt5/QtCore/qjsonvalue.h:119:12: error: ‘QJsonValue::QJsonValue(const void_)’ is private
inline QJsonValue(const void *) {}
^
../../src/tablemodel.cpp:282:62: error: within this context
fieldObj.insert(__TYPE, QVariant::typeToName(f->type));
^
make: *_* [tablemodel.o] Error 1

Any idea you could give me to get this ORM to build ?

Can not select data on mysql driver?

//code
auto q = db.users()->query()
->setWhere(User::idField() == "{a5dba5aa-254a-45fc-bee3-a102cfb805f5}");
int num = q->count(); // num is 1;
User* u = q->first(); // u is NULL;

Doesn't update or delete if primary key is string.

I found and fix the error of doesn't update or delete if primary key is string.

I solved this issue as below:

sqlgeneratorbase.cpp

*QString SqlGeneratorBase::updateRecord(Table t, QString tableName)

    sql = QString("UPDATE %1 SET %2 WHERE %3=%4")
            .arg(tableName)
            .arg(values.join(", "))
            .arg(key)
            .arg(val.type() == QVariant::String ? "\'" + val.toString() + "\'" : val.toString());

*QString SqlGeneratorBase::deleteRecord(Table t, QString tableName)

    QString sql = QString("DELETE FROM %1 WHERE %2='%3'")
            .arg(tableName)
            .arg(t->primaryKey())
            .arg(val.type() == QVariant::String ? "\'" + val.toString() + "\'" : val.toString());

It make fail with "sqlserializer.h: No such file or directory"

Steps to reproduce the behavior:

  1. "qmake nut.pro"
  2. "make"

Output
generators\sqlgeneratorbase.cpp:34:27: fatal error: sqlserializer.h: No such file or directory compilation terminated. Makefile.Release:818: recipe for target 'release/sqlgeneratorbase.o' failed make[2]: *** [release/sqlgeneratorbase.o] Error 1 make[2]: Leaving directory 'D:/WorkSpace/Nut-master/src' Makefile:36: recipe for target 'release' failed make[1]: *** [release] Error 2 make[1]: Leaving directory 'D:/WorkSpace/Nut-master/src' Makefile:41: recipe for target 'sub-src-make_first-ordered' failed make: *** [sub-src-make_first-ordered] Error 2

Development platform:

  • OS: [e.g. win10 2016 LTSB ]
  • Qt version [e.g. 5.9.9]
  • Compiler [e.g.MingW 5.3.0]

What requirement is nut?

Could you make a list of requirement for using nut?
I knew 1 requirement is "mysql connector c " source code.

I use qt5.12 on windows10.
Many thanks!
jeff

[1 to many] relations implementation

I read that [1 to many] relations are implemented with child tables, but I can't see them in the db.
Is it the user's responsibility to explicitly create those tables?
Shouldn't be the ORM the one that creates them?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.