22class ISubscribableData;
30class AbstractNodeInfo;
60 virtual bool initSqlDb( QString DBparamsFile =
"",
68 bool isSqlInited()
const;
81 virtual bool run(
const QString &localNodeName);
94 virtual QVariantMap defaultDbParams()
const;
100 QString dbLocation()
const;
108 QVariant getDBAttribute(
const QString& key,
const QVariant& defaultVal);
115 bool setDBAttribute(
const QString& key,
const QVariant& newValue);
144 QString backUp(
int version)
const;
150 const QString &localNodeName()
const;
158 void setLocalNodeName(
const QString &newLocalNodeName);
221 virtual QStringList SQLSources()
const;
228 virtual QSet<QString> systemTables()
const;
235 virtual void objectRemoved(
const DbAddress& address);
242 virtual void objectChanged(
const QSharedPointer<PKG::DBObject>& obj);
294 void addDBPatch(
const DBPatch& patch);
302 virtual bool upgradeDataBase();
311 virtual void onBeforeDBUpgrade(
int currentVerion,
int tergetVersion)
const;
334 template <
class Object,
class Id,
class Setter>
335 QSharedPointer<Object>
getById(
const Id&
id, Setter setter,
bool ifNotExistsCreate =
false) {
336 if (
auto&& database = db()) {
337 auto&& request = QSharedPointer<Object>::create();
338 (*request.*setter)(
id);
340 if (
auto&& result = database->getObject(*request)) {
344 if (ifNotExistsCreate)
370 template <
class Object,
class Id,
class Setter>
372 if (
auto&& database = db()) {
373 auto&& request = QSharedPointer<Object>::create();
374 (*request.*setter)(
id);
375 return database->deleteObject(request);
396 template <
class Object>
398 if (
auto&& database = db()) {
399 return database->replaceObject(obj);
419 template <
class Object>
420 bool insertObj(
const Object& obj,
const QWeakPointer<unsigned int>& resultId = {}) {
421 if (
auto&& database = db()) {
422 return database->insertObject(obj, !resultId.isNull(), resultId);
445 template<
class Object>
446 QList<QSharedPointer<Object>>
getAll(
const QString& table,
const QString& condition =
"")
const {
449 auto&& response = db()->getObject(request);
454 return response->data();
464 bool workWithSubscribe(
const PKG::WebSocket &rec,
465 const QVariant &clientOrNodeid,
469 bool isForbidenTable(
const QString& table);
472 unsigned short _targetDBVersion = 0;
474 QString _localNodeName;
475 friend class DataBaseNode;
The AbstractNodeInfo class contains information about client or server connection and tcp socket of n...
The DataBase class is DataBase base implementation. This implementation contains methods for work wit...
void sigObjectChanged(const QSharedPointer< QH::PKG::DBObject > &obj)
sigItemChanged This signal emitted when database object is changed.
bool deleteById(const Id &id, Setter setter)
Delete an object by its identifier.
bool insertObj(const Object &obj, const QWeakPointer< unsigned int > &resultId={})
insert a new value into database, and save into resultId autoincremented id of inserted object.
bool saveObj(const Object &obj)
Save an object in the database.
void sigObjectDeleted(const QH::DbAddress &obj)
sigItemDeleted This signal emitted when database object is deleted.
QSharedPointer< Object > getById(const Id &id, Setter setter, bool ifNotExistsCreate=false)
Get an object by its identifier.
QList< QSharedPointer< Object > > getAll(const QString &table, const QString &condition="") const
Get a list of all objects from a specified table.
The DbAddress class use to work with database addresses. Database Address it is structure with 2 valu...
The ISqlDB class it is db cache and bridge for DbWriters. Work Scheme of the database cache:
The DBObjectsRequest class is template class for get array of TEMPLATE Objects from database.
The SqlDBWriter class. This class write and read objects from database (hard level)....
#define HEARTSHARED_EXPORT
Q_DECLARE_METATYPE(QH::HostAddress)
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
QMap< unsigned short, QMap< unsigned short, DBPatch > > DBPatchMap
DBPatchMap This is 2 depch map of the DBPatch structure when the first key it is version (from) and s...
DBPatch This is function that should be upgrade database.