Constructor
new Schema(keyColumnName, propertyName, convert)
Initialize the Schema instance.
Parameters:
Name | Type | Description |
---|---|---|
keyColumnName |
string | The name of the unique key column, generally the primary key. |
propertyName |
string | An optional mapping for the key column. Defaults to the same name as the key column. |
convert |
function | An optional convert function that takes in the value associated the key column and converts it. For example, a function that converts a bit to a boolean, or a native Date object to a string. |
- Source:
Members
(static, constant) RELATIONSHIP_TYPE :Object
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
MANY |
string | Map to an array. |
SINGLE |
string | Map to an object. |
- Source:
Methods
addProperties(propertyNames) → {this}
Short-hand notation for adding properties. An array can be used, or a
series of strings (variadic).
Parameters:
Name | Type | Description |
---|---|---|
propertyNames |
Array.<string> | An array of property names. |
- Source:
Returns:
- Type
- this
addProperty(columnName, propertyNamea, convert) → {this}
Add a property to the schema.
Parameters:
Name | Type | Description |
---|---|---|
columnName |
string | The name of the database column. |
propertyNamea |
string | The name of the property in the resulting object. Defaults to the property name. |
convert |
function | An optional convert function that takes in the value associated the column and converts it. |
- Source:
Returns:
- Type
- this
addSchema(propertyName, schema, relationshipType) → {this}
Add a sub schema, which is a related table and will be nested under this
schema using propertyName.
Parameters:
Name | Type | Description |
---|---|---|
propertyName |
string | The name of the sub schema property. |
schema |
Schema | A Schema instance. |
relationshipType |
Schema.RELATIONSHIP_TYPE | The type of relationship, either single (object) or many (array). Defaults to Schema.RELATIONSHIP_TYPE.MANY. |
- Source:
Returns:
- Type
- this
getKeyColumnName() → {string}
Get the name of the key column.
- Source:
Returns:
The name of the key column.
- Type
- string
getProperties() → {Array.<Object>}
Get the array of properties. Each property has the column name and the
property name.
- Source:
Returns:
An array of properties, each with a propertyName,
columnName, and convert function.
- Type
- Array.<Object>
getSchemata() → {Array.<Object>}
Get the array of schemata, each of which has a property name and a Schema
instance.
- Source:
Returns:
An array of objects, each with a property name and
a Schema instance.
- Type
- Array.<Object>