Next: , Previous: , Up: Octet Molding/Mashing   [Contents][Index]


11.3 Defining New Converters

To define a new non-array type means associating with the type name a procedure for converting from a PostgreSQL string representation to a Scheme object (the objectifier), a procedure to do the conversion in the opposite direction (the stringifier), and a default string to use if none is specified (for example, during an INSERT operation). For this, use the define-db-col-type procedure.

Procedure: define-db-col-type name default stringifier objectifier

Register type name with default, stringifier and objectifier procs. name is a symbol. default is a string to use if the Scheme object is #f. stringifier is a proc that takes a Scheme object and returns a string suitable for use in an INSERT VALUES SQL command. objectifier is a proc that takes a string and returns the Scheme object parsed out of it.

Both stringifier and objectifier need not worry about SQL-style quoting (using single quotes) and related quote escaping.

If name already exists, it is redefined. See also dbcoltype-lookup.

To express conversion of arrays (no matter the dimensionality) of non-array types, use the register-array-variant procedure.

Procedure: register-array-variant rank simple [stringifier [objectifier]]

Register an array type of rank dimensions based on simple. rank is a (typically small) positive integer. simple is a type name already registered using define-db-col-type.

By default, the associated stringifier and objectifier are those of simple. If stringifier and objectifier are specified and non-#f, Guile-PG uses them instead.

The default value of all array types is ‘{}’ and cannot be changed.

Return the name (a symbol) of the array type. This is basically rank asterisks followed immediately by simple. For example, if rank is 2 and and simple is int4, the name would be **int4.

The following is obsolete.

Procedure: define-db-col-type-array-variant composed simple [stringifier [objectifier]]

NB: This procedure will be removed by 2015-12-31.

Register type composed (string or symbol) as an array variant of simple. simple should be a type name already registered using define-db-col-type. composed must be formed by appending simple with one or more pairs of ‘[]’ (square braces), with the number of pairs indicating the array dimensionality. For example, if simple is text, a two-dimensional text array would be named text[][].

By default, the stringifier and objectifier for composed are those of simple. If stringifier and objectifier are specified and non-#f, Guile-PG uses them instead.

The default value of all array types is ‘{}’ and cannot be changed.


Next: , Previous: , Up: Octet Molding/Mashing   [Contents][Index]