Skip to main content

Complete Example

This example shows one CSDB file with two related tables and one minimal table.

--- csdb
format: CSDB
version: 1
name: payroll
machine_indexing:
enabled: true
machine_key_width: 80
machine_value_width: 40
section_title_length: 80
footer_entry_count: 1
tables:
- workers
- sessions
- tags
comments:
database: Payroll and work-session records.

--- table:workers:schema
name: workers
columns:
id: text
name: text
email: text
home_path: path
type_options:
email: {option: key, option2: key}
required:
- id
- name
- email
defaults: {}
primary_key:
columns: [id]
unique:
- [email]
foreign_keys: []
constraints: []
indexes:
- name: workers_email_idx
columns: [email]
unique: true
computed_fields: {}
comments:
table: People who can work sessions.
columns:
home_path: Optional writable filesystem path.
indexes:
workers_email_idx: Supports email lookups.

--- table:workers:data
id,name,email,home_path
w_001,Ada Lovelace,ada@example.com,/users/ada
w_002,Grace Hopper,grace@example.com,/users/grace

--- table:sessions:schema
name: sessions
columns:
id: text
worker_id: text
start_time: timestamp
end_time: timestamp
hourly_pay: numeric
metadata: json
required:
- id
- worker_id
- start_time
- hourly_pay
defaults: {}
primary_key:
columns: [id]
unique: []
foreign_keys:
- name: sessions_worker_fk
columns: [worker_id]
references:
table: workers
columns: [id]
on_delete: restrict
on_update: cascade
relationship: worker
constraints:
- name: end_after_start
expression: end_time IS NULL OR end_time >= start_time
- name: pay_nonnegative
expression: hourly_pay >= 0
indexes:
- name: sessions_worker_id_idx
columns: [worker_id]
unique: false
- name: sessions_open_idx
columns: [worker_id]
where: end_time IS NULL
unique: false
computed_fields:
duration:
type: interval
expression: end_time - start_time
stored: false
comments:
table: Work sessions for workers.
columns:
end_time: Null means the session is still open.
foreign_keys:
sessions_worker_fk: Each session belongs to one worker.
constraints:
end_after_start: End time must not be before start time.
indexes:
sessions_worker_id_idx: Supports joins from sessions to workers.

--- table:sessions:data
id,worker_id,start_time,end_time,hourly_pay,metadata
s_001,w_001,2026-01-01T09:00:00Z,2026-01-01T17:00:00Z,25.00,"{""source"":""manual""}"
s_002,w_001,2026-01-02T09:00:00Z,,25.00,"{""source"":""timer""}"

--- table:tags:schema
name: tags
columns:
label: text

--- table:tags:data
label
remote
manual

--- row_index:workers:id
strategy sorted_binary
w_001 1 46
w_002 2 50

--- row_index:sessions:id
strategy sorted_binary
s_001 1 86
s_002 2 65

--- section_index
csdb 320
table:workers:schema 900
table:workers:data 120
table:sessions:schema 1400
table:sessions:data 220
table:tags:schema 70
table:tags:data 20
row_index:workers:id 512
row_index:sessions:id 512
footer 991

--- footer
section_index_count 10