com.borkdal.squirrel.entity

declare-entity

macro

(declare-entity entity)

Declare an entity before its definition, in order to allow circular definitions.

def-entity

macro

(def-entity [name structure] & body)

Define a new entity.

Parameters:

name
The entity name. The name DummyEntity will create functions containing the name dummy-entity, as explained below.
structure
A vector of vectors specifying sub-entities.

Each sub-entity vector has three elements:

  • :single, :ordered or :unordered, specifying the number and ordering of instances of this sub-entity.

  • The name of the sub-entity.

  • The variable name used to refer to the sub-entity in the body.

body
The code that creates the SQL string for the entity.

The following are created (given entity name DummyEntity:

  • The record DummyEntity, the type used for instances of the entity. The sub-entities are record fields, with names given by the structure parameters.

  • A method for the generic function com.borkdal.squirrel.definitions/record-type, giving record type :*ns*/dummy-entity.

  • The function dummy-entity? for checking if a value is an instance of this entity.

  • The function make-dummy-entity for creating an instance of this entity.

  • The function update-dummy-entity for updating an instance of this entity.

  • A method for the generic function com.borkdal.squirrel.definitions/add, for adding sub-entities to instances of this entity.

  • The function dummy-entity for creating instances of this entity.

  • A method for the generic function com.borkdal.squirrel.definitions/compile-sql, for compiling instances of this entity into SQL strings.

An example, from com.borkdal.squirrel.postgresql.language-def:

(entity/def-entity [LiteralString [[:single String expression]]]
(str "'"
(defs/compile-sql expression)
"'"))

This specifies an entity called LiteralString, containing a single String sub-entity, where the SQL string for the LiteralString is the SQL string for the sub-entity surrounded by single quotes.

The following entities are then created:

def-parent-entity

macro

(def-parent-entity [parent [& children]])

Define an entity as the parent of children entities.

The effect of this is that the parent entity can be used in any context where the sub-entities can be used.

The following is an example from com.borkdal.squirrel.postgresql.language-def:

(entity/def-parent-entity [Expression [String LiteralString FunctionCall]])

Values of type String, LiteralString and FunctionCall can now be used as sub-entities for entities that take Expression, and com.borkdal.squirrel.postgresql.language-def/expression? will return true for values of these types.

def-string-entity

macro

(def-string-entity [entity])

Define an entity that is a simple string.

All the functions from def-entity are created.

The SQL string for the entity is the string itself.