Herunterladen als
root/samples/simple/main.cpp @ 6c14baaf
b7446f4c | Christian Ehringfeld | #include <QCoreApplication>
|
|
#include <QDir>
|
|||
#include <QDebug>
|
|||
c5d0ed54 | Christian Ehringfeld | #include "article.h"
|
|
886bdb22 | Christian Ehringfeld | #include "entitymanager.h"
|
|
#include "entityinstancefactory.h"
|
|||
0ec1cbfb | Christian Ehringfeld | ||
b7446f4c | Christian Ehringfeld | using namespace CuteEntityManager;
|
|
int main(int argc, char *argv[]) {
|
|||
Q_UNUSED(argc) Q_UNUSED(argv)
|
|||
c5d0ed54 | Christian Ehringfeld | EntityInstanceFactory::registerClass<Article>();
|
|
QSharedPointer<CuteEntityManager::EntityManager> e =
|
|||
QSharedPointer<CuteEntityManager::EntityManager>(new
|
|||
CuteEntityManager::EntityManager("QSQLITE",
|
|||
QDir::currentPath() + "/db.sqlite"));
|
|||
QStringList inits = QStringList() << "Article";
|
|||
b7446f4c | Christian Ehringfeld | e->startup("0.1", inits);
|
|
c5d0ed54 | Christian Ehringfeld | QSharedPointer<Article> a = QSharedPointer<Article>(new Article(5.0,
|
|
"muesli"));
|
|||
5b3fa099 | Christian Ehringfeld | auto ep = a.objectCast<CuteEntityManager::Entity>();
|
|
c5d0ed54 | Christian Ehringfeld | qDebug() << e->create(ep, true, true); //INSERT on database
|
|
a->setPrice(6.0); //inflation
|
|||
a->setName("muesli improved"); //1337 muesli upgrade
|
|||
qDebug() << e->save(ep); //UPDATE on database
|
|||
qDebug() << e->remove(ep); //REMOVE on database
|
|||
b7446f4c | Christian Ehringfeld | return 0;
|
|
}
|