Difference between revisions of "WikiDB/Defining tables"
From TestWiki
< WikiDB
m (→Tables: better wording) |
m (→Tables: Fixed inverted statement.) |
||
Line 10: | Line 10: | ||
* Any page in a table namespace is a table definition, which is referred to by its page name (e.g. <code><nowiki>[[Table:People]]</nowiki></code>). | * Any page in a table namespace is a table definition, which is referred to by its page name (e.g. <code><nowiki>[[Table:People]]</nowiki></code>). | ||
* The content of each page in a table namespace defines the schema for a specific table. | * The content of each page in a table namespace defines the schema for a specific table. | ||
− | * When referring to tables, the namespace prefix is only required when the context is ambiguous | + | * When referring to tables, the namespace prefix is only required when the context is ambiguous. If the context is unambiguous then, for example, <code>People</code> may be used instead of <code>Table:People</code>. If there is only one table namespace, context is unambiguous most of the time. |
* Creating redirects within a table namespace allows you to set up alternative names for tables. The most common use for this is to allow you to rename/move a table without having to update all existing data definitions to use the new name. | * Creating redirects within a table namespace allows you to set up alternative names for tables. The most common use for this is to allow you to rename/move a table without having to update all existing data definitions to use the new name. | ||
Latest revision as of 12:23, 24 January 2016
WikiDB is a tool to create and query database-like data from within your wiki.
This page describes how to add structure to your data.
Basic principles[edit]
Tables[edit]
- The wiki administrator needs to define one ore more 'table' namespaces, in
LocalSettings.php
. - Any page in a table namespace is a table definition, which is referred to by its page name (e.g.
[[Table:People]]
). - The content of each page in a table namespace defines the schema for a specific table.
- When referring to tables, the namespace prefix is only required when the context is ambiguous. If the context is unambiguous then, for example,
People
may be used instead ofTable:People
. If there is only one table namespace, context is unambiguous most of the time. - Creating redirects within a table namespace allows you to set up alternative names for tables. The most common use for this is to allow you to rename/move a table without having to update all existing data definitions to use the new name.
Data in tables[edit]
- Data exists independently of any table structure, which has a number of important implications:
- No structure is required - you can assign data to a table without the table page even existing.
- The structure can change at any time, and all existing data is immediately updated appropriately.
- All schema changes are non-destructive, i.e. they don't modify data. For example, unlike in most database systems, converting a string field to an integer won't destroy all non-integer values that may exist for that field.
- As a corollary to the above: all schema changes are reversible. Changing that integer back to a string will restore all data to its original state.
- Any field you define will cause all data in that field to be formatted/validated/sorted according to the data-type (including any relevant options) that you specify.
- For example, non-numeric values in a field defined as
integer
will be considered invalid and be treated as blank.
- For example, non-numeric values in a field defined as
- Any field for which there is some data but no definition will be treated as a
wikistring
field. - The list of data types is extensible (i.e. you can create your own types).
- You can define field aliases, so if half the pages on your wiki describe People using a
LastName
field, and half use aSurname
field, then you can simply set up an alias so both are treated as equivalent.