You should have some knowledge of the Velocity Template Language before reading this page.
In a MVC Webapp, operations that issue changes to the database should not be done from inside the templates but from a separate controller. One way to enforce this is to set the read-only flag on in Velosurf configuration file (the controller can change this flag programmatically for its own connection).
All methods that take a "Map values"
argument expect column names as keys. They are quite convenient to use with the $query
variable (that contains all the HTTP query parameters) when coming
from an HTML form: you only have to ensure that the names of HTML
input fields map correctly to the names of the corresponding table
columns.
Plain keywords represent actual names of properties or methods, while keywords in italic stand for user properties or variables.
$db.entity | returns an entity |
$db.attribute | gets an attribute, returns a scalar, an instance, or an iterable attribute |
$db.action | executes an action, returns the number of affected rows |
$db.external-parameter | gets or sets an external parameter |
$db.error | returns the last encountered error, if any |
$db.locale | returns the current locale |
$entity.fetch(key) | returns the instance uniquely identified by key if it does exist, null otherwise |
#foreach( $instance in $entity ) | iterates over this entity's instances |
$entity.rows | returns the list of this entity's instances |
#set( $entity.order = 'order' ) | specifies how to order this entity's instances |
$entity.refine( 'condition' ) | adds a filtering condition on this entity's instances |
$entity.clearRefinement() | clears any previously set refinement |
$entity.newInstance() | returns a new empty instance for this entity |
$entity.validate(Mapvalues) | validate data against this entity's constraints, returns the boolean success status |
$entity.insert(Map values) | inserts an instance of the entity, returns the boolean success status |
$entity.lastInsertID | returns the last inserted ID for this entity's autoincremented primary key |
$entity.update(Map values) | updates an instance of the entity, returns the boolean success status |
$entity.delete(Map values) | delete an instance of the entity, returns the boolean success status |
Returns the instance uniquely identified by key if it does exist, null otherwise. key specifies this entity's primary key value and can be a scalar value (string or number, for single-column keys), a list of values (for multi-column keys), or a map (where key values are stored under their column name).
refine() and order() methods.
refine() and order() methods.Sets the column(s) to be used for ordering this entity's instances when issuing a #foreach.
This setting is local to the current Velocity context. The argument follows the syntax of a standard SQL ORDER BY clause, that is,
several columns can be present in a comma separated list, and when postfixed to a column name the DESC keyword means descending order.
Specifies an additional SQL condition before issuing a #foreach on this entity.
This method can be called several times to accumulate conditions. The refinement is local to the current Velocity context.
Refinements can be reset using the clearRefinement() method.
Use of this method is not encouraged, as it breaks the principle of SQL code isolation. It may be removed from future versions of Velosurf.
Inserts the given values as a new instance of this entity and returns the boolean success status of the operation.
Unless auto-incremented, primary key values must be present in the map.
If this entity's primary key is an auto-incremented index, its value can be retrieved using $entity.lastInsertID.
If there are validation constraints for this entity, values are validated against them before the insertion.
Returns the last inserted ID value for this entity's autoincremented primary key.
Updates the values of an instance of this entity and returns the boolean success status of the operation. Primary key values must be present in the map along with values to be updated.
Note that this method cannot be used to update the values of the primary key itself (use insert(new key) plus delete(old key)).
If there are validation constraints for this entity, values are validated against them before the update.
Deletes an instance of the entity and returns the boolean success status of the operation. Primary key values must be present in the map.
#foreach( $instance in $attribute ) | iterates over the instances of this attribute |
$attribute.rows | returns the list of this attribute's resulting instances |
#set( $attribute.order = 'order' ) | specifies how to order this attribute's resulting instances |
$attribute.refine( 'condition' ) | adds a filtering condition on this entity's instances |
$attribute.clearRefinement() | clears any previously set refinement |
Only multivalued attributes (attributes that return a row set) can be referenced from templates. Others are directly evaluated when referenced.
refine() and order() methods.
refine() and order() methods.Sets the column(s) to be used for ordering this attributes's resulting instances when issuing a #foreach.
This setting is local to the current Velocity context. The argument follows the syntax of a standard SQL ORDER BY clause, that is,
several columns can be present in a comma separated list, and when postfixed to a column name the DESC keyword means descending order.
Specifies an additional SQL condition before issuing a #foreach on this attribute.
This method can be called several times to accumulate conditions. The refinement is local to the current Velocity context.
Refinements can be reset using the clearRefinement() method.
Use of this method is not encouraged, as it breaks the principle of SQL code isolation. It may be removed from future versions of Velosurf.
An action has no attribute and no method. It is executed when referenced, and returns the number of affected rows.
$instance.column | Gets or sets the value of the specified column |
$instance.attribute | calls an attribute of this instance, returned value depend on the attribute result type |
$instance.action | executes an action of this instance and returns the number of affected rows |
$instance.entity | returns this instance's entity or null for a generic instance |
$instance.primaryKey | returns a list of two-elements maps ('name'→name and 'value'→value) of this instance's key column(s) |
$instance.validate | validates this instance's data |
$instance.insert() | inserts this instance in the database |
$instance.update() | updates this instance with current values and return the boolean success state of the operation |
$instance.update( Map values ) | updates this instance with values in values and return the boolean success state of the operation |
$instance.delete() | deletes this instance from the database |
#foreach.
null for a generic instance.Returns a list of two-elements maps ('name'→name and 'value'→value) of this instance's key column(s).
Validates the data currently set in the instance.
Inserts this instance in the database and returns the boolean success status of the operation.
Data is validated against constraints present in this instance's entity, if any.
Updates this instance using current values. Returns the boolean success status of the operation.
Data is validated against constraints present in this instance's entity, if any.
Updates this instance using values in the map (or current values for columns not present in the map). Returns the boolean success status of the operation.
Data is validated against constraints present in this instance's entity, if any.
Removes this instance from the database, and returns the boolean success status of the operation.
$local.locale | returns the current locale |
$local.message-id | returns the message corresponding to the specified id and the current locale |
$local.get('message-id',...) | returns the message corresponding to the given id and the current locale, using the supplied parameters |
Returns the current locale used by the localizer
Returns the message corresponding to the given id and using the current locale.
Returns the message corresponding to the given id and the current locale, using the supplied parameters. The message must contain {0}, {1}, ... tags at the places where supplied parameters are to be inserted.
$auth.challenge | returns a new challenge for CRAM authentication |
Returns a new challenge for CRAM authentication. See this section in the user guide for more details.