theorm
v0.2.13
Published
Nodejs MySQL ORM
Downloads
14
Readme
theorm
Javascript Object-Relational Mapper (This is still a work in progress)
Primitive Model Property Types
type.bool
This will store a boolean true/false value to the database. Unless configured otherwise, the value will default to false.
field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "tinyint(3) unsigned")
default_value: {db_default_value} (default 0)
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'boolean' })
type.bool_true
default_value: true
type.bool_false
default_value: false
type.int
This will store an integer number to the database. The default is to store a 4-byte signed integer.
field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "int(11)")
default_value: {db_default_value} (default 0)
auto_increment: {db_auto_increment} (default false)
primary_key: {db_primary_key} (default false)
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'integer' })
type.uint : extends type.int
data_type: 'int(10) unsigned'
search_mapping: { type: 'integer' }
type.tiny_int : extends type.int
data_type: 'tinying(4)
search_mapping: { type: 'byte' }
type.tiny_uint : extends type.int
data_type: 'tinyint(3) unsigned'
search_mapping: { type: 'byte' }
type.small_int : extends type.int
data_type: 'smallint(6)'
search_mapping: { type: 'short' }
type.small_uint : extends type.int
data_type: 'smallint(5) unsigned'
search_mapping: { type: 'short' }
type.medium_int : extends type.int
data_type: 'mediumint(9)
search_mapping: { type: 'integer' }
type.medium_int : extends type.int
data_type: 'mediumint(8) unsigned'
search_mapping: { type: 'integer' }
type.big_int : extends type.int
data_type: 'bigint(20)'
search_mapping: { type: 'long' }
type.big_uint : extends type.int
data_type: 'bigint(19) unsigned'
search_mapping: { type: 'long' }
type.int_key : extends type.int
index: true
type.tiny_key : extends type.int
index: true
type.small_key : extends type.int
index: true
type.medium_key : extends type.int
index: true
type.big_key : extends type.int
index: true
type.primary_key : extends type.uint
auto_increment: true
primary_key: true
type.tiny_primary_key : extends type.uint
auto_increment: true
primary_key: true
type.small_primary_key : extends type.small_uint
auto_increment: true
primary_key: true
type.medium_primary_key : extends type.medium_uint
auto_increment: true
primary_key: true
type.big_primary_key : extends type.big_uint
auto_increment: true
primary_key: true
type.char
This will store a short character string to the database. Unless the size option is set, it will default to a one byte character.
size: {db_column_type_size} (default 1)
field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "char(<size>)")
primary_key: {db_primary_key} (default false)
string_key: {model_string_key} (default false)
default_value: {db_default_value} (default '')
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'string' })
type.varchar : extends type.char
size: 255
data_type: 'varchar(size)'
type.binary : extends type.char
size: 255
data_type: 'binary(size)'
type.varbinary : extends type.char
size: 255
data_type: 'varbinary(size)'
type.blob : extends type.char
data_type: 'blobl'
type.blob_tiny : extends type.char
data_type: 'tinyblob'
type.blob_medium : extends type.char
data_type: 'mediumblob'
type.blob_long : extends type.char
data_type: 'tinyblob'
type.text : extends type.char
data_type: 'text'
type.text_tiny : extends type.char
data_type: 'tinytext'
type.text_medium : extends type.char
data_type: 'mediumtet'
type.text_long : extends type.char
data_type: 'longtext'
type.varchar_key : extends type.varchar
index: 16
type.string_key : extends type.varchar
string_key: 8
type.date
This will store a date to the database. By changing the format and data_type, it can easily be adapted to store a datetime.
format: {db_field_format} (default to "YYYY-MM-DD")
field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "date")
primary_key: {db_primary_key} (default false)
default_value: {db_default_value} (default '0000-00-00')
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'date', format: 'YYYY-MM-dd HH:mm:ss' })
type.date_time : extends type.date
data_type: 'datetime'
format: 'YYYY-MM-DD HH:mm:ss'
default_value: '0000-00-00 00:00:00'
type.create_time : extends type.date_time
update: 2 (Never update, only create)
type.update_time : extends type.date_time
update: 1 (Always update, including create)
type.timestamp : extends type.date_time
data_type: 'timestamp'
default_value: 'CURRENT_TIMESTAMP'
update_timestamp: 'on update CURRENT_TIMESTAMP'
type.date_time_key : extends type.date_time
index: true
type.create_time_key : extends type.create_time
index: true
type.update_time_key : extends type.update_time
index: true
type.timestamp_key : extends type.timestamp
index: true
type.json
This will store a javascript object to the database as a json string. By default, it uses a text blob for storage, so can store up to 64K of serialized json.
field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default "text")
default_value: {db_default_value} (default '')
allow_null: {db_allow_null} (default false)
search: {search_enable} (default false)
search_mapping: {search_mapping_type} (default { type: 'object' })
type.password
This will encrypt a password using bcrypt
field: {db_field_type} (default to property name)
index: {db_column_index} (default false)
data_type: {db_column_type} (default 'varchar(255)')
default_value: {db_default_value} (default '')
allow_null: {db_allow_null} (default false)
Relational Model Property Types
type.one_to_one
This will establish a one-to-one relationship bwetween this model and a target model
TODO
type.many_to_one
This will establish a many-to-one relationship between a property of this model and a target model
model: {target_model_name} (Defaults to name derived from poperty name)
field: {db_field_type} (Defaults name derived from target model & property name)
index: {db_column_index} (default false)
data_type: {db_field_type} (Defaults to type of foreign_model's primary key)
default_value: {db_default_value} (default '0')
allow_null: {db_allow_null} (default false)
primary_key: {db_primary_key} (default false)
search: {search_enable} (default false | can be 'field' or ['field1','field2'...])
search_mapping: {search_mapping_type} (default { type: <search_type> })
search_type: {search_type} (Specify as 'key' or ['field1','field2'...])
type.foreign_key : extends type.many_to_one
index: true
type.foreign_primary_key : extends type.many_to_one
primary_key: true
type.one_to_many
This will establish a one-to-many relationship with aother model
model: {target_model_name} (Defaults to name derived from poperty name)
key: {target_model_key} (Defaults to current model name singularized, with _id)
type.many_to_many
This will establish a many-to-many relationship between a linking model and a target model
map: {linking_model_name} (Defaults to current model name singularized + target model name)
model: {target_model_name} (Defaults to name derived from poperty name)
search: {search_enable} (default false | can be 'field' or ['field1','field2'...])
key: {target_model_key} (Defaults to current model name singularized, with _id)