Rudiments
Public Member Functions | List of all members
mvccrud Class Referenceabstract

Inherits object.

Public Member Functions

virtual bool doCreate (const char *const *columns, const char *const *values)=0
 
virtual bool doCreate (dictionary< const char *, const char * > *kvp)=0
 
virtual bool doCreate (jsondom *j)=0
 
virtual bool doRead (const char *criteria, const char *sort, uint64_t skip)=0
 
virtual bool doRead (jsondom *j)=0
 
virtual bool doUpdate (const char *const *columns, const char *const *values, const char *criteria)=0
 
virtual bool doUpdate (dictionary< const char *, const char * > *kvp, const char *criteria)=0
 
virtual bool doUpdate (jsondom *j)=0
 
virtual bool doDelete (const char *criteria)=0
 
virtual bool doDelete (jsondom *j)=0
 
virtual const char * getErrorMessage ()=0
 
virtual int64_t getErrorCode ()=0
 
virtual scalarcollection< uint64_t > * getAffectedRowsScalar ()=0
 
virtual listcollection< uint64_t > * getAffectedRowsList ()=0
 
virtual dictionarycollection< const char *, uint64_t > * getAffectedRowsDictionary ()=0
 
virtual tablecollection< uint64_t > * getAffectedRowsTable ()=0
 
virtual scalarcollection< const char * > * getFirstFieldScalar ()=0
 
virtual listcollection< const char * > * getFirstRowList ()=0
 
virtual dictionarycollection< const char *, const char * > * getFirstRowDictionary ()=0
 
virtual listcollection< const char * > * getFirstColumnList ()=0
 
virtual tablecollection< const char * > * getResultSetTable ()=0
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

The mvccrud class defines an interface for child classes which implement the CRUD (create, read, update, and delete) paradigm.

A typical invocation of a mycrud class which implements mvccrud, from within the dao tier of an MVC application, would be something like:

// initialize crud mycrud *crud=new mycrud(); mycrud->init(...some init parameters...);

// read data mycrud->doRead(...);

// return results via instance of mvcresults mvcr->setSuccess(); mvcr->attachData("myresults","table",mycrud->getResultSetTable()); mvcr->getWastebasket()->attach(crud);

