Skip to main content

createdbtable

createdbtable(
@data ? ## llll (required)
@name 'data'
@db null
) -> null

Creates and populates a SQLite3 table with data entries. Each element or entry in @data should be structured as a llll of key-value pairs, where each key corresponds to a column name in the resulting table and each value is the corresponding data entry. For example:

expected structure for each data entry
[ ## item 1
[ <key_1> <value_1> ]
[ <key_2> <value_2> ]
...
[ <key_N> <value_N> ]
]
...
[ ## item N
[ <key_1> <value_1> ]
[ <key_2> <value_2> ]
...
[ <key_N> <value_N> ]
]

This format ensures that the resulting table can be queried using standard SQL-style syntax, with each key becoming a column in the table schema.


Arguments

  • @data ? [llll]: Data from which to build SQL table, each element structured as a list of key-value pairs. (required)
  • @name [symbol]: SQL Table name, to be used with querydb. For instance, for a table named 'mytable', a basic query would be 'SELECT * FROM mytable'. (default: 'data').
  • @db [symbol/null]: Optional database name. If set to null, 'main' is used as the default database name. (default: null).

Usage

## import MIDI events to use as data
$events = importmidi('bach.mid');
## create `notes` table based on MIDI events
createdbtable(@data $events @name 'notes');
## Use SQL query to retrieve all events with pitch class 0
$results = querydb('SELECT * FROM notes WHERE pitch % 1200 == 0');
print($results) ## print results