-
Notifications
You must be signed in to change notification settings - Fork 3
XML format
XMLs for NiceQL are very simple and easy to read/write. Here's a small example:
<?xml version="1.0" encoding="UTF-8"?>
<scheme version="1">
<table name="articles" withPrimaryKey="true">
<column name="title" type="TEXT" notNull="true" />
<column name="text" type="TEXT" />
<column name="order_key" type="INTEGER" notNull="true" />
<index name="idx_articles_order_key" isUnique="true">
<column name="order_key" />
</index>
<seed>
<column name="title">First article</column>
<column name="text">Hello world!</column>
<column name="order_key">0</column>
</seed>
<seed>
<column name="title">More stuff to come!</column>
<column name="text">Yeah!</column>
<column name="order_key">1</column>
</seed>
</table>
<sql>
SELECT 1 FROM articles
</sql>
<table name="friends" withPrimaryKey="true">
<column name="name" type="TEXT" notNull="true" />
<column name="surname" type="TEXT" notNull="true" />
</table>
</scheme>
Root tag is <scheme>
with optional attribute version
which should contain numerical (int) scheme version. If it is not specified, then version value passed to parse()
method will be used. If none passed and found, version number one will be used.
<table>
tag contains table definition for every table including indices and seeds. It must have name
attribute and it might have boolean withPrimaryKey
(boolean attributes may have only two values values: true
or false
. Default is false when attribute is undefined). Inside <table>
tag you should put some columns. Indices and seeds are optional.
<column>
tag describes one column for a table. It must have name
and type
attributes. You must use SQLite compatible type names when defining column type. You may also specify notNull
boolean attribute to make column NOT NULL.
<index>
tags are used to specify table indices. They must have name
attribute and may have isUnique
boolean attribute. Inside you should place one or more <column>
tags with only one attribute name
to specify which columns are relevant to this index.
<seed>
tags are used to pre-populate tables with some data. They don't have any attributes, but should contain <column>
tags with only one attribute name
with values stored as tag text. One seed equals one record. Make sure to put correct columns.
NiceQL is very lax when it gets to errors. You can write whatever you want in XML file, unknown tags and attributes will be ignored and illegal SQL statements, values and types will be passed to Scheme instance. You will only know about the errors when you will try to execute statements. That makes NiceQL a future-compliant library - you can use it safely with future versions of SQLite with more datatypes. It is up to you to properly catch exceptions.