Module erlydb_field

This module contains data structures and functions for exposing database fields' metadata.

Copyright © Yariv Sadan 2006-2007

Authors: Yariv Sadan (yarivsblog@gmail.com) [web site: http://yarivsblog.com].

Description

This module contains data structures and functions for exposing database fields' metadata.

After calling erlydb: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.

Data Types

erlydb_field()

abstract datatype: erlydb_field()

An opaque structure holding database field metadata.

Function Index

attributes/1Get the field's user-defined attributes.
attributes/2Set the field's user-defined attributes.
default/1Get the field's default value.
erl_type/1Get the field's corresponding Erlang type.
extra/1Get the field's extra metadata.
html_input_type/1Get the field's default HTML input field type.
is_transient/1Transient flag of field's user-defined attributes.
key/1Get the field's key definition.
maxlength/1If this is a text field, get its max length.
modifier/1Get the field's modifier.
name/1Get the field's name.
name_bin/1Get the field's name as a binary.
name_str/1Get the field's name as a string.
new/0Create a new erlydb_field record.
new/6Create a new erlydb_field record initialized with the given values.
null/1Get the field's 'null' status.
options/1If this is an enum field, get its list of options.
type/1Get the field's type.

Function Details

attributes/1

attributes(Field::erlydb_field()) -> undefined | [term()]

Get the field's user-defined attributes.

attributes/2

attributes(Field::erlydb_field(), Attributes::[term()]) -> erlydb_field()

Set the field's user-defined attributes.

default/1

default(Field::erlydb_field()) -> undefined | term()

Get the field's default value.

erl_type/1

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/1

extra(Field::erlydb_field()) -> undefined | identity

Get the field's extra metadata.

html_input_type/1

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/1

is_transient(Field::erlydb_field()) -> true | false

Transient flag of field's user-defined attributes.

key/1

key(Field::erlydb_field()) -> undefined | primary | unique | multiple

Get the field's key definition.

maxlength/1

maxlength(Field::erlydb_field()) -> term()

If this is a text field, get its max length. This is identical to modifier/1.

modifier/1

modifier(Field::erlydb_field()) -> term()

Get the field's modifier.

name/1

name(Field::erlydb_field()) -> atom()

Get the field's name.

name_bin/1

name_bin(Field::erlydb_field()) -> binary()

Get the field's name as a binary.

name_str/1

name_str(Field::erlydb_field()) -> string()

Get the field's name as a string.

new/0

new() -> erlydb_field()

Create a new erlydb_field record.

new/6

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/1

null(Field::erlydb_field()) -> boolean()

Get the field's 'null' status.

options/1

options(Field::erlydb_field()) -> term()

If this is an enum field, get its list of options. This is identical to modifier/1.

type/1

type(Field::erlydb_field()) -> term()

Get the field's type.