Base Class Script

Base class for database, table and row classes.

This is the parent class used by all the library.database classes. It provides common functionality. In some cases, it documents what methods should be available without providing a working implementation.

The base class children classes are used to provide instance scripts for nodes, i.e. application.require(node) will return a node instance object.

The base class and its children use exceptions to signal unexpected conditions.

o = new Base(context)

Create a new instance of the base class which provides an API to the data in the context node.

node = getContext() Return the node used when creating the instance.
clearData() Clear the data associated with the class. This should be called after an update to ensure that data is re-retrieved, rather than old data returned.
object = getRowDefinition()

Return a definition of the row associated with this type of object. In Base class, this returned nothing, but the class is overridden for Table and Row classes to return the appropriate row definition.

The row definition is documented in Derive Row Definition.

node = resolveNodeWithField(rowData,field)

Given data object and a field definition, return the node to which the data object refers. Throw an exception if rowData cannot be resolved to a node.

This will resolve a node using the following options, in order:

  • If rowData is missing, empty or null, it will resolve to null.
  • if rowData is exactly true, it will resolve to the system.TRUE node.
  • If rowData is a valid node reference t, it will resolve to a node.
  • If rowData looks like it is file upload information, and this is a file field, it will resolve to the special value library.database.UnresolvedFileConstant. Later processing may use this to process file uploads.
  • If rowData is an object with a reference, assume it is a node reference and resolve the node.
    • If the field is a parent link, resolve rowData as if it were a key field for the table.
node = resolveNodeFromReference(rowData)

Attempts to resolve a node without referring to a field definition. If it cannot resolve the node but it may be resolvable with the field definition, return exactly false. Otherwise, throw an exception if the rowData cannot be resolved.

object = getFieldDefinition(fieldReference)

Get the definition of the field with the given reference, or throw an exception if not found.

object = getTable(tableReference)

Get the object for the given table reference. Throw an exception if not found.

The object will be an instance of Table Class, or a class derived from this.

node = getTableNode(tableReference)

Get the node that represents the given table reference. Throw an exception if not found.

object = parseJSON(string,default)

Standard parseJSON method.

object = getParamsObject(request)

Given a request xPath object (i.e. from application.get('request')), return an object containing all the request parameters.

object = getRequestBodyMerged(request)

Read the request and parse the body as JSON. Then merge in all the other request parameters, and return the resultant merge.

If the body is an array, merge the request parameters into each item in the array.


Set the data on node to the data in row. If setKeys is false, do not set the keys (i.e. perform an update of non-key data). If deleteMissing is true, delete members that exist but which are not in the row.

This method does not apply the changes.

Once the changes have been applied, use completeSetNodeData() on the row instance.


Call this on the instance object for a node after calling setNodeData on that node to complete writing rowData to the node. This will process children fields and associated file fields.

object = getNodeJSON(node,field)

Return the JSON held in the field on the node.


Run the class as a service.

This reads the request and then forwards the call to the method in, where action is the action parameter.

node = getNode(reference)

Get the node identified by the reference.

Node retrieval is cached between all children of BaseClass. Use clearData() to clear the cache.

object = extend(o1,o2,deep)

Standard extend() functionality. Overwrite o1 with properties from o2. If deep is true, continue processing into sub objects.


Return true if o is a plain object. Instance and static method.


Returns true if o is an array. Instance and static method.


Allow a child to inherit Base functionality. The general form of inheritance is

ChildClass = ParentClass.inherit(function(){
// Additional constructor code goes here

The ChildClass.parent property point to the parent class.


Tag List