WikiDB/Defining tables

From TestWiki
Jump to: navigation, search

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]


  • 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 of Table: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.
  • 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 a Surname field, then you can simply set up an alias so both are treated as equivalent.