Project

General

Profile

Creating a database web-frontend with interactive search in Wt

Added by Alec Taylor about 13 years ago

Good Morning,

I'm attempting to create a frontend to a database with interactivity.

Interactive search, and interactive search results.

Attached is a mockup of what I mean by that.

Please tell me if it's possible to do in Wt, and if so, how.

Thanks,

Alec Taylor

RandomDatabase.png (113 KB) RandomDatabase.png Mockup of database frontend

Replies (3)

RE: Creating a database web-frontend with interactive search in Wt - Added by John Harris about 13 years ago

Alec,

Looking at your image, the best I can tell, yes, you can do what you want in Wt.

However, Wt's learning curve is fairly steep. I'm still climbing this mountain. If you're not very facile with C already, I would probably recommend a different approach than Wt.

Things I like at Wt (so far):

  1. Any web development package where you have to type your own HTML tags is a non-starter for me. I strongly believe that the development package should abstract out all of the requirements of knowing HTML and all of its ugliness. PHP, Ruby on Rails, Zope, etc, all require you to type some or all of the HTML tags. While in Wt you can, if you really want, type HTML tags, so far I've never needed to.
  2. I don't want to worry about differences in browsers. Wt really shines here.
  3. Fast. I'm using sqlite for the database and the standalone web server. A very responsive web application sounds like an oxymoron, but Wt is responsive.
  4. Security. Due to some C-isms and the excellent coding of Wt, many/most (all?) of the more difficult web security problems are nonexistent in Wt.

I will say that using PHP will probably get you something up and running much faster than Wt, but the Wt app will feel much more professional and polished (did I mention responsive?) should you go that route. I'd like to give some estimate if the differences in development time, Wt will always take longer than PHP. How much longer? Right now I can't say.

Hope that helps,

- john

RE: Creating a database web-frontend with interactive search in Wt - Added by Alec Taylor about 13 years ago

Thanks for the suggestion, I'll post on stackoverflow and see what alternatives they recommend (PHP, asp &etc.)

I am a C programmer, which is what interests me with Wt.

I'm happy to use any database software, however this database I'm writing will have >1 000 000 000 entries (all with relations to others), so I need a scalable database.

If I could see some sample Wt code which does... lets say, just the search sidebar, it'd be incredibly useful and appreciated.

Thanks,

Alec Taylor

RE: Creating a database web-frontend with interactive search in Wt - Added by John Harris about 13 years ago

If I could see some sample Wt code which does... lets say, just the search sidebar, it'd be incredibly useful and appreciated.

That's exactly where I am! I did finish one app using .csv files. Had enough success with that I'm pressing on.

This is the bit of code I'm working on. Do not, in anyway, think that is correct or but free. This is a work in progress.

The following is largely cobbled from code I've found in Koen's blog, code on the Wt forums, and looking at the Wt documentation.

And lastly, I would like to say that Koen & Wim themselves have been very responsive and helpful.

This code seems to work better with Wt 3.1.9 (3.1.8 has problems, http://redmine.emweb.be/boards/2/topics/1881), but I'm also finding issues with viewing it under firefox, chrome works well though. This sentence sounds pretty bad, so let me say that this is the first significant problem I've had with Wt, everything else just worked as documented.

#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
#include <Wt/WTableView>

using namespace Wt;

#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/backend/Sqlite3>
#include <Wt/Dbo/QueryModel>

namespace dbo = Wt::Dbo;

#include <string>
using namespace std;



// DataBase definition.

class User {
public:
  enum Role {
    Visitor = 0,
    Admin = 1,
    Alien = 42
  };

  std::string name;
  std::string password;
  Role        role;
  int         karma;

  template<class Action>
  void persist(Action& a)
  {
    dbo::field(a, name,     "name");
    dbo::field(a, password, "password");
    dbo::field(a, role,     "role");
    dbo::field(a, karma,    "karma");
  }
};

void create_database (void)
{
  dbo::Session session;
  dbo::backend::Sqlite3 sqlite3 ("MyDB.sql3");
  session.setConnection (sqlite3);
  session.mapClass<User> ("user");

  session.createTables();
  cout << "here" << endl;
  { 
    dbo::Transaction transaction(session);
    for (int i = 0; i < 1000000; i += 1)
      {
        User *user = new User();
        user->name = "Joe" + boost::lexical_cast<std::string>(i);
        user->password = "Secret";
        user->role = User::Visitor;
        user->karma = 42;

        dbo::ptr<User> userPtr = session.add (user);
      }
    transaction.commit();
  }
}

class mainWindow : public WContainerWidget
{
public:
  mainWindow (dbo::Session & session, WContainerWidget *parent=0)
    : WContainerWidget (parent)
  {
    dbo::QueryModel< dbo::ptr<User> > *model = new dbo::QueryModel< dbo::ptr<User> >();
    model->setQuery(session.find<User>());
    model->addAllFieldsAsColumns();

    WTableView *view = new WTableView (this);
    view->resize(800, 300);
    view->setSelectionMode(SingleSelection);
    view->setModel(model);
  }
};

class MyApplication : public WApplication
{
private:
  dbo::Session session;
  dbo::backend::Sqlite3 sqlite3;
public:
  MyApplication (WEnvironment const & env) 
    : WApplication (env), sqlite3 ("MyDB.sql3")
  {
    session.setConnection (sqlite3);
    session.mapClass<User>("user");

    root () -> resize (800, 300);
    root () -> addWidget (new mainWindow (session, root ()));
  }
  ~MyApplication (void) { std::cout << "MyApplication dead" << std::endl; }
};


WApplication * createApplication (WEnvironment const & env)
{ return new MyApplication (env); }

int main(int argc, char **argv)
{
  create_database ();
  return WRun (argc, argv, & createApplication);
}

cmake file:

ADD_EXECUTABLE(dbo.wt dbo.C)
TARGET_LINK_LIBRARIES(dbo.wt wthttp wt wtdbo wtdbosqlite3)
#set(CMAKE_CXX_FLAGS "-Wall -ggdb -DNDEBUG")        # Maximize debugging
set(CMAKE_CXX_FLAGS "-Wall -ggdb")              # Maximize debugging

Save the code as dbo.C, the cmake as CMakeList.txt. Then "cmake CMakeList.txt", and "make". You'l need a "resources" directory, try "ln -s /usr/share/Wt/resources". Run with: "./dbo.wt ---docroot . ---http-address 0.0.0.0 ---http-port 8080"

So far, Wt seems to me as very solid. Not at all a flaky/brittle platform to develop on. I don't know about the 100,000,000 records, but I suspect that sqlite will handle it. This example code create 1,000,000 records.

YMMV!

- john

    (1-3/3)