61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#ifndef INVENTORY_DBOPERATIONS_HH
|
|
#define INVENTORY_DBOPERATIONS_HH
|
|
#include <string>
|
|
#include <stdexcept>
|
|
#include <functional>
|
|
#include <zdb.h>
|
|
#include "dbobjectptr.hh"
|
|
#include "dbobjectvec.hh"
|
|
#include "dbcontainer.hh"
|
|
|
|
namespace inventory {
|
|
namespace datamodel {
|
|
template<class Derived>
|
|
class DBObject;
|
|
}
|
|
|
|
namespace db {
|
|
|
|
class DBSession;
|
|
|
|
class DBOperations {
|
|
DBOperations() {}
|
|
|
|
public:
|
|
template<class K>
|
|
using StatementConstructorExecute = std::function<void(K, PreparedStatement_T)>;
|
|
|
|
template<class K>
|
|
using StatementConstructorSingle = std::function<void(K, PreparedStatement_T)>;
|
|
|
|
// + offset, limit
|
|
template<class K>
|
|
using StatementConstructor = std::function<void(K, PreparedStatement_T, int, int)>;
|
|
|
|
// only a statement constructor argument class here, operation is the same
|
|
// for whole database object hierarchy
|
|
template<class K>
|
|
static void execute(
|
|
DBSession &session, const K &stmt_arg, const char *prepared_stmt,
|
|
StatementConstructorExecute<K> cons);
|
|
|
|
template<class T, class K>
|
|
static datamodel::DBObjectPtr<T> get_single(
|
|
DBSession &session, const K &stmt_arg, const char *prepared_stmt,
|
|
StatementConstructorSingle<K> cons);
|
|
|
|
template<class T, class K,
|
|
template<class> class Container = datamodel::DBObjectVector>
|
|
static datamodel::DBContainerPtr<T, Container> get_all(
|
|
DBSession& session, const K &stmt_arg,
|
|
const char *prepared_stmt, StatementConstructor<K> cons,
|
|
datamodel::DBObjectInserter<T, Container> inserter,
|
|
datamodel::DBContainerPtr<T, Container> pcontainer,
|
|
int offset, int limit);
|
|
};
|
|
|
|
}
|
|
}
|
|
|
|
#endif
|