![]() |
Formats of database entries | ![]() |
From the high-level point of view, it is often useful to manipulate database values as other objects than raw strings. In
database/db-format.scm
, an additional layer is added to the basic database API which allows you to specify encoding and decoding schemes between raw strings and user defined data formats for specific types of entries and attributes. More precisely, the extension introduces the following tables:
For each “kind” of database (e.g. "bib" for bibliographies), specify a finite list of supported entry types (e.g. "article", "book", etc. for bibliographies).
For each entry type, specify the format of the fields: mandatory fields, alternative fields and/or optional fields, using the combinators and, or and optional. See
database/bib-db.scm
for examples. The routine (format->attributes fm) returns the list of attributes which occur in such a format.
For each triple (attr type enc) of an attribute, an entry type and an encoding scheme, specify a keyword which specifies how to encode/decode field values. Each component of the triple may be the wildcard *. If no matching entry is found, then the keyword :texmacs is used, which encodes TeXmacs snippets as strings. Keywords for which no encoder (resp. decoder) has been defined, such as :identity, leave the values unchanged. For instance,
database/db-users.scm
uses the keyword :users for the permission attributes under the encoding scheme :pseudos.
For the keyword values in db-encoding-table, specify the actual routines to be used for encoding and decoding.
Specify the encoding/decoding scheme enc to be used inside body. This value is used as the third component of triples in db-encoding-table. The value #f disables encoding and decoding, the default scheme is :default, and the scheme :pseudos is used for representing users by their pseudos (see users and permissions).
Specifies the entry type.
The default behaviour is customized so as to encode/decode field values according to the current encoding/decoding scheme. For a query, the encoding is determined by the entry type given by a type constraint, if any. The routine db-get-entry in addition sorts the fields: the fields specified by the format of the entry type come first, in the order of the format.