| t | This document describes how to make a new database in TB Wiki. | t | |
| <p> | | |
| TB Wiki was designed specifically to make this as easy as possible, using | | |
| regular wiki files as the records for the database. This page is intended | | |
| to be a quickstart guide to setting up a simple database. For complete | | |
| documentation, see <a href="/tbwiki/DocTables">DocTables</a> | | |
| <p> | | |
| <h2><a name="Table_Type">Table Type</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/HowTo_make_a_new_database?action=edit§ion=Table_Type">edit section</a>]</font></span> | | |
| </h2> | | |
| First, determine the table type - single file or multi-file. | | |
| <p> | | |
| You can edit the database in a single file, or have a database consist of | | |
| multiple files. If the records are large, and have lots of free-form text, | | |
| it is usually better to put them into separate files. | | |
| <p> | | |
| <h2><a name="single-file">single-file</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/HowTo_make_a_new_database?action=edit§ion=single-file">edit section</a>]</font></span> | | |
| </h2> | | |
| For a single file database, just create a page to hold the table of data, | | |
| and start a table in TB wiki inline table format: | | |
| <p> | | |
| like so: | | |
| <pre> | | |
| {{{!Table:contacts | | |
| ||name||address||phone|| | | |
| ||Tim||123 Main St.||555-5555|| | | |
| ||Frank||456 State Ave.||666-6666|| | | |
| } }} | | |
| </pre> | | |
| <p> | | |
| <h3><a name="multi-file">multi-file</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/HowTo_make_a_new_database?action=edit§ion=multi-file">edit section</a>]</font></span> | | |
| </h3> | | |
| For a multi-file database, you need to decide on a page prefix to use | | |
| for the data files. Each record of the database will reside on it's | | |
| own page in the wiki, and you can use a Table processor to collect | | |
| them into a view of the data. | | |
| <p> | | |
| Let's say you create a contacts database, and use "contacts_" as the | | |
| file prefix. Specify this with a "source_spec=contacts_.*" | | |
| (<i>Note the '.' in the wildcard for the page name</i>) | | |
| Each file in the database has a single record from the database | | |
| in TB wiki name-attr format (these are referred to as attribute files). | | |
| <p> | | |
| The following files might be defined: | | |
| <p> | | |
| "contact_1" would have the following content: | | |
| <pre> | | |
| record=1 | | |
| name=Tim | | |
| address=123 Main St. | | |
| phone=555-5555 | | |
| description="""you could put | | |
| a mult-line description here""" | | |
| </pre> | | |
| <p> | | |
| "contact_2" would have the following content: | | |
| <pre> | | |
| record=2 | | |
| name=Frank | | |
| address=456 State Ave. | | |
| phone=666-6666 | | |
| </pre> | | |
| <p> | | |
| <p> | | |
| <i>Note that not every record needs to define every field</i> | | |
| <p> | | |
| Then, create a separate page to have a view of the table, like so: | | |
| <p> | | |
| "Contacts", would have the following content: | | |
| <pre> | | |
| {{{!Table:contacts | | |
| source_spec=contact_.* | | |
| cols=record_id:name:address:phone:description | | |
| sortby=name:alpha | | |
| } }} | | |
| </pre> | | |
| <p> | | |