Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
dbobject.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 DBOBJECT_H
9#define DBOBJECT_H
10#include <QSqlRecord>
11#include <QVariantMap>
12#include "abstractdata.h"
13#include "heart_global.h"
14#include "dbaddress.h"
15
16class QSqlQuery;
17
18namespace QH {
19namespace PKG {
20
24enum class PrepareResult {
26 Fail,
28 Success,
31};
32
37enum class MemberType {
39 None = 0x0,
40
42 Insert = 0x1,
43
45 Update = 0x2,
46
48 Unique = 0x4,
49
51 Autoincement = 0x8,
52
55
58
61};
62
63constexpr inline uint qHash(MemberType type) {
64 return static_cast<uint>(type);
65}
66
71 DBVariant();
72
73 DBVariant(const QVariant& value, MemberType type);
74 QVariant value;
75 MemberType type = MemberType::None;
76};
77
84typedef QMap<QString, DBVariant> DBVariantMap;
85
94{
95 QH_PACKAGE("DBObject")
96
97public:
98
99 DBObject();
100
101 ~DBObject() override;
102
103 bool isValid() const override;
104
110 bool isHaveAPrimaryKey() const;
111
117 virtual void clear();
118
128 virtual DBObject* createDBObject() const = 0;
129
143 virtual PrepareResult prepareSelectQuery(QSqlQuery& q) const;
144
163 virtual bool fromSqlRecord(const QSqlRecord& q) = 0;
164
228 virtual PrepareResult prepareInsertQuery(QSqlQuery& q, bool replace) const;
229
288 virtual PrepareResult prepareUpdateQuery(QSqlQuery& q) const;
289
299 virtual PrepareResult prepareRemoveQuery(QSqlQuery& q) const;
300
312 virtual bool isCached() const;
313
320 virtual bool isBundle() const;
321
327 DbAddress dbAddress() const;
328
329 QString toString() const override;
330
361 virtual DBVariantMap variantMap() const;
362
367 virtual QString table() const = 0;
368
369protected:
370
371 QDataStream &fromStream(QDataStream &stream) override;
372 QDataStream &toStream(QDataStream &stream) const override;
373
391 virtual std::pair<QString, QMap<QString, QVariant>> condition() const;
392
399 virtual QString primaryKey() const;
400
407 virtual QVariant primaryValue() const;
408
414 bool isInsertPrimaryKey() const;
415
416};
417}
418}
419
422Q_DECLARE_METATYPE(QList<QH::PKG::DBObject *>*);
423Q_DECLARE_METATYPE(QList<const QH::PKG::DBObject *>*);
424
425#endif // DBOBJECT_H
#define QH_PACKAGE(S)
QH_PACKAGE This macross prepare data to send and create a global id for package. For get global id us...
The DbAddress class use to work with database addresses. Database Address it is structure with 2 valu...
Definition dbaddress.h:24
The AbstractData class is provide base functions for transport data by network For create you own pac...
The DBObject class- main class for work with data base.
Definition dbobject.h:94
virtual bool fromSqlRecord(const QSqlRecord &q)=0
fromSqlRecord This method should be initialize this object from the executed sqlRecord....
virtual DBObject * createDBObject() const =0
createDBObject This method should be create a object with the some type as the object called this met...
virtual QString table() const =0
table This method should be return name of the database table that should be contains objects with th...
Q_DECLARE_METATYPE(QList< QH::PKG::DBObject * > *)
#define HEARTSHARED_EXPORT
PrepareResult
The PrepareResult enum is result of work prepare sql query of dbobjects.
Definition dbobject.h:24
@ Success
prepare finished successful.
@ Disabled
prepare disabled for method. Use this case for disable prepare method for object without errors.
@ Fail
prepare is failed.
QMap< QString, DBVariant > DBVariantMap
DBVariantMap this is Map with key, and value with data type.
Definition dbobject.h:84
constexpr uint qHash(MemberType type)
Definition dbobject.h:63
MemberType
The MemberType enum. This enum contains types of members DBObjects classes. for more information see ...
Definition dbobject.h:37
@ Update
The Field With This type can be updated but not inserted.
@ PrimaryKey
The primary key field without autoincrement.
@ None
The Field with this type can not be update and Inserted.
@ Autoincement
The field with this atribute automaticaly incemented into database, and will not to added into insert...
@ InsertUpdate
The Field With This type can be inserted and updated.
@ Insert
The Field With This type can be inserted but not updated.
@ Unique
The Field with this type can not be duplicate on a table. If a Database object do not have a primary ...
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13
The DBVariant struct contains QVariant value of the DBObjects member and it type.
Definition dbobject.h:70