Various methods such as doRead(), doUpdate(), and doDelete() take a "criteria" argument. This should be a JSON string in jsonlogic format (http://jsonlogic.com), and will be used to construct the where clause for these operations:

{ "and" : [ { "=" : [ { "var" : "col1" }, 1 ] }, { "!=" : [ { "var" : "col2" }, "one" ] } ] }

The doRead() method also takes a "sort" argument. This should be a JSON string conforming to the following format, and will be used to construct the order-by clause for these operations:

{ "col1" : "asc", "col2" : "asc", "col3" : "desc" }

Member Function Documentation

◆ doCreate() [1/3]

virtual bool mvccrud::doCreate ( const char *const *  columns,
const char *const *  values 
)
pure virtual

Executes a create (insert) operation.

"columns" should contain the set of columns that corresponding elements of "values" will be inserted into.

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doCreate() [2/3]

virtual bool mvccrud::doCreate ( dictionary< const char *, const char * > *  kvp)
pure virtual

Executes a create (insert) operation.

"kvp" should contain the column/value pairs to be inserted.

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doCreate() [3/3]

virtual bool mvccrud::doCreate ( jsondom j)
pure virtual

Executes a create (insert) operation.

"j" should be a jsondom containing 1 object:

"data" should be a JSON object consisting of the column/value pairs to be inserted.

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doDelete() [1/2]

virtual bool mvccrud::doDelete ( const char *  criteria)
pure virtual

Executes a delete operation.

"criteria" should be a JSON string representing the criteria that will be used to determine what to delete, conforming to the format described in the class description.

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doDelete() [2/2]

virtual bool mvccrud::doDelete ( jsondom j)
pure virtual

Executes a delete operation.

"j" should be a jsondom containing 1 object:

"criteria" should be a JSON object representing the criteria that will be used to determine what to delete, conforming to the format described in the class description.

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doRead() [1/2]

virtual bool mvccrud::doRead ( const char *  criteria,
const char *  sort,
uint64_t  skip 
)
pure virtual

Executes a read operation.

"criteria" should be a JSON string representing the criteria that will be used to build the where clause, conforming to the format described in the class description.

"sort" should be a JSON object representing the criteria that will be used to order the results, conforming to the format described in the class description.

"skip" indicates how many rows to skip immediately (useful for paging).

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doRead() [2/2]

virtual bool mvccrud::doRead ( jsondom j)
pure virtual

Executes a read operation.

"j" should be a jsondom containing 3 objects:

"criteria" should be a JSON object representing the criteria that will be used to determine what to read, conforming to the format described in the class description.

"sort" should be a JSON object representing the criteria that will be used to order the results, conforming to the format described in the class description.

"skip" should be a number indicating how many rows to skip immediately (useful for paging).

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doUpdate() [1/3]

virtual bool mvccrud::doUpdate ( const char *const *  columns,
const char *const *  values,
const char *  criteria 
)
pure virtual

Executes an update operation.

"columns" and "values" should be set to the column/value pairs to be updated.

"criteria" should be a JSON string representing the criteria that will be used to determine what to update, conforming to the format described in the class description.

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doUpdate() [2/3]

virtual bool mvccrud::doUpdate ( dictionary< const char *, const char * > *  kvp,
const char *  criteria 
)
pure virtual

Executes an update operation.

Keys of "kvp" and values of "kvp" should be set to the column/value pairs to be updated.

"criteria" should be a JSON string representing the criteria that will be used to determine what to update, conforming to the format described in the class description.

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ doUpdate() [3/3]

virtual bool mvccrud::doUpdate ( jsondom j)
pure virtual

Executes an update operation.

"j" should be a jsondom containing 2 objects:

"criteria" should be a JSON object representing the criteria that will be used to determine what to update, conforming to the format described in the class description.

"data" should be a JSON object consisting of the column/value pairs to be updated.

Returns true on success and false on error. On error, the code and message can be retrieved using getErrorCode() and getErrorMessage().

◆ getAffectedRowsDictionary()

virtual dictionarycollection<const char *, uint64_t>* mvccrud::getAffectedRowsDictionary ( )
pure virtual

Returns an instance of dictionarycollection with a single element, containing the affected rows doCreate(), doUpdate(), or doDelete() was most recently called or an empty dictionary if doRead() was most recently called.

◆ getAffectedRowsList()

virtual listcollection<uint64_t>* mvccrud::getAffectedRowsList ( )
pure virtual

Returns an instance of listcollection with a single element, containing the affected rows doCreate(), doUpdate(), or doDelete() was most recently called or an empty list if doRead() was most recently called.

◆ getAffectedRowsScalar()

virtual scalarcollection<uint64_t>* mvccrud::getAffectedRowsScalar ( )
pure virtual

Returns an instance of scalarcollection, containing the number of affected rows if doCreate(), doUpdate(), or doDelete() was most recently called or an empty scalar if doRead() was most recently called.

◆ getAffectedRowsTable()

virtual tablecollection<uint64_t>* mvccrud::getAffectedRowsTable ( )
pure virtual

Returns an instance of tablecollection with a single field, containing the affected rows doCreate(), doUpdate(), or doDelete() was most recently called or an empty table if doRead() was most recently called.

◆ getErrorCode()

virtual int64_t mvccrud::getErrorCode ( )
pure virtual

Returns whatever error code may have been set by the most recent failed method call.

◆ getErrorMessage()

virtual const char* mvccrud::getErrorMessage ( )
pure virtual

Returns whatever error message may have been set by the most recent failed method call.

◆ getFirstColumnList()

virtual listcollection<const char *>* mvccrud::getFirstColumnList ( )
pure virtual

Returns an instance of dictionarycollection, representing the first column of each row of the results if doRead() was most recently called, or an empty dictionary if doCreate(), doUpdate(), or doDelete() was most recently called.

◆ getFirstFieldScalar()

virtual scalarcollection<const char *>* mvccrud::getFirstFieldScalar ( )
pure virtual

Returns an instance of scalarcollection, representing the first field of the first row of the results if doRead() was most recently called, or an empty scalar if doCreate(), doUpdate(), or doDelete() was most recently called.

◆ getFirstRowDictionary()

virtual dictionarycollection<const char *, const char *>* mvccrud::getFirstRowDictionary ( )
pure virtual

Returns an instance of dictionarycollection, representing the first row of the results if doRead() was most recently called, or an empty dictionary if doCreate(), doUpdate(), or doDelete() was most recently called.

◆ getFirstRowList()

virtual listcollection<const char *>* mvccrud::getFirstRowList ( )
pure virtual

Returns an instance of listcollection, representing the first row of the results if doRead() was most recently called, or an empty list if doCreate(), doUpdate(), or doDelete() was most recently called.

◆ getResultSetTable()

virtual tablecollection<const char *>* mvccrud::getResultSetTable ( )
pure virtual

Returns an instance of tablecollection, representing the results if doRead() was most recently called, or an empty resultsettable if doCreate(), doUpdate(), or doDelete() was most recently called.