working :-( [skip ci]

This commit is contained in:
Hamed Masafi 2019-06-18 20:07:03 +04:30
parent e946a54753
commit 5e5471fdeb
23 changed files with 285 additions and 213 deletions

View File

@ -3,6 +3,7 @@ QT += core sql
CONFIG += c++11
INCLUDEPATH += $$PWD/include
DEFINES += NUT_SHARED_POINTER
include(3rdparty/serializer/src/src.pri)
HEADERS += \

View File

@ -278,7 +278,7 @@ bool DatabasePrivate::getCurrectScheema()
DatabaseModel DatabasePrivate::getLastScheema()
{
typename TableType<ChangeLogTable>::Row u = changeLogs->query()
Row<ChangeLogTable> u = changeLogs->query()
->orderBy(!ChangeLogTable::idField())
->first();
@ -321,7 +321,7 @@ bool DatabasePrivate::putModelToDatabase()
DatabaseModel current = currentModel;
/*current.remove(__CHANGE_LOG_TABLE_NAME)*/;
auto *changeLog = new ChangeLogTable();
auto changeLog = create<ChangeLogTable>();
changeLog->setData(QJsonDocument(current.toJson()).toJson(QJsonDocument::Compact));
changeLog->setVersion(current.version());
changeLogs->append(changeLog);

View File

@ -45,6 +45,83 @@
Q_CLASSINFO(__nut_NAME_PERFIX type #name #value, \
type "\n" #name "\n" value)
#define NUT_FIELD_PERFIX
#define NUT_FIELD_POSTFIX Field
// Database
#define NUT_DB_VERSION(version) \
NUT_INFO(__nut_DB_VERSION, version, 0)
#define NUT_DECLARE_TABLE(type, name) \
NUT_INFO(__nut_TABLE, type, name) \
Q_PROPERTY(NUT_WRAP_NAMESPACE(TableSet<type>) name READ name) \
NUT_WRAP_NAMESPACE(TableSet<type>) *m_##name; \
public: \
static const type *_##name; \
NUT_WRAP_NAMESPACE(TableSet<type>) *name() const \
{ return m_##name; } \
private:
//Table
#define NUT_DECLARE_FIELD(type, name, read, write) \
Q_PROPERTY(type name READ read WRITE write) \
NUT_INFO(__nut_FIELD, name, 0) \
type m_##name; \
public: \
static NUT_WRAP_NAMESPACE(FieldPhrase<type>)& name ## Field(){ \
static NUT_WRAP_NAMESPACE(FieldPhrase<type>) f = \
NUT_WRAP_NAMESPACE(FieldPhrase<type>) \
(staticMetaObject.className(), #name); \
return f; \
} \
type read() const{ \
return m_##name; \
} \
void write(type name){ \
m_##name = name; \
propertyChanged(#name); \
}
#define NUT_FOREGION_KEY(type, keytype, name, read, write) \
Q_PROPERTY(Nut::Row<type> name READ read WRITE write) \
NUT_DECLARE_FIELD(keytype, name##Id, read##Id, write##Id) \
NUT_INFO(__nut_FOREGION_KEY, name, type) \
Nut::Row<type> m_##name; \
public: \
Nut::Row<type> read() const { return m_##name ; } \
void write(Nut::Row<type> name){ \
m_##name = name; \
}
#define NUT_DECLARE_CHILD_TABLE(type, n) \
private: \
NUT_WRAP_NAMESPACE(TableSet)<type> *m_##n; \
public: \
static type *n##Table(); \
NUT_WRAP_NAMESPACE(TableSet)<type> *n();
#define NUT_IMPLEMENT_CHILD_TABLE(class, type, n) \
type *class::n##Table(){ \
static auto f = new type(); \
return f; \
} \
NUT_WRAP_NAMESPACE(TableSet)<type> *class::n(){ \
return m_##n; \
}
#define NUT_FIELD(name) NUT_INFO(__nut_FIELD, name, 0)
#define NUT_PRIMARY_KEY(x) NUT_INFO(__nut_PRIMARY_KEY, x, 0)
#define NUT_AUTO_INCREMENT(x) NUT_INFO(__nut_AUTO_INCREMENT, x, 0)
#define NUT_PRIMARY_AUTO_INCREMENT(x) NUT_INFO(__nut_PRIMARY_KEY_AI, x, 0)
#define NUT_DISPLAY_NAME(field, name) NUT_INFO(__nut_DISPLAY, field, name)
#define NUT_UNIQUE(x) NUT_INFO(__nut_UNIQUE, x, 0)
#define NUT_LEN(field, len) NUT_INFO(__nut_LEN, field, len)
#define NUT_DEFAULT_VALUE(x, n) NUT_INFO(__nut_DEFAULT_VALUE, x, n)
#define NUT_NOT_NULL(x) NUT_INFO(__nut_NOT_NULL, x, 1)
#define NUT_INDEX(name, field, order)
NUT_BEGIN_NAMESPACE
inline bool nutClassInfo(const QMetaClassInfo &classInfo,
QString &type, QString &name, QVariant &value)
{
@ -117,107 +194,37 @@ inline bool nutClassInfoInt(const QMetaClassInfo &classInfo,
}
}
#define NUT_FIELD_PERFIX
#define NUT_FIELD_POSTFIX Field
// Database
#define NUT_DB_VERSION(version) \
NUT_INFO(__nut_DB_VERSION, version, 0)
#define NUT_DECLARE_TABLE(type, name) \
NUT_INFO(__nut_TABLE, type, name) \
Q_PROPERTY(NUT_WRAP_NAMESPACE(TableSet<type>) name READ name) \
NUT_WRAP_NAMESPACE(TableSet<type>) *m_##name; \
public: \
static const type *_##name; \
NUT_WRAP_NAMESPACE(TableSet<type>) *name() const \
{ return m_##name; } \
private:
//Table
#define NUT_DECLARE_FIELD(type, name, read, write) \
Q_PROPERTY(type name READ read WRITE write) \
NUT_INFO(__nut_FIELD, name, 0) \
type m_##name; \
public: \
static NUT_WRAP_NAMESPACE(FieldPhrase<type>)& name ## Field(){ \
static NUT_WRAP_NAMESPACE(FieldPhrase<type>) f = \
NUT_WRAP_NAMESPACE(FieldPhrase<type>) \
(staticMetaObject.className(), #name); \
return f; \
} \
type read() const{ \
return m_##name; \
} \
void write(type name){ \
m_##name = name; \
propertyChanged(#name); \
}
#define NUT_FOREGION_KEY(type, keytype, name, read, write) \
Q_PROPERTY(type* name READ read WRITE write) \
NUT_DECLARE_FIELD(keytype, name##Id, read##Id, write##Id) \
NUT_INFO(__nut_FOREGION_KEY, name, type) \
type *m_##name; \
public: \
type *read() const { return m_##name ; } \
void write(type *name){ \
m_##name = name; \
}
#define NUT_DECLARE_CHILD_TABLE(type, n) \
private: \
NUT_WRAP_NAMESPACE(TableSet)<type> *m_##n; \
public: \
static type *n##Table(); \
NUT_WRAP_NAMESPACE(TableSet)<type> *n();
#define NUT_IMPLEMENT_CHILD_TABLE(class, type, n) \
type *class::n##Table(){ \
static auto f = new type(); \
return f; \
} \
NUT_WRAP_NAMESPACE(TableSet)<type> *class::n(){ \
return m_##n; \
}
#define NUT_FIELD(name) NUT_INFO(__nut_FIELD, name, 0)
#define NUT_PRIMARY_KEY(x) NUT_INFO(__nut_PRIMARY_KEY, x, 0)
#define NUT_AUTO_INCREMENT(x) NUT_INFO(__nut_AUTO_INCREMENT, x, 0)
#define NUT_PRIMARY_AUTO_INCREMENT(x) NUT_INFO(__nut_PRIMARY_KEY_AI, x, 0)
#define NUT_DISPLAY_NAME(field, name) NUT_INFO(__nut_DISPLAY, field, name)
#define NUT_UNIQUE(x) NUT_INFO(__nut_UNIQUE, x, 0)
#define NUT_LEN(field, len) NUT_INFO(__nut_LEN, field, len)
#define NUT_DEFAULT_VALUE(x, n) NUT_INFO(__nut_DEFAULT_VALUE, x, n)
#define NUT_NOT_NULL(x) NUT_INFO(__nut_NOT_NULL, x, 1)
#define NUT_INDEX(name, field, order)
#ifdef NUT_SHARED_POINTER
template <class T>
using RowList = QList<QSharedPointer<T>>;
template <class T>
struct TableType
{
#ifdef NUT_SHARED_POINTER
typedef QList<QSharedPointer<T>> RowList;
typedef QSet<QSharedPointer<T>> RowSet;
typedef QSharedPointer<T> Row;
using RowSet = QSet<QSharedPointer<T>>;
template <typename T>
using Row = QSharedPointer<T>;
template<class T>
inline Row<T> create() {
return QSharedPointer<T>(new T);
}
#else
typedef QList<T*> RowList;
typedef QSet<T*> RowSet;
typedef T* Row;
template <typename T>
using RowList = QList<T*>;
template <typename T>
using RowSet = QSet<T*>;
template <typename T>
using Row = T*;
template<class T>
inline Row<T> create() {
return new T;
}
#endif
};
//#ifdef NUT_SHARED_POINTER
// template <class T>
// using RowList = typename QList<QSharedPointer<T>>;
// template <typename T>
// using Row = typename QSharedPointer<T>;
//#else
// template <typename T>
// using RowList = typename QList<T*>;
// template <typename T>
// using Row = typename T*
//#endif
NUT_END_NAMESPACE
#endif // SYNTAX_DEFINES_H

View File

@ -89,8 +89,8 @@ public:
Query<T> *setWhere(const ConditionalPhrase &ph);
//data selecting
typename TableType<T>::Row first();
typename TableType<T>::RowList toList(int count = -1);
Row<T> first();
RowList<T> toList(int count = -1);
template <typename F>
QList<F> select(const FieldPhrase<F> f);
@ -175,11 +175,11 @@ Q_OUTOFLINE_TEMPLATE Query<T>::~Query()
}
template <class T>
Q_OUTOFLINE_TEMPLATE typename TableType<T>::RowList Query<T>::toList(int count)
Q_OUTOFLINE_TEMPLATE RowList<T> Query<T>::toList(int count)
{
Q_UNUSED(count);
Q_D(Query);
typename TableType<T>::RowList returnList;
RowList<T> returnList;
d->select = "*";
d->sql = d->database->sqlGenertor()->selectCommand(
@ -378,11 +378,11 @@ Q_OUTOFLINE_TEMPLATE QList<F> Query<T>::select(const FieldPhrase<F> f)
}
template <class T>
Q_OUTOFLINE_TEMPLATE typename TableType<T>::Row Query<T>::first()
Q_OUTOFLINE_TEMPLATE Row<T> Query<T>::first()
{
skip(0);
take(1);
typename TableType<T>::RowList list = toList(1);
RowList<T> list = toList(1);
if (list.count())
return list.first();

View File

@ -11,9 +11,9 @@ QueryBase::QueryBase(QObject *parent) : QObject(parent)
}
void QueryBase::addTableToSet(TableSetBase *set, Table *table)
{
set->add(table);
}
//void QueryBase::addTableToSet(TableSetBase *set, Table *table)
//{
// set->add(table);
//}
NUT_END_NAMESPACE

View File

@ -44,7 +44,7 @@ public:
explicit QueryBase(QObject *parent = 0);
protected:
void addTableToSet(TableSetBase *set, Table *table);
// void addTableToSet(TableSetBase *set, Table *table);
public slots:
};

View File

@ -75,7 +75,7 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
return QVariant("-");
if (role == Qt::DisplayRole) {
TableType<Table>::Row t = d->rows.at(index.row());
Row<Table> t = d->rows.at(index.row());
QVariant v = t->property(d->model->field(index.column())->name.toLocal8Bit().data());
// emit beforeShowText(index.column(), v);
if (_renderer != nullptr)
@ -102,7 +102,7 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
return QVariant();
}
void SqlModel::setRows(TableType<Table>::RowList rows)
void SqlModel::setRows(RowList<Table> rows)
{
Q_D(SqlModel);
beginRemoveRows(QModelIndex(), 0, d->rows.count());
@ -113,7 +113,7 @@ void SqlModel::setRows(TableType<Table>::RowList rows)
endInsertRows();
}
void SqlModel::append(TableType<Table>::Row table)
void SqlModel::append(Row<Table> table)
{
Q_D(SqlModel);
beginInsertRows(QModelIndex(), d->rows.count(), d->rows.count());

View File

@ -51,8 +51,8 @@ public:
template<class T>
void setTable(QList<QSharedPointer<T>> rows);
void setRows(TableType<Table>::RowList rows);
void append(TableType<Table>::Row table);
void setRows(RowList<Table> rows);
void append(Row<Table> table);
// void append(Table *table);
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Table *at(const int &i) const;
@ -72,7 +72,7 @@ Q_OUTOFLINE_TEMPLATE void SqlModel::setTable(QList<QSharedPointer<T> > rows)
{
Q_D(SqlModel);
TableType<Table>::RowList tab;
RowList<Table> tab;
foreach (auto t, rows)
tab.append(t);
setRows(tab);

View File

@ -18,7 +18,7 @@ public:
QString tableName;
TableType<Table>::RowList rows;
RowList<Table> rows;
TableModel *model;
};

View File

@ -1,9 +1,12 @@
DEFINES += NUT_SHARED_POINTER
HEADERS += \
$$PWD/generators/sqlgeneratorbase_p.h \
$$PWD/generators/postgresqlgenerator.h \
$$PWD/generators/mysqlgenerator.h \
$$PWD/generators/sqlitegenerator.h \
$$PWD/generators/sqlservergenerator.h \
$$PWD/tablesetbasedata.h \
$$PWD/types/dbgeography.h \
$$PWD/tableset.h \
$$PWD/defines_p.h \

View File

@ -32,6 +32,7 @@
#include "bulkinserter.h"
//#include "database.h"
#include "databasemodel.h"
#include "tablesetbasedata.h"
NUT_BEGIN_NAMESPACE
@ -47,8 +48,8 @@ public:
explicit TableSet(Database *parent);
explicit TableSet(Table *parent);
void append(T *t);
void append(QList<T *> t);
void append(Row<T> t);
void append(RowList<T> t);
void remove(T *t);
void remove(QList<T *> t);
@ -65,19 +66,19 @@ public:
template<class T>
Q_OUTOFLINE_TEMPLATE TableSet<T>::TableSet(Database *parent) : TableSetBase(parent)
{
_childClassName = T::staticMetaObject.className();
data->childClassName = T::staticMetaObject.className();
}
template<class T>
Q_OUTOFLINE_TEMPLATE TableSet<T>::TableSet(Table *parent) : TableSetBase(parent)
{
_childClassName = T::staticMetaObject.className();
data->childClassName = T::staticMetaObject.className();
}
template<class T>
Q_OUTOFLINE_TEMPLATE Query<T> *TableSet<T>::query(bool autoDelete)
{
Query<T> *q = new Query<T>(_database, this, autoDelete);
Query<T> *q = new Query<T>(data->database, this, autoDelete);
return q;
}
@ -85,34 +86,34 @@ Q_OUTOFLINE_TEMPLATE Query<T> *TableSet<T>::query(bool autoDelete)
template<class T>
Q_OUTOFLINE_TEMPLATE BulkInserter *TableSet<T>::bulkInserter()
{
BulkInserter *bi = new BulkInserter(_database, _childClassName);
BulkInserter *bi = new BulkInserter(data->database, data->childClassName);
return bi;
}
template<class T>
Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
{
return _tables.count();
return data->tables.count();
}
template<class T>
Q_OUTOFLINE_TEMPLATE T *TableSet<T >::at(int i) const
{
return reinterpret_cast<T*>(_childRows.at(i));
//TODO: check
return reinterpret_cast<T*>(data->childRows.at(i));
}
template<class T>
Q_OUTOFLINE_TEMPLATE const T &TableSet<T>::operator[](int i) const
{
return _childRows[i];
return data->childRows[i];
}
template<class T>
Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(T *t)
Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(Row<T> t)
{
_tables.insert(t);
_childRows.append(t);
data->tables.insert(t.data());
data->childRows.append(t.data());
// if (_database)
// t->setModel(_database->model().tableByClassName(t->metaObject()->className()));
@ -123,16 +124,16 @@ Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(T *t)
}
template<class T>
Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(QList<T *> t)
Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(RowList<T> t)
{
foreach (T* i, t)
foreach (Row<T> i, t)
append(i);
}
template<class T>
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(T *t)
{
_tables.remove(t);
data->tables.remove(t);
t->setStatus(Table::Deleted);
}

View File

@ -22,24 +22,25 @@
#include "database.h"
#include "tablesetbase_p.h"
#include "databasemodel.h"
#include "tablesetbasedata.h"
NUT_BEGIN_NAMESPACE
TableSetBase::TableSetBase(Database *parent) : QObject(parent),
_database(parent), _table(nullptr)//, _tableName(QString())
data(new TableSetBaseData(parent))
{
parent->add(this);
}
TableSetBase::TableSetBase(Table *parent) : QObject(parent),
_database(nullptr), _table(parent)//, _tableName(QString())
data(new TableSetBaseData(parent))
{
parent->add(this);
}
TableSetBase::~TableSetBase()
{
foreach (Table *t, _tables)
foreach (Table *t, data->tables)
t->setParentTableSet(nullptr);
}
@ -47,12 +48,13 @@ int TableSetBase::save(Database *db, bool cleanUp)
{
int rowsAffected = 0;
TableModel *masterModel = nullptr;
if (_table)
masterModel = db->model().tableByClassName(_table->metaObject()->className());
if (data->table)
masterModel = db->model().tableByClassName(data->table->metaObject()->className());
foreach (Table *t, _childRows) {
if(_table)
t->setParentTable(_table, masterModel,
foreach (Row<Table> t, data->childRows) {
if(data->table)
t->setParentTable(data->table,
masterModel,
db->model().tableByClassName(t->metaObject()->className()));
if(t->status() == Table::Added
@ -66,45 +68,47 @@ int TableSetBase::save(Database *db, bool cleanUp)
}
if (cleanUp)
_childRows.clear();
data->childRows.clear();
return rowsAffected;
}
void TableSetBase::clearChilds()
{
foreach (Table *t, _childRows)
#ifndef NUT_SHARED_POINTER
foreach (Table *t, data->_childRows)
t->deleteLater();
_childRows.clear();
#endif
data->childRows.clear();
}
void TableSetBase::add(Table *t)
void TableSetBase::add(Row<Table> t)
{
if(!_tables.contains(t)){
_tables.insert(t);
_childRows.append(t);
if(!data->tables.contains(t.data())){
data->tables.insert(t.data());
data->childRows.append(t);
}
}
void TableSetBase::remove(Table *t)
void TableSetBase::remove(Row<Table> t)
{
_tables.remove(t);
_childRows.removeOne(t);
data->tables.remove(t.data());
data->childRows.removeOne(t);
}
QString TableSetBase::childClassName() const
{
return _childClassName;
return data->childClassName;
}
Database *TableSetBase::database() const
{
return _database;
return data->database;
}
void TableSetBase::setDatabase(Database *database)
{
_database = database;
data->database = database;
}
NUT_END_NAMESPACE

View File

@ -24,6 +24,7 @@
#include <QtCore/QObject>
#include <QtCore/qglobal.h>
#include <QtCore/QSet>
#include <QExplicitlySharedDataPointer>
#include "defines.h"
@ -31,6 +32,7 @@ NUT_BEGIN_NAMESPACE
class Table;
class Database;
class TableSetBaseData;
class TableSetBase : public QObject
{
@ -47,16 +49,17 @@ public:
void setDatabase(Database *database);
protected:
QSet<Table*> _tables;
QList<Table*> _childRows;
Database *_database;
Table *_table;
// QString _tableName;
QString _childClassName;
// QSet<Table*> _tables;
// RowList<Table> _childRows;
// Database *_database;
// Table *_table;
//// QString _tableName;
// QString _childClassName;
QExplicitlySharedDataPointer<TableSetBaseData> data;
private:
void add(Table* t);
void remove(Table* t);
void add(Row<Table> t);
void remove(Row<Table> t);
friend class Table;
friend class QueryBase;

50
src/tablesetbasedata.h Normal file
View File

@ -0,0 +1,50 @@
/**************************************************************************
**
** This file is part of Nut project.
** https://github.com/HamedMasafi/Nut
**
** Nut is free software: you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Nut is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with Nut. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************/
#ifndef TABLESETBASEDATA_H
#define TABLESETBASEDATA_H
#include <QSharedData>
#include "defines.h"
NUT_BEGIN_NAMESPACE
class Table;
class Database;
class TableSetBaseData : public QSharedData
{
public:
TableSetBaseData(Database *parent) :
database(parent), table(nullptr)
{ }
TableSetBaseData(Table *parent) :
database(nullptr), table(parent)
{ }
QSet<Table*> tables;
QList<Table*> childRows;
Database *database;
Table *table;
QString childClassName;
};
NUT_END_NAMESPACE
#endif // TABLESETBASEDATA_H

View File

@ -11,7 +11,7 @@
.arg(timer.elapsed() / 1000.) \
.arg(__func__)
#define DRIVER "QPSQL"
#define DRIVER "QSQLITE"
#define DATABASE QString("nut_test_%1_db").arg(metaObject()->className()).toLower()
#define HOST "127.0.0.1"
#define USERNAME "postgres"

View File

@ -8,3 +8,5 @@ win32 {
LIBS += -L$$LIBDIR -lnut
INCLUDEPATH += $$PWD/../../src $$PWD/../common
#include(../../src/src.pri)
DEFINES += NUT_SHARED_POINTER

View File

@ -56,7 +56,7 @@ void BasicTest::dataScheema()
void BasicTest::createUser()
{
user = new User;
user = Nut::create<User>();
user->setUsername("admin");
user->setPassword("123456");
db.users()->append(user);
@ -66,7 +66,7 @@ void BasicTest::createUser()
void BasicTest::createPost()
{
TIC();
Post *newPost = new Post;
auto newPost = Nut::create<Post>();
newPost->setTitle("post title");
newPost->setSaveDate(QDateTime::currentDateTime());
newPost->setPublic(false);
@ -74,14 +74,14 @@ void BasicTest::createPost()
db.posts()->append(newPost);
for(int i = 0 ; i < 3; i++){
auto *comment = new Comment;
auto comment = Nut::create<Comment>();
comment->setMessage("comment #" + QString::number(i));
comment->setSaveDate(QDateTime::currentDateTime());
comment->setAuthorId(user->id());
newPost->comments()->append(comment);
}
for (int i = 0; i < 10; ++i) {
auto *score = new Score;
auto score = Nut::create<Score>();
score->setScore(i % 5);
newPost->scores()->append(score);
}
@ -106,7 +106,7 @@ void BasicTest::createPost2()
int postId = postIdVar.toInt();
for(int i = 0 ; i < 3; i++){
auto *comment = new Comment;
auto comment = Nut::create<Comment>();
comment->setMessage("comment #" + QString::number(i + 2));
comment->setSaveDate(QDateTime::currentDateTime());
comment->setAuthor(user);
@ -205,7 +205,7 @@ void BasicTest::testDate()
QTime t = QTime(d.time().hour(), d.time().minute(), d.time().second());
d.setTime(t);
Post *newPost = new Post;
auto newPost = Nut::create<Post>();
newPost->setTitle("post title");
newPost->setSaveDate(d);
@ -249,7 +249,7 @@ void BasicTest::modifyPost()
auto q = db.posts()->query();
q->setWhere(Post::idField() == postId);
Post *post = q->first();
Nut::Row<Post> post = q->first();
QTEST_ASSERT(post != nullptr);

View File

@ -12,8 +12,8 @@ class BasicTest : public QObject
Q_OBJECT
WeblogDatabase db;
int postId;
Post *post;
User *user;
Nut::Row<Post> post;
Nut::Row<User> user;
public:
explicit BasicTest(QObject *parent = nullptr);

View File

@ -45,7 +45,7 @@ void BenchmarkTest::insert1kPost()
t.start();
for (int i = 0; i < 100; ++i) {
Post *newPost = new Post;
auto newPost = Nut::create<Post>();
newPost->setTitle("post title");
newPost->setSaveDate(QDateTime::currentDateTime());

View File

@ -85,53 +85,54 @@ void DataTypesTest::initTestCase()
void DataTypesTest::insert()
{
SampleTable t;
t.setInt8(f_int8);
t.setInt16(f_int16);
t.setInt32(f_int32);
t.setInt64(f_int64);
auto t = Nut::create<SampleTable>();
t.setUint8(f_uint8);
t.setUint16(f_uint16);
t.setUint32(f_uint32);
t.setUint64(f_uint64);
t->setInt8(f_int8);
t->setInt16(f_int16);
t->setInt32(f_int32);
t->setInt64(f_int64);
t.setReal(f_real);
t.setFloat(f_float);
t->setUint8(f_uint8);
t->setUint16(f_uint16);
t->setUint32(f_uint32);
t->setUint64(f_uint64);
t.setUrl(f_url);
t->setReal(f_real);
t->setFloat(f_float);
t.setTime(f_time);
t.setDate(f_date);
t.setDateTime(f_dateTime);
t.setUuid(f_uuid);
t->setUrl(f_url);
t.setJsonDoc(f_jsonDoc);
t.setJsonObj(f_jsonObj);
t.setJsonArray(f_jsonArray);
t.setJsonValue(f_jsonValue);
t->setTime(f_time);
t->setDate(f_date);
t->setDateTime(f_dateTime);
t->setUuid(f_uuid);
t.setString(f_string);
t.setStringList(f_stringList);
t.setQchar(f_qchar);
t->setJsonDoc(f_jsonDoc);
t->setJsonObj(f_jsonObj);
t->setJsonArray(f_jsonArray);
t->setJsonValue(f_jsonValue);
t->setString(f_string);
t->setStringList(f_stringList);
t->setQchar(f_qchar);
#ifdef QT_GUI_LIB
t.setColor(f_color);
t->setColor(f_color);
t.setPoint(f_point);
t.setPointf(f_pointf);
t->setPoint(f_point);
t->setPointf(f_pointf);
t.setPolygon(f_polygon);
t.setPolygonf(f_polygonf);
t->setPolygon(f_polygon);
t->setPolygonf(f_polygonf);
#endif
db.sampleTables()->append(&t);
db.sampleTables()->append(t);
db.saveChanges();
}
void DataTypesTest::retrive()
{
QList<SampleTable*> list = db.sampleTables()->query()->toList();
Nut::RowList<SampleTable> list = db.sampleTables()->query()->toList();
QTEST_ASSERT(list.count() == 1);
SampleTable *t = list.first();
Nut::Row<SampleTable> t = list.first();
QTEST_ASSERT(t->f_int8() == f_int8);
QTEST_ASSERT(t->f_int16() == f_int16);

View File

@ -39,7 +39,7 @@ void TestJson::store()
db.open();
Table *t = new Table;
auto t = Nut::create<Table>();
QJsonParseError e;
QJsonDocument doc = QJsonDocument::fromJson(R"({"a": 4, "b":3.14})", &e);
qDebug() << e.errorString();

View File

@ -41,10 +41,10 @@ void UuidTest::initTestCase()
void UuidTest::save()
{
TIC();
Test t;
t.setId(QUuid::createUuid());
t.setUuid(uuid);
db.tests()->append(&t);
auto t = Nut::create<Test>();
t->setId(QUuid::createUuid());
t->setUuid(uuid);
db.tests()->append(t);
int n = db.saveChanges();
TOC();

View File

@ -58,11 +58,11 @@ void Upgrades::version2()
initDb(db);
QTEST_ASSERT(db.open());
Table2 t;
t.setStr("0");
db.sampleTable()->append(&t);
auto t = Nut::create<Table2>();
t->setStr("0");
db.sampleTable()->append(t);
db.saveChanges();
id = t.id();
id = t->id();
}
void Upgrades::version3()