working :-( [skip ci]
This commit is contained in:
parent
e946a54753
commit
5e5471fdeb
1
nut.pri
1
nut.pri
|
|
@ -3,6 +3,7 @@ QT += core sql
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/include
|
INCLUDEPATH += $$PWD/include
|
||||||
|
DEFINES += NUT_SHARED_POINTER
|
||||||
include(3rdparty/serializer/src/src.pri)
|
include(3rdparty/serializer/src/src.pri)
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,7 @@ bool DatabasePrivate::getCurrectScheema()
|
||||||
|
|
||||||
DatabaseModel DatabasePrivate::getLastScheema()
|
DatabaseModel DatabasePrivate::getLastScheema()
|
||||||
{
|
{
|
||||||
typename TableType<ChangeLogTable>::Row u = changeLogs->query()
|
Row<ChangeLogTable> u = changeLogs->query()
|
||||||
->orderBy(!ChangeLogTable::idField())
|
->orderBy(!ChangeLogTable::idField())
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
|
@ -321,7 +321,7 @@ bool DatabasePrivate::putModelToDatabase()
|
||||||
DatabaseModel current = currentModel;
|
DatabaseModel current = currentModel;
|
||||||
/*current.remove(__CHANGE_LOG_TABLE_NAME)*/;
|
/*current.remove(__CHANGE_LOG_TABLE_NAME)*/;
|
||||||
|
|
||||||
auto *changeLog = new ChangeLogTable();
|
auto changeLog = create<ChangeLogTable>();
|
||||||
changeLog->setData(QJsonDocument(current.toJson()).toJson(QJsonDocument::Compact));
|
changeLog->setData(QJsonDocument(current.toJson()).toJson(QJsonDocument::Compact));
|
||||||
changeLog->setVersion(current.version());
|
changeLog->setVersion(current.version());
|
||||||
changeLogs->append(changeLog);
|
changeLogs->append(changeLog);
|
||||||
|
|
|
||||||
201
src/defines.h
201
src/defines.h
|
|
@ -45,6 +45,83 @@
|
||||||
Q_CLASSINFO(__nut_NAME_PERFIX type #name #value, \
|
Q_CLASSINFO(__nut_NAME_PERFIX type #name #value, \
|
||||||
type "\n" #name "\n" 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,
|
inline bool nutClassInfo(const QMetaClassInfo &classInfo,
|
||||||
QString &type, QString &name, QVariant &value)
|
QString &type, QString &name, QVariant &value)
|
||||||
{
|
{
|
||||||
|
|
@ -117,107 +194,37 @@ inline bool nutClassInfoInt(const QMetaClassInfo &classInfo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NUT_FIELD_PERFIX
|
#ifdef NUT_SHARED_POINTER
|
||||||
#define NUT_FIELD_POSTFIX Field
|
template <class T>
|
||||||
|
using RowList = QList<QSharedPointer<T>>;
|
||||||
// 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)
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
struct TableType
|
using RowSet = QSet<QSharedPointer<T>>;
|
||||||
{
|
|
||||||
#ifdef NUT_SHARED_POINTER
|
template <typename T>
|
||||||
typedef QList<QSharedPointer<T>> RowList;
|
using Row = QSharedPointer<T>;
|
||||||
typedef QSet<QSharedPointer<T>> RowSet;
|
|
||||||
typedef QSharedPointer<T> Row;
|
template<class T>
|
||||||
|
inline Row<T> create() {
|
||||||
|
return QSharedPointer<T>(new T);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
typedef QList<T*> RowList;
|
template <typename T>
|
||||||
typedef QSet<T*> RowSet;
|
using RowList = QList<T*>;
|
||||||
typedef T* Row;
|
|
||||||
|
template <typename T>
|
||||||
|
using RowSet = QSet<T*>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using Row = T*;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline Row<T> create() {
|
||||||
|
return new T;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
};
|
|
||||||
|
|
||||||
//#ifdef NUT_SHARED_POINTER
|
NUT_END_NAMESPACE
|
||||||
// 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
|
|
||||||
|
|
||||||
#endif // SYNTAX_DEFINES_H
|
#endif // SYNTAX_DEFINES_H
|
||||||
|
|
|
||||||
12
src/query.h
12
src/query.h
|
|
@ -89,8 +89,8 @@ public:
|
||||||
Query<T> *setWhere(const ConditionalPhrase &ph);
|
Query<T> *setWhere(const ConditionalPhrase &ph);
|
||||||
|
|
||||||
//data selecting
|
//data selecting
|
||||||
typename TableType<T>::Row first();
|
Row<T> first();
|
||||||
typename TableType<T>::RowList toList(int count = -1);
|
RowList<T> toList(int count = -1);
|
||||||
template <typename F>
|
template <typename F>
|
||||||
QList<F> select(const FieldPhrase<F> f);
|
QList<F> select(const FieldPhrase<F> f);
|
||||||
|
|
||||||
|
|
@ -175,11 +175,11 @@ Q_OUTOFLINE_TEMPLATE Query<T>::~Query()
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
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_UNUSED(count);
|
||||||
Q_D(Query);
|
Q_D(Query);
|
||||||
typename TableType<T>::RowList returnList;
|
RowList<T> returnList;
|
||||||
d->select = "*";
|
d->select = "*";
|
||||||
|
|
||||||
d->sql = d->database->sqlGenertor()->selectCommand(
|
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>
|
template <class T>
|
||||||
Q_OUTOFLINE_TEMPLATE typename TableType<T>::Row Query<T>::first()
|
Q_OUTOFLINE_TEMPLATE Row<T> Query<T>::first()
|
||||||
{
|
{
|
||||||
skip(0);
|
skip(0);
|
||||||
take(1);
|
take(1);
|
||||||
typename TableType<T>::RowList list = toList(1);
|
RowList<T> list = toList(1);
|
||||||
|
|
||||||
if (list.count())
|
if (list.count())
|
||||||
return list.first();
|
return list.first();
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ QueryBase::QueryBase(QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryBase::addTableToSet(TableSetBase *set, Table *table)
|
//void QueryBase::addTableToSet(TableSetBase *set, Table *table)
|
||||||
{
|
//{
|
||||||
set->add(table);
|
// set->add(table);
|
||||||
}
|
//}
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ public:
|
||||||
explicit QueryBase(QObject *parent = 0);
|
explicit QueryBase(QObject *parent = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addTableToSet(TableSetBase *set, Table *table);
|
// void addTableToSet(TableSetBase *set, Table *table);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
|
||||||
return QVariant("-");
|
return QVariant("-");
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
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());
|
QVariant v = t->property(d->model->field(index.column())->name.toLocal8Bit().data());
|
||||||
// emit beforeShowText(index.column(), v);
|
// emit beforeShowText(index.column(), v);
|
||||||
if (_renderer != nullptr)
|
if (_renderer != nullptr)
|
||||||
|
|
@ -102,7 +102,7 @@ QVariant SqlModel::data(const QModelIndex &index, int role) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlModel::setRows(TableType<Table>::RowList rows)
|
void SqlModel::setRows(RowList<Table> rows)
|
||||||
{
|
{
|
||||||
Q_D(SqlModel);
|
Q_D(SqlModel);
|
||||||
beginRemoveRows(QModelIndex(), 0, d->rows.count());
|
beginRemoveRows(QModelIndex(), 0, d->rows.count());
|
||||||
|
|
@ -113,7 +113,7 @@ void SqlModel::setRows(TableType<Table>::RowList rows)
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SqlModel::append(TableType<Table>::Row table)
|
void SqlModel::append(Row<Table> table)
|
||||||
{
|
{
|
||||||
Q_D(SqlModel);
|
Q_D(SqlModel);
|
||||||
beginInsertRows(QModelIndex(), d->rows.count(), d->rows.count());
|
beginInsertRows(QModelIndex(), d->rows.count(), d->rows.count());
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ public:
|
||||||
template<class T>
|
template<class T>
|
||||||
void setTable(QList<QSharedPointer<T>> rows);
|
void setTable(QList<QSharedPointer<T>> rows);
|
||||||
|
|
||||||
void setRows(TableType<Table>::RowList rows);
|
void setRows(RowList<Table> rows);
|
||||||
void append(TableType<Table>::Row table);
|
void append(Row<Table> table);
|
||||||
// void append(Table *table);
|
// void append(Table *table);
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
Table *at(const int &i) const;
|
Table *at(const int &i) const;
|
||||||
|
|
@ -72,7 +72,7 @@ Q_OUTOFLINE_TEMPLATE void SqlModel::setTable(QList<QSharedPointer<T> > rows)
|
||||||
{
|
{
|
||||||
Q_D(SqlModel);
|
Q_D(SqlModel);
|
||||||
|
|
||||||
TableType<Table>::RowList tab;
|
RowList<Table> tab;
|
||||||
foreach (auto t, rows)
|
foreach (auto t, rows)
|
||||||
tab.append(t);
|
tab.append(t);
|
||||||
setRows(tab);
|
setRows(tab);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ public:
|
||||||
|
|
||||||
QString tableName;
|
QString tableName;
|
||||||
|
|
||||||
TableType<Table>::RowList rows;
|
RowList<Table> rows;
|
||||||
TableModel *model;
|
TableModel *model;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
|
DEFINES += NUT_SHARED_POINTER
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/generators/sqlgeneratorbase_p.h \
|
$$PWD/generators/sqlgeneratorbase_p.h \
|
||||||
$$PWD/generators/postgresqlgenerator.h \
|
$$PWD/generators/postgresqlgenerator.h \
|
||||||
$$PWD/generators/mysqlgenerator.h \
|
$$PWD/generators/mysqlgenerator.h \
|
||||||
$$PWD/generators/sqlitegenerator.h \
|
$$PWD/generators/sqlitegenerator.h \
|
||||||
$$PWD/generators/sqlservergenerator.h \
|
$$PWD/generators/sqlservergenerator.h \
|
||||||
|
$$PWD/tablesetbasedata.h \
|
||||||
$$PWD/types/dbgeography.h \
|
$$PWD/types/dbgeography.h \
|
||||||
$$PWD/tableset.h \
|
$$PWD/tableset.h \
|
||||||
$$PWD/defines_p.h \
|
$$PWD/defines_p.h \
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
#include "bulkinserter.h"
|
#include "bulkinserter.h"
|
||||||
//#include "database.h"
|
//#include "database.h"
|
||||||
#include "databasemodel.h"
|
#include "databasemodel.h"
|
||||||
|
#include "tablesetbasedata.h"
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
|
@ -47,8 +48,8 @@ public:
|
||||||
explicit TableSet(Database *parent);
|
explicit TableSet(Database *parent);
|
||||||
explicit TableSet(Table *parent);
|
explicit TableSet(Table *parent);
|
||||||
|
|
||||||
void append(T *t);
|
void append(Row<T> t);
|
||||||
void append(QList<T *> t);
|
void append(RowList<T> t);
|
||||||
void remove(T *t);
|
void remove(T *t);
|
||||||
void remove(QList<T *> t);
|
void remove(QList<T *> t);
|
||||||
|
|
||||||
|
|
@ -65,19 +66,19 @@ public:
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE TableSet<T>::TableSet(Database *parent) : TableSetBase(parent)
|
Q_OUTOFLINE_TEMPLATE TableSet<T>::TableSet(Database *parent) : TableSetBase(parent)
|
||||||
{
|
{
|
||||||
_childClassName = T::staticMetaObject.className();
|
data->childClassName = T::staticMetaObject.className();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE TableSet<T>::TableSet(Table *parent) : TableSetBase(parent)
|
Q_OUTOFLINE_TEMPLATE TableSet<T>::TableSet(Table *parent) : TableSetBase(parent)
|
||||||
{
|
{
|
||||||
_childClassName = T::staticMetaObject.className();
|
data->childClassName = T::staticMetaObject.className();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE Query<T> *TableSet<T>::query(bool autoDelete)
|
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;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
@ -85,34 +86,34 @@ Q_OUTOFLINE_TEMPLATE Query<T> *TableSet<T>::query(bool autoDelete)
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE BulkInserter *TableSet<T>::bulkInserter()
|
Q_OUTOFLINE_TEMPLATE BulkInserter *TableSet<T>::bulkInserter()
|
||||||
{
|
{
|
||||||
BulkInserter *bi = new BulkInserter(_database, _childClassName);
|
BulkInserter *bi = new BulkInserter(data->database, data->childClassName);
|
||||||
return bi;
|
return bi;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
|
Q_OUTOFLINE_TEMPLATE int TableSet<T>::length() const
|
||||||
{
|
{
|
||||||
return _tables.count();
|
return data->tables.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE T *TableSet<T >::at(int i) const
|
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>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE const T &TableSet<T>::operator[](int i) const
|
Q_OUTOFLINE_TEMPLATE const T &TableSet<T>::operator[](int i) const
|
||||||
{
|
{
|
||||||
return _childRows[i];
|
return data->childRows[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
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);
|
data->tables.insert(t.data());
|
||||||
_childRows.append(t);
|
data->childRows.append(t.data());
|
||||||
|
|
||||||
// if (_database)
|
// if (_database)
|
||||||
// t->setModel(_database->model().tableByClassName(t->metaObject()->className()));
|
// t->setModel(_database->model().tableByClassName(t->metaObject()->className()));
|
||||||
|
|
@ -123,16 +124,16 @@ Q_OUTOFLINE_TEMPLATE void TableSet<T>::append(T *t)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class 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);
|
append(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(T *t)
|
Q_OUTOFLINE_TEMPLATE void TableSet<T>::remove(T *t)
|
||||||
{
|
{
|
||||||
_tables.remove(t);
|
data->tables.remove(t);
|
||||||
t->setStatus(Table::Deleted);
|
t->setStatus(Table::Deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,24 +22,25 @@
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "tablesetbase_p.h"
|
#include "tablesetbase_p.h"
|
||||||
#include "databasemodel.h"
|
#include "databasemodel.h"
|
||||||
|
#include "tablesetbasedata.h"
|
||||||
|
|
||||||
NUT_BEGIN_NAMESPACE
|
NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
TableSetBase::TableSetBase(Database *parent) : QObject(parent),
|
TableSetBase::TableSetBase(Database *parent) : QObject(parent),
|
||||||
_database(parent), _table(nullptr)//, _tableName(QString())
|
data(new TableSetBaseData(parent))
|
||||||
{
|
{
|
||||||
parent->add(this);
|
parent->add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TableSetBase::TableSetBase(Table *parent) : QObject(parent),
|
TableSetBase::TableSetBase(Table *parent) : QObject(parent),
|
||||||
_database(nullptr), _table(parent)//, _tableName(QString())
|
data(new TableSetBaseData(parent))
|
||||||
{
|
{
|
||||||
parent->add(this);
|
parent->add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TableSetBase::~TableSetBase()
|
TableSetBase::~TableSetBase()
|
||||||
{
|
{
|
||||||
foreach (Table *t, _tables)
|
foreach (Table *t, data->tables)
|
||||||
t->setParentTableSet(nullptr);
|
t->setParentTableSet(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,12 +48,13 @@ int TableSetBase::save(Database *db, bool cleanUp)
|
||||||
{
|
{
|
||||||
int rowsAffected = 0;
|
int rowsAffected = 0;
|
||||||
TableModel *masterModel = nullptr;
|
TableModel *masterModel = nullptr;
|
||||||
if (_table)
|
if (data->table)
|
||||||
masterModel = db->model().tableByClassName(_table->metaObject()->className());
|
masterModel = db->model().tableByClassName(data->table->metaObject()->className());
|
||||||
|
|
||||||
foreach (Table *t, _childRows) {
|
foreach (Row<Table> t, data->childRows) {
|
||||||
if(_table)
|
if(data->table)
|
||||||
t->setParentTable(_table, masterModel,
|
t->setParentTable(data->table,
|
||||||
|
masterModel,
|
||||||
db->model().tableByClassName(t->metaObject()->className()));
|
db->model().tableByClassName(t->metaObject()->className()));
|
||||||
|
|
||||||
if(t->status() == Table::Added
|
if(t->status() == Table::Added
|
||||||
|
|
@ -66,45 +68,47 @@ int TableSetBase::save(Database *db, bool cleanUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cleanUp)
|
if (cleanUp)
|
||||||
_childRows.clear();
|
data->childRows.clear();
|
||||||
|
|
||||||
return rowsAffected;
|
return rowsAffected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::clearChilds()
|
void TableSetBase::clearChilds()
|
||||||
{
|
{
|
||||||
foreach (Table *t, _childRows)
|
#ifndef NUT_SHARED_POINTER
|
||||||
|
foreach (Table *t, data->_childRows)
|
||||||
t->deleteLater();
|
t->deleteLater();
|
||||||
_childRows.clear();
|
#endif
|
||||||
|
data->childRows.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::add(Table *t)
|
void TableSetBase::add(Row<Table> t)
|
||||||
{
|
{
|
||||||
if(!_tables.contains(t)){
|
if(!data->tables.contains(t.data())){
|
||||||
_tables.insert(t);
|
data->tables.insert(t.data());
|
||||||
_childRows.append(t);
|
data->childRows.append(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::remove(Table *t)
|
void TableSetBase::remove(Row<Table> t)
|
||||||
{
|
{
|
||||||
_tables.remove(t);
|
data->tables.remove(t.data());
|
||||||
_childRows.removeOne(t);
|
data->childRows.removeOne(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TableSetBase::childClassName() const
|
QString TableSetBase::childClassName() const
|
||||||
{
|
{
|
||||||
return _childClassName;
|
return data->childClassName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Database *TableSetBase::database() const
|
Database *TableSetBase::database() const
|
||||||
{
|
{
|
||||||
return _database;
|
return data->database;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSetBase::setDatabase(Database *database)
|
void TableSetBase::setDatabase(Database *database)
|
||||||
{
|
{
|
||||||
_database = database;
|
data->database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
NUT_END_NAMESPACE
|
NUT_END_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
#include <QtCore/QSet>
|
#include <QtCore/QSet>
|
||||||
|
#include <QExplicitlySharedDataPointer>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
|
|
||||||
|
|
@ -31,6 +32,7 @@ NUT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class Table;
|
class Table;
|
||||||
class Database;
|
class Database;
|
||||||
|
class TableSetBaseData;
|
||||||
class TableSetBase : public QObject
|
class TableSetBase : public QObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -47,16 +49,17 @@ public:
|
||||||
void setDatabase(Database *database);
|
void setDatabase(Database *database);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSet<Table*> _tables;
|
// QSet<Table*> _tables;
|
||||||
QList<Table*> _childRows;
|
// RowList<Table> _childRows;
|
||||||
Database *_database;
|
// Database *_database;
|
||||||
Table *_table;
|
// Table *_table;
|
||||||
// QString _tableName;
|
//// QString _tableName;
|
||||||
QString _childClassName;
|
// QString _childClassName;
|
||||||
|
QExplicitlySharedDataPointer<TableSetBaseData> data;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void add(Table* t);
|
void add(Row<Table> t);
|
||||||
void remove(Table* t);
|
void remove(Row<Table> t);
|
||||||
|
|
||||||
friend class Table;
|
friend class Table;
|
||||||
friend class QueryBase;
|
friend class QueryBase;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
.arg(timer.elapsed() / 1000.) \
|
.arg(timer.elapsed() / 1000.) \
|
||||||
.arg(__func__)
|
.arg(__func__)
|
||||||
|
|
||||||
#define DRIVER "QPSQL"
|
#define DRIVER "QSQLITE"
|
||||||
#define DATABASE QString("nut_test_%1_db").arg(metaObject()->className()).toLower()
|
#define DATABASE QString("nut_test_%1_db").arg(metaObject()->className()).toLower()
|
||||||
#define HOST "127.0.0.1"
|
#define HOST "127.0.0.1"
|
||||||
#define USERNAME "postgres"
|
#define USERNAME "postgres"
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,5 @@ win32 {
|
||||||
LIBS += -L$$LIBDIR -lnut
|
LIBS += -L$$LIBDIR -lnut
|
||||||
INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
INCLUDEPATH += $$PWD/../../src $$PWD/../common
|
||||||
#include(../../src/src.pri)
|
#include(../../src/src.pri)
|
||||||
|
|
||||||
|
DEFINES += NUT_SHARED_POINTER
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ void BasicTest::dataScheema()
|
||||||
|
|
||||||
void BasicTest::createUser()
|
void BasicTest::createUser()
|
||||||
{
|
{
|
||||||
user = new User;
|
user = Nut::create<User>();
|
||||||
user->setUsername("admin");
|
user->setUsername("admin");
|
||||||
user->setPassword("123456");
|
user->setPassword("123456");
|
||||||
db.users()->append(user);
|
db.users()->append(user);
|
||||||
|
|
@ -66,7 +66,7 @@ void BasicTest::createUser()
|
||||||
void BasicTest::createPost()
|
void BasicTest::createPost()
|
||||||
{
|
{
|
||||||
TIC();
|
TIC();
|
||||||
Post *newPost = new Post;
|
auto newPost = Nut::create<Post>();
|
||||||
newPost->setTitle("post title");
|
newPost->setTitle("post title");
|
||||||
newPost->setSaveDate(QDateTime::currentDateTime());
|
newPost->setSaveDate(QDateTime::currentDateTime());
|
||||||
newPost->setPublic(false);
|
newPost->setPublic(false);
|
||||||
|
|
@ -74,14 +74,14 @@ void BasicTest::createPost()
|
||||||
db.posts()->append(newPost);
|
db.posts()->append(newPost);
|
||||||
|
|
||||||
for(int i = 0 ; i < 3; i++){
|
for(int i = 0 ; i < 3; i++){
|
||||||
auto *comment = new Comment;
|
auto comment = Nut::create<Comment>();
|
||||||
comment->setMessage("comment #" + QString::number(i));
|
comment->setMessage("comment #" + QString::number(i));
|
||||||
comment->setSaveDate(QDateTime::currentDateTime());
|
comment->setSaveDate(QDateTime::currentDateTime());
|
||||||
comment->setAuthorId(user->id());
|
comment->setAuthorId(user->id());
|
||||||
newPost->comments()->append(comment);
|
newPost->comments()->append(comment);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
auto *score = new Score;
|
auto score = Nut::create<Score>();
|
||||||
score->setScore(i % 5);
|
score->setScore(i % 5);
|
||||||
newPost->scores()->append(score);
|
newPost->scores()->append(score);
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ void BasicTest::createPost2()
|
||||||
int postId = postIdVar.toInt();
|
int postId = postIdVar.toInt();
|
||||||
|
|
||||||
for(int i = 0 ; i < 3; i++){
|
for(int i = 0 ; i < 3; i++){
|
||||||
auto *comment = new Comment;
|
auto comment = Nut::create<Comment>();
|
||||||
comment->setMessage("comment #" + QString::number(i + 2));
|
comment->setMessage("comment #" + QString::number(i + 2));
|
||||||
comment->setSaveDate(QDateTime::currentDateTime());
|
comment->setSaveDate(QDateTime::currentDateTime());
|
||||||
comment->setAuthor(user);
|
comment->setAuthor(user);
|
||||||
|
|
@ -205,7 +205,7 @@ void BasicTest::testDate()
|
||||||
QTime t = QTime(d.time().hour(), d.time().minute(), d.time().second());
|
QTime t = QTime(d.time().hour(), d.time().minute(), d.time().second());
|
||||||
d.setTime(t);
|
d.setTime(t);
|
||||||
|
|
||||||
Post *newPost = new Post;
|
auto newPost = Nut::create<Post>();
|
||||||
newPost->setTitle("post title");
|
newPost->setTitle("post title");
|
||||||
newPost->setSaveDate(d);
|
newPost->setSaveDate(d);
|
||||||
|
|
||||||
|
|
@ -249,7 +249,7 @@ void BasicTest::modifyPost()
|
||||||
auto q = db.posts()->query();
|
auto q = db.posts()->query();
|
||||||
q->setWhere(Post::idField() == postId);
|
q->setWhere(Post::idField() == postId);
|
||||||
|
|
||||||
Post *post = q->first();
|
Nut::Row<Post> post = q->first();
|
||||||
|
|
||||||
QTEST_ASSERT(post != nullptr);
|
QTEST_ASSERT(post != nullptr);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ class BasicTest : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
WeblogDatabase db;
|
WeblogDatabase db;
|
||||||
int postId;
|
int postId;
|
||||||
Post *post;
|
Nut::Row<Post> post;
|
||||||
User *user;
|
Nut::Row<User> user;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BasicTest(QObject *parent = nullptr);
|
explicit BasicTest(QObject *parent = nullptr);
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ void BenchmarkTest::insert1kPost()
|
||||||
t.start();
|
t.start();
|
||||||
|
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
Post *newPost = new Post;
|
auto newPost = Nut::create<Post>();
|
||||||
newPost->setTitle("post title");
|
newPost->setTitle("post title");
|
||||||
newPost->setSaveDate(QDateTime::currentDateTime());
|
newPost->setSaveDate(QDateTime::currentDateTime());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,53 +85,54 @@ void DataTypesTest::initTestCase()
|
||||||
|
|
||||||
void DataTypesTest::insert()
|
void DataTypesTest::insert()
|
||||||
{
|
{
|
||||||
SampleTable t;
|
auto t = Nut::create<SampleTable>();
|
||||||
t.setInt8(f_int8);
|
|
||||||
t.setInt16(f_int16);
|
|
||||||
t.setInt32(f_int32);
|
|
||||||
t.setInt64(f_int64);
|
|
||||||
|
|
||||||
t.setUint8(f_uint8);
|
t->setInt8(f_int8);
|
||||||
t.setUint16(f_uint16);
|
t->setInt16(f_int16);
|
||||||
t.setUint32(f_uint32);
|
t->setInt32(f_int32);
|
||||||
t.setUint64(f_uint64);
|
t->setInt64(f_int64);
|
||||||
|
|
||||||
t.setReal(f_real);
|
t->setUint8(f_uint8);
|
||||||
t.setFloat(f_float);
|
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->setUrl(f_url);
|
||||||
t.setDate(f_date);
|
|
||||||
t.setDateTime(f_dateTime);
|
|
||||||
t.setUuid(f_uuid);
|
|
||||||
|
|
||||||
t.setJsonDoc(f_jsonDoc);
|
t->setTime(f_time);
|
||||||
t.setJsonObj(f_jsonObj);
|
t->setDate(f_date);
|
||||||
t.setJsonArray(f_jsonArray);
|
t->setDateTime(f_dateTime);
|
||||||
t.setJsonValue(f_jsonValue);
|
t->setUuid(f_uuid);
|
||||||
|
|
||||||
t.setString(f_string);
|
t->setJsonDoc(f_jsonDoc);
|
||||||
t.setStringList(f_stringList);
|
t->setJsonObj(f_jsonObj);
|
||||||
t.setQchar(f_qchar);
|
t->setJsonArray(f_jsonArray);
|
||||||
|
t->setJsonValue(f_jsonValue);
|
||||||
|
|
||||||
|
t->setString(f_string);
|
||||||
|
t->setStringList(f_stringList);
|
||||||
|
t->setQchar(f_qchar);
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
t.setColor(f_color);
|
t->setColor(f_color);
|
||||||
|
|
||||||
t.setPoint(f_point);
|
t->setPoint(f_point);
|
||||||
t.setPointf(f_pointf);
|
t->setPointf(f_pointf);
|
||||||
|
|
||||||
t.setPolygon(f_polygon);
|
t->setPolygon(f_polygon);
|
||||||
t.setPolygonf(f_polygonf);
|
t->setPolygonf(f_polygonf);
|
||||||
#endif
|
#endif
|
||||||
db.sampleTables()->append(&t);
|
db.sampleTables()->append(t);
|
||||||
db.saveChanges();
|
db.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataTypesTest::retrive()
|
void DataTypesTest::retrive()
|
||||||
{
|
{
|
||||||
QList<SampleTable*> list = db.sampleTables()->query()->toList();
|
Nut::RowList<SampleTable> list = db.sampleTables()->query()->toList();
|
||||||
QTEST_ASSERT(list.count() == 1);
|
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_int8() == f_int8);
|
||||||
QTEST_ASSERT(t->f_int16() == f_int16);
|
QTEST_ASSERT(t->f_int16() == f_int16);
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ void TestJson::store()
|
||||||
|
|
||||||
db.open();
|
db.open();
|
||||||
|
|
||||||
Table *t = new Table;
|
auto t = Nut::create<Table>();
|
||||||
QJsonParseError e;
|
QJsonParseError e;
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(R"({"a": 4, "b":3.14})", &e);
|
QJsonDocument doc = QJsonDocument::fromJson(R"({"a": 4, "b":3.14})", &e);
|
||||||
qDebug() << e.errorString();
|
qDebug() << e.errorString();
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,10 @@ void UuidTest::initTestCase()
|
||||||
void UuidTest::save()
|
void UuidTest::save()
|
||||||
{
|
{
|
||||||
TIC();
|
TIC();
|
||||||
Test t;
|
auto t = Nut::create<Test>();
|
||||||
t.setId(QUuid::createUuid());
|
t->setId(QUuid::createUuid());
|
||||||
t.setUuid(uuid);
|
t->setUuid(uuid);
|
||||||
db.tests()->append(&t);
|
db.tests()->append(t);
|
||||||
int n = db.saveChanges();
|
int n = db.saveChanges();
|
||||||
TOC();
|
TOC();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,11 @@ void Upgrades::version2()
|
||||||
initDb(db);
|
initDb(db);
|
||||||
QTEST_ASSERT(db.open());
|
QTEST_ASSERT(db.open());
|
||||||
|
|
||||||
Table2 t;
|
auto t = Nut::create<Table2>();
|
||||||
t.setStr("0");
|
t->setStr("0");
|
||||||
db.sampleTable()->append(&t);
|
db.sampleTable()->append(t);
|
||||||
db.saveChanges();
|
db.saveChanges();
|
||||||
id = t.id();
|
id = t->id();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Upgrades::version3()
|
void Upgrades::version3()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue