DbReference - do-/node-doix-db GitHub Wiki
DbReference is an object representing the fact that values stored in some DbColumn are unambiguously tied to records in some relation in the same database.
For regular tables, it can be used to build a corresponding foreign key.
For other table like objects (SQL views etc.) foreign keys may not be available, but DbReference still can be used to perform automatic query building and similar tasks.
Properties
| Name | Type | Description | Note |
|---|---|---|---|
column |
DbColumn | parent to this reference | |
targetSchemaName |
String |
Name of the schema targeted by this reference. null for default model's schema, undefined for same schema (local reference) |
|
targetSchema |
DbSchema | The schema targeted by this reference | fetched by targetSchemaName |
targetRelationName |
String |
Name of the relation targeted by this reference | |
targetRelation |
DbRelation | The relation targeted by this reference | fetched by targetRelationName |
targetColumnName |
String |
Name of the column targeted by this reference | inferred by targetRelation.pk |
targetColumn |
DbColumn | The column targeted by this reference | fetched by targetColumnName |
on |
Object |
Actions to use by the foreign key | |
on.DELETE |
String |
Action for the the foreign key's ON DELETE clause |
Domain-specific language
The class implements a tiny DSL to build DbReference objects from formatted strings
reference ::= "(" on_delete? relation ")"
relation ::= (targetSchemaName ".")? targetRelationName
on_delete ::= ("-" | "~")
where
targetSchemaNameis either a schema name or an empty string (for the default schema);targetRelationNameis the name of some relation in the corresponding schema;on_deleteis translated toon.DELETEasCASCADEfor"-"SET DEFAULTfor"~"when the parent column has a default value;SET NULLfor"~"otherwise.
Constructor
Normally, called by the DbColumn constructor. Can accept the 1st parameter in two forms:
- an Object to copy to
this - or a
Stringto parse
const ref = new DbReference ({relation: 'users', on: {DELETE: 'CASCADE'}}, parentColumn)
// or
const ref = new DbReference ('(-users)', parentColumn)
Methods
parse ()
Parses this.src (where the constructor puts the 1st string argument) into local properties. Used by the constructor itself.