|
#include <Wt/WApplication>
|
|
#include <Wt/WContainerWidget>
|
|
#include <Wt/WEnvironment>
|
|
#include <Wt/WTableView>
|
|
|
|
#include <Wt/Dbo/Dbo>
|
|
#include <Wt/Dbo/backend/Sqlite3>
|
|
#include <Wt/Dbo/QueryModel>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
using namespace Wt;
|
|
namespace dbo = Wt::Dbo;
|
|
|
|
struct example {
|
|
example() : flag(false) {}
|
|
|
|
bool flag;
|
|
template<class Action>
|
|
void persist(Action& a) { dbo::field(a, flag, "flag");}
|
|
};
|
|
|
|
class ExampleApplication : public WApplication {
|
|
private:
|
|
dbo::Session session;
|
|
dbo::backend::Sqlite3 sqlite3;
|
|
public:
|
|
ExampleApplication (WEnvironment const & env) : WApplication(env), sqlite3("example.db")
|
|
{
|
|
session.setConnection(sqlite3);
|
|
session.mapClass<example>("example");
|
|
try {
|
|
session.createTables();
|
|
dbo::Transaction t(session);
|
|
session.add(new example());
|
|
t.commit();
|
|
} catch (const dbo::Exception) {
|
|
// database exists, catch and ignore
|
|
}
|
|
|
|
dbo::QueryModel<dbo::ptr<example> > *model = new dbo::QueryModel<dbo::ptr<example> >(root());
|
|
model->setQuery(session.find<example>());
|
|
model->addAllFieldsAsColumns();
|
|
|
|
WTableView *view = new WTableView(root());
|
|
view->resize(800, 300);
|
|
view->setModel(model);
|
|
}
|
|
};
|
|
|
|
WApplication * createApplication (WEnvironment const & env)
|
|
{
|
|
return new ExampleApplication(env);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return WRun (argc, argv, &createApplication);
|
|
}
|