Copyright © Yariv Sadan 2006-2007
Authors: Yariv Sadan (yarivsblog@gmail.com) [web site: http://yarivsblog.com].
This module contains data structures and functions for exposing database fields' metadata.
After callingerlydb:codegen/3, generated modules contain a few
functions for getting database field metadata as well as transforming
records to iolists and setting their field values from strings. Those
functions use opaque erlydb_field structures, whose values can be
retrieved using the functions in this module. For more information,
refer to erlydb_base.
abstract datatype: erlydb_field()
An opaque structure holding database field metadata.
| attributes/1 | Get the field's user-defined attributes. |
| attributes/2 | Set the field's user-defined attributes. |
| default/1 | Get the field's default value. |
| erl_type/1 | Get the field's corresponding Erlang type. |
| extra/1 | Get the field's extra metadata. |
| html_input_type/1 | Get the field's default HTML input field type. |
| is_transient/1 | Transient flag of field's user-defined attributes. |
| key/1 | Get the field's key definition. |
| maxlength/1 | If this is a text field, get its max length. |
| modifier/1 | Get the field's modifier. |
| name/1 | Get the field's name. |
| name_bin/1 | Get the field's name as a binary. |
| name_str/1 | Get the field's name as a string. |
| new/0 | Create a new erlydb_field record. |
| new/6 | Create a new erlydb_field record initialized with the given values. |
| null/1 | Get the field's 'null' status. |
| options/1 | If this is an enum field, get its list of options. |
| type/1 | Get the field's type. |
attributes(Field::erlydb_field()) -> undefined | [term()]
Get the field's user-defined attributes.
attributes(Field::erlydb_field(), Attributes::[term()]) -> erlydb_field()
Set the field's user-defined attributes.
default(Field::erlydb_field()) -> undefined | term()
Get the field's default value.
erl_type(Field::erlydb_field()) -> binary | integer | float | date | time | datetime
Get the field's corresponding Erlang type. Possible values are 'binary', 'integer', 'float', 'date', 'time', and 'datetime'.
Date, time and datetime fields have the following forms:
{date, {Year, Month, Day}}
{time, {Hour, Minute, Second}}
{datetime, {{Year, Month, Day}, {Hour, Minute, Second}}}
extra(Field::erlydb_field()) -> undefined | identity
Get the field's extra metadata.
html_input_type(Field::erlydb_field()) -> text_field | text_area | select
Get the field's default HTML input field type. Possible values are 'text_field', 'text_area' and 'select'.
is_transient(Field::erlydb_field()) -> true | false
Transient flag of field's user-defined attributes.
key(Field::erlydb_field()) -> undefined | primary | unique | multiple
Get the field's key definition.
maxlength(Field::erlydb_field()) -> term()
If this is a text field, get its max length. This is identical to modifier/1.
modifier(Field::erlydb_field()) -> term()
Get the field's modifier.
name(Field::erlydb_field()) -> atom()
Get the field's name.
name_bin(Field::erlydb_field()) -> binary()
Get the field's name as a binary.
name_str(Field::erlydb_field()) -> string()
Get the field's name as a string.
new() -> erlydb_field()
Create a new erlydb_field record.
new(Name::atom(), Type::{Type::atom(), Modifier::term()}, Null::boolean(), Key::term(), Default::term(), Extra::term()) -> erlydb_field()
Create a new erlydb_field record initialized with the given values.
'Type' is the DBMS datatype, ('integer', 'varchar', etc.), represented as an atom.
'Modifier' is used to define the maximum length of the field, or the list of options for an enum field. This value is set to 'undefined' if it's not provided.
'Null' a boolean value indicating if the field is allowed to have a null value.
'Key' indicates if the field is used as a primary or a unique key. The possible values are 'primary', 'unique', 'multiple' and 'undefined'.
'Default' is the field's default value.
'Extra' is any additional information used to describe the field. Currently, the possible values are 'identity' and 'undefined'null(Field::erlydb_field()) -> boolean()
Get the field's 'null' status.
options(Field::erlydb_field()) -> term()
If this is an enum field, get its list of options. This is identical to modifier/1.
type(Field::erlydb_field()) -> term()
Get the field's type.