1 Tables
(require scone) | package: scone |
Tables are the core data type in scone, they represent simple tabular data in a similar manner to CSV files. There are two table types, row-oriented and column-oriented, although the former has more support at this time than the latter. Tables are intended to be as light-weight as possible with very simple schema-like definitions and to use a mix of lists and vectors for the main data.
1.1 Table Types
Layout
,-------------------------------------------------------------------, |
| vector | columndef | columndef | columndef | columndef | |
|-----------------+-----------+------------+------------+-----------| |
| list | vector | value | value | value | value | |
| | vector | value | value | value | value | |
| | vector | value | value | value | value | |
| | vector | value | value | value | value | |
'-------------------------------------------------------------------' |
struct
(struct columnar-table (def columns) #:transparent) def : tabledef? columns : (vectorof list?)
Layout
,----------------------------------------------------------, |
| vector | columndef | columndef | columndef | columndef | |
|--------+-----------+------------+------------+-----------| |
| vector | list | list | list | list | |
| |-----------+------------+------------+-----------| |
| | value | value | value | value | |
| | value | value | value | value | |
| | value | value | value | value | |
'----------------------------------------------------------' |
procedure
(table-name table) → table-name/c
table : table-type/c
procedure
(table-columns table) → (listof columndef?)
table : table-type/c
procedure
(table-column-count table) → exact-nonnegative-integer?
table : table-type/c
procedure
(table-has-column? table name) → boolean?
table : table-type/c name : column-name/c
procedure
(table-column-def table name)
→ (or/c (cons/c exact-nonnegative-integer? columndef?) #f) table : table-type/c name : column-name/c
procedure
(table-column-index table name)
→ (or/c exact-nonnegative-integer? #f) table : table-type/c name : column-name/c
procedure
(table-row-count table) → exact-nonnegative-integer?
table : table-type/c
1.1.1 Rows and Values
procedure
(row-validate tabledef row) → row/c
tabledef : tabledef? row : row/c
1.2 Table Definition
A table definition structure, tabledef, acts as the schema for a table or columnar-table.
struct
(struct tabledef (name columns) #:transparent) name : column-name/c columns : (listof columndef?)
constructor
(make-tabledef columns [name]) → tabledef?
columns : (listof columndef-from/c) name : table-name/c = (next-table-name)
constructor
(make-tabledef-from row) → tabledef?
row : row/c
procedure
def : tabledef?
procedure
(tabledef-has-column? def name) → boolean?
def : tabledef? name : column-name/c
procedure
(tabledef-column-def def name)
→ (or/c (cons/c exact-nonnegative-integer? columndef?) #f) def : tabledef? name : column-name/c
procedure
(tabledef-column-index def name)
→ (or/c exact-nonnegative-integer? #f) def : tabledef? name : column-name/c
procedure
(next-table-name) → (table-name/c)
1.3 Column Definition
A column definition structure, columndef, acts as the schema for a single column within a table’s tabledef.
struct
(struct columndef (name data-type is-list) #:transparent) name : column-name/c data-type : data-type/c is-list : boolean?
constructor
(make-columndef name [data-type is-list?]) → columndef?
name : column-name/c data-type : data-type/c = (default-column-data-type) is-list? : boolean/c = #f
constructor
(make-columndef-from value index) → columndef?
value : value/c index : exact-nonnegative-integer?
1.4 Table Contracts
contract
(columndef-from/c value) → boolean?
value : any/c
(or/c column-name/c (list/c column-name/c) (list/c column-name/c data-type/c) (list/c column-name/c data-type/c boolean?))
contract
(column-name/c value) → boolean?
value : any/c
contract
(data-type/c value) → boolean?
value : any/c
'boolean, accepts the standard boolean values #t and #f
'number, accepts any numeric value
'string, accepts any string value
'symbol, accepts any symbol value
contract
(table-name/c value) → boolean?
value : any/c
contract
(table-type/c value) → boolean?
value : any/c
1.5 Table Defaults
parameter
(default-column-data-type data-type) → void? data-type : data-type/c
= 'string
parameter
(default-column-prefix column-prefix) → void? column-prefix : column-name/c
= 'column
parameter
(default-table-name table-name) → void? table-name : table-name/c
= 'unnamed