Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
dbobjectsrequest.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#ifndef DBOBJECTSREQUEST_H
9#define DBOBJECTSREQUEST_H
10
11#include "dbobjectset.h"
12
13#include <QDataStream>
14
15
16namespace QH {
17namespace PKG {
18
32template <class T>
33class DBObjectsRequest final: public DBObjectSet
34{
35public:
36
42 fromBytes(pkkg.toBytes());
43 }
44
53 DBObjectsRequest(const QString& table,
54 const QString& conditions = "",
55 const QVariantMap& valuesToBind = {}):
57
58 _conditions = conditions;
59 _condirionValues = valuesToBind;
60 };
61
62 void clear() override {
63 _data.clear();
64 };
65
66 bool fromSqlRecord(const QSqlRecord &q) override {
67 auto ptr = QSharedPointer<T>::create();
68
69 if (!ptr->fromSqlRecord(q)) {
70 clear();
71 return false;
72 }
73
74 _data.push_back(ptr);
75
76 return true;
77 };
78
79 QDataStream &fromStream(QDataStream &stream) override {
80 return stream;
81 };
82
83 QDataStream &toStream(QDataStream &stream) const override {
84 return stream;
85 };
86
87 bool isValid() const override {
88 return true;
89 };
90
95 const QList<QSharedPointer<T>> & data() const {
96 return _data;
97 };
98
99 DBVariantMap variantMap() const override {
100 return T{}.variantMap();
101 };
102
107 void setConditions(const QString &newConditions) {
108 _conditions = newConditions;
109 }
110
111protected:
112
113 std::pair<QString, QMap<QString, QVariant> > condition() const override {
114 return {_conditions, _condirionValues};
115 }
116
117 DBObject *createDBObject() const override {
118 return create<DBObjectsRequest<T>>(table(), _conditions);
119 };
120
121 QList<QSharedPointer<T>> _data;
122
123private:
124 QString _conditions;
125 QVariantMap _condirionValues;
126
127
128};
129
130}
131}
132#endif // DBOBJECTSREQUEST_H
The DBObjectSet class add features for control database object arrays. You will be able be get or rem...
Definition dbobjectset.h:24
QString table() const override
table This method should be return name of the database table that should be contains objects with th...
The DBObject class- main class for work with data base.
Definition dbobject.h:94
The DBObjectsRequest class is template class for get array of TEMPLATE Objects from database.
DBObject * createDBObject() const override
createDBObject This method should be create a object with the some type as the object called this met...
void clear() override
clear This method clear all data of database object. Override This method for remove or reset your ow...
DBObjectsRequest(const Package &pkkg)
DBObjectsRequest This is default constructor for parsing packages.
QDataStream & toStream(QDataStream &stream) const override
fromStream This method should be write all members of the current object to the stream object.
const QList< QSharedPointer< T > > & data() const
data This method return a list of getted objects.
DBVariantMap variantMap() const override
variantMap This method should be create a DBVariantMap implementation of this database object.
void setConditions(const QString &newConditions)
setConditions This method sets condition value for request.
QList< QSharedPointer< T > > _data
bool isValid() const override
isValid This method check current object to valid.
std::pair< QString, QMap< QString, QVariant > > condition() const override
condition This method must to return a condition of the WHERE block of the sql query....
QDataStream & fromStream(QDataStream &stream) override
fromStream This method should be read all bytes from the stream object and full the current object.
bool fromSqlRecord(const QSqlRecord &q) override
fromSqlRecord This method should be initialize this object from the executed sqlRecord....
DBObjectsRequest(const QString &table, const QString &conditions="", const QVariantMap &valuesToBind={})
DBObjectsRequest This contsrucor create a object with request the array of T objects.
The Package struct. This is base structure for transporting data by network between QH nodes....
Definition package.h:23
bool fromBytes(const QByteArray &data)
fromBytes This method provide initialization of object from byte array.
QByteArray toBytes() const
toBytes This method convert a current object to bytes array.
QMap< QString, DBVariant > DBVariantMap
DBVariantMap this is Map with key, and value with data type.
Definition dbobject.h:84
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13