#ifndef SERVICE_H #define SERVICE_H #include #include #include #include #include #include template class Service { public: Service() { } QList > all() { odb::database *db = Context::instance().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++) { QSharedPointer entity = db->template load(((T*)*it)->id()); ret.append(entity); } 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