GNU TeXmacsUser manualReferenceAboutEnglish
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:

db-kind-table

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).

db-format-table

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.

db-encoding-table

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.

db-encoder-table, db-decoder-table

For the keyword values in db-encoding-table, specify the actual routines to be used for encoding and decoding.

Macros for context specification
(with-encoding enc . body)
(specify encoding/decoding scheme)

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).

Special attributes
type

Specifies the entry type.

Affected routines of the database API
(db-set-field id attr vals)
(set values for a given field)
(db-get-field id attr)
(get all values for a given field)
(db-set-entry id l)
(fill out a complete entry)
(db-get-entry id)
(retrieve a complete entry)
(db-remove-entry id)
(remove a complete entry)
(db-search q)
(search for a list of fields)

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.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".