LiteSQL - C++ Object-Relational Persistence Framework
Writing XML Database Definition

Before the library can be used, an XML file has to be written. The XML file defines types, objects, fields, methods and relations between objects of the database.

For those of you familiar with DTD, the file format is defined in [attachment:litesql.dtd litesql.dtd]. To make valid XML, the definition file should begin with following lines:

<?xml version="1.0"?>
<!DOCTYPE database SYSTEM "litesql.dtd">

Database-tag

A database definition file has a root tag which encloses all definitions inside it. It must have exactly one 'database'-tag.

<database name="TestDatabase" namespace="test" [include="extra.hpp"]>
... definitions ...
</database>

Note: attributes in [square brackets] are optional.

The definition above will be extracted to C++ - class test::TestDatabase.

Include-tag

A database definition can have zero or more 'include'-tags. The model in the included file is read, objects and relations are inserted into the actual model.

Object-tag

Each 'object'-tag will be extracted to Persistent-class. 'object'-tags are placed inside 'database'-tag.

<object name="MyObject" [inherits="ParentObject"]>
... definitions ...
</object>
}}}

Field-tag

'field'-tags are used to define Persistent object's fields (data members) and relation attributes. They can be placed inside 'object'-tag or 'relation'-tag.

<field name="myfield" type="integer" [default="1"] [indexed="true"]/>
<field name="color" type="integer">
<value name="Red" value="0"/>
<value name="Green" value="1"/>
</field>

Enumerated values can be specified by putting 'value'-tags inside 'field'-tag.

Method-tag

Persistent object's methods are defined with 'method'-tag. It is placed inside 'object'-tag.

<method name="myMethod" [returntype="void"]>
<param name="magic" type="int"/>
</method>

Relation-tag

'relation'-tag defines a relation between two or more objects.

<relation [name="SomeRelation"] [id="1"] [unidir="true"]>
<relate object="Person" [unique="false"] [limit="one"] [handle="cars"]/>
<relate object="Car" [limit="many"] [handle="owner"]/>
... more related objects ...
[<field name="order" type="integer"/>]
... more relation attributes ...
</relation>

Index-tag

'index'-tag defines an index built on two or more fields. It can be used inside 'object'- and 'relation'-tags.

<field name="myfield" type="integer" [default="value"] [indexed="true"]/>
<field name="color" type="integer">
<value name="Red" value="0"/>
<value name="Green" value="1"/>
</field>
<index [unique="true"]>
<indexfield name="myfield"/>
<indexfield name="color"/>
</index>

Indexfield-tag

'indexfield'-tag defines an index field inside multi field index. It can be used inside 'index'-tag.

Naming Identifiers

C++'s reserved words cannot be used as identifier names. Also, "id"- and "type"-fields are defined for each Persistent-object.