12.2.2 Define table in Model

In this example, we craete a table like this:

+-------------------------------------------------------------+
| Field | Type        | Null | Key | Default | Extra          |
|-------+-------------+------+-----+---------+----------------|
| id    | auto        | NO   | PRI | NULL    | auto_increment |
| name  | char-field  | NO   |     | NULL    |                |
| email | char-field  | NO   |     | NULL    |                |
+-------------------------------------------------------------+

For Model definition syntax in GNU Artanis, we have:

(create-artanis-model
 user  ; model name
 (:deps) ; deps list
 (id auto (#:primary-key))
 (name char-field (#:not-null #:maxlen 128))
 (email char-field (#:not-null #:maxlen 128))
 )

NOTE: If you have definition, and you’ve imported in any controller, when booting GNU Artanis with src_scheme[:exports code](art work), then the defined table will be created automatically in the specified database. Don’t worry, it will be created only once.

NOTE: The Model name must be the same with Model file’s name.