Wednesday, July 10, 2013

Treefrog web framework (C++) and mongo models; contributing some vision

Treefrog is one of the few C++ frameworks that have emerged with good documentation and a dedicated development team. I personally like it so far, predominantly because it works and for C++ it is easy. Note file references are the way they are because I am on a Mac trying things out.

There really is no reason we can not perform CRUD operations with mongo, we just sort of need to standardize the crud operations. However, in 1.6.1 even with QT >= 5, treefrog is only mostly there. I don't really expect scaffolding tools; NoSQL is rather loosely defined after all, just to be able to create model abstraction.

more /Library/Frameworks/treefrog.framework/Versions/1/Headers/tabstractmodel.h
#ifndef TABSTRACTMODEL_H
#define TABSTRACTMODEL_H

#include 
#include 

class TSqlObject;
class TModelObject;


class T_CORE_EXPORT TAbstractModel
{
public:
    virtual ~TAbstractModel() { }
    virtual bool create();
    virtual bool save();
    virtual bool update();
    virtual bool remove();
    virtual bool isNull() const;
    virtual bool isNew() const;
    virtual bool isSaved() const;
    virtual void setProperties(const QVariantMap &properties);
    virtual QVariantMap toVariantMap() const;

    static QString fieldNameToVariableName(const QString &name);

protected:
    virtual TSqlObject *data() { return NULL; }  // obsolete
    virtual const TSqlObject *data() const { return NULL; }  // obsolete
    virtual TModelObject *modelData() { return NULL; }
    virtual const TModelObject *modelData() const { return NULL; }

    virtual TModelObject *mdata();
    virtual const TModelObject *mdata() const;
};


inline QString TAbstractModel::fieldNameToVariableName(const QString &name)
{
    QString ret;
    bool existsLower = false;
    bool existsUnders = name.contains('_');
    const QLatin1Char Underscore('_');

    ret.reserve(name.length());
more /Library/Frameworks/treefrog.framework/Versions/1/Headers/TreeFrogModel 

So having saw this I though, great, I can probably make my own mongodb model. Then I thought - wait, I better check on that.

#include "tabstractmodel.h"
#include "tcriteria.h"
#include "tcriteriaconverter.h"
#include "tfnamespace.h"
#include "tglobal.h"
#include "tmodelutil.h"
#include "tsqlormapper.h"
#include "tsqlormapperiterator.h"
#include "tsqlobject.h"
#include "tsqlquery.h"
#include "tsqlqueryormapper.h"
#include "tsqlqueryormapperiterator.h"
#include "twebapplication.h"

#if QT_VERSION >= 0x050000
#include 
#include 
#include 
#include 
#endif

So I spoke with the developer and he said he was planning to expand the model class to permit mongo as well.

ao27 via lists.sourceforge.net 
9:16 PM (12 hours ago)

to treefrog-user 
Hello Mehmet,

To access MongoDB server easily, I considered that the framework
should execute it
through TAbstractModel class.

I am going to modify TAbstractModel class so that its object can have not only a
TSqlObject object but also a TMongoObject object.
That means that TAbstractModel class can access MongoDB server.


  [ Inheritance Hierarchy ]

        TModelObject
             |
   +---------+--------+
   |                  |
TSqlObject        TMongoObject

A TAbstractModel object has the pointer to a TModelObject object,
can perform CRUD operations.

Regards,

aoyama

This guy is awesome. If he acts on it, it wouldn't be the first time he indulged me. Thanks Aoyama!

Still, I can't be sure what he plans to do. I presume it shouldn't be too tough, because he made both TSqlObject and TMongoObject use QVariant maps, which suggests to me we may have been thinking alike all along.