12.2.4 Model API ¶
The model definition API:
src_scheme[:exports code]((create-artanis-model model_name (:deps deps_list …) fields_def …))
The fields_def syntax is:
src_scheme[:exports code]((field_name type (options …)))
- Field Type
To unify API amoung all the DB backend supported by GNU Artanis, we provide abstract types:
- auto: auto incremental index
- tiny-integer:
- small-integer:
- big-integer: 0~2^64
- text: long text
- boolean:
- float
- double
- char-field: varchar
- you need to specify src_scheme[:exports code](#:maxlen positive_integer) in the options.
- date-field
- These options imply src_scheme[:exports code](#:no-edit)
- src_scheme[:exports code](#:auto-now)
- src_scheme[:exports code](#:auto-now-once)
NOTE: if these types can’t meet your requirements, just write the known type for your configured DB backend supported types, it will be passed directly to the backend, however, without the framework specific feature like type checking.
The options has specific syntax for different DB backend.
- MySQL/MariaDB options
The specific options are:
- src_scheme[:exports code](#:not-null)
- src_scheme[:exports code](#:null)
- src_scheme[:exports code](#:default) to speficy default value.
- src_scheme[:exports code](#:unique)
- src_scheme[:exports code](#:unique-key)
- src_scheme[:exports code](#:primary-key)
- src_scheme[:exports code](#:key) to specify keys.
- src_scheme[:exports code](#:auto-incremental)
- src_scheme[:exports code](#:comment) for commenting.
- src_scheme[:exports code](#:column-format)
- src_scheme[:exports code](#:storage mode) DISK or MEMORY mode.
- src_scheme[:exports code](#:signed)
- src_scheme[:exports code](#:unsigned)
- src_scheme[:exports code](#:zerofill)
- PostgreSQL options
PostgreSQL migration hasn’t been supported yet…patches are welcome.
- SQLite3 options
- src_scheme[:exports code](#:not-null)
- src_scheme[:exports code](#:null)
- src_scheme[:exports code](#:default value)
- src_scheme[:exports code](#:unique)
- src_scheme[:exports code](#:unique-key)
- src_scheme[:exports code](#:primary-key)
- src_scheme[:exports code](#:key)
- src_scheme[:exports code](#:auto-increment)
- src_scheme[:exports code](#:auto-now-once) for timestamp.