#ifndef SERVICE_H #define SERVICE_H #include #include #include #include #include #include #include "core_global.h" #include "context.h" template class Service { public: Service() { } QList > all() { odb::database *db = Context::instance().db(); Q_ASSERT(db); odb::transaction tx(db->begin()); odb::result res = db->template query(); QList > ret; for (typename odb::result::iterator it = res.begin(); it != res.end(); it++) { ret.append(it.load()); } tx.commit(); return ret; } void save(QSharedPointer entity) { odb::database *db = Context::instance().db(); odb::transaction tx(db->begin()); db->persist(entity); tx.commit(); } QSharedPointer loadById(int id) { odb::database *db = Context::instance().db(); odb::transaction tx(db->begin()); db->template load(id); tx.commit(); } }; #endif // SERVICE_H