-
Notifications
You must be signed in to change notification settings - Fork 2
DbColumn
DbColumn is an object describing a column of a relation in a database.
| Name | Type | Description |
|---|---|---|
relation |
DbRelation | Table, view etc. which this column belongs to |
name |
String |
Logical name (identifier) of this column |
qName |
String |
Quoted name of this column, good for SQL (DDL etc.) |
comment |
String |
Comment for this column |
reference |
DbReference | (if present) |
type |
String |
Name of the data type |
typeDef |
DbType | The result of DbLang's getTypeDefinition ()
|
typeDim |
String |
${type}[(${size}[,${scale}])] |
size |
int |
Maximum size of the data (length for VARCHAR, precision for DECIMAL etc.). The exact meaning (units etc.) and the mere existence meaning depends of the type. |
scale |
int |
For DECIMAL, his synonyms and/or derived types, (NUMERIC etc.) means the length of the fractional part. Must be absent for other types. |
default |
String |
If non-null, this string is to be interpolated into the DEFAULT clause of the corresponding CREATE/ALTER TABLE statement. |
nullable |
Boolean |
false for NOT NULL columns, true otherwise. |
min |
String |
The minimal allowed value. Corresponds to the HTML INPUT's min attribute. May be used in autogenerated validation procedures, forwarded to UI components etc. |
max |
String |
The maximal allowed value. Corresponds to the HTML INPUT's max attribute. May be used in autogenerated validation procedures, forwarded to UI components etc. |
pattern |
String |
The regular expression to test values against. Corresponds to the HTML INPUT's pattern attribute. May be used in autogenerated validation procedures, forwarded to UI components etc. |
The class implements a tiny DSL to build DbColumn objects from formatted strings.
column ::= ( physical | reference ) nullable? ("=" default)? range? re? ("//" comment )?
physical ::= type dimension?
dimension ::= "(" size ("," scale)? ")"
nullable ::= "?" | "!"
range ::= "{" min? ".." max? "}"
re ::= "/" pattern "/"
Where:
- for
reference, see DbReference; -
sizeandscale, if present, must be positive integer decimal numbers not starting with0; - when the
rangeis specified,minormaxmay be omitted, but not both -
default,minandmaxliterals are not delimited, so they must not contain any special characters used by delimiters by the DSL itself (e. g.maxcan't contain'}', but no ordinal type allow such constants, so it's not really a restriction). Round braces (and so, function calls, compound expressions etc.) are allowed indefault. - the
nullableavailability and meaning depends ondefault:
nullable |
deault |
example | The column is... |
|---|---|---|---|
| int | NULLABLE | ||
| defined | int = 0 | NOT NULL | |
! |
int! | NOT NULL | |
? |
defined | int ?= 0 | NULLABLE |
? |
n/a | ||
! |
defined | n/a |
Can accept the 1st parameter in two forms:
- an Object to copy to
this - or a
Stringto parse
const ref = new DbColumn ({type: 'int', comment: 'ID', default: '0', nullable: false})
// or
const ref = new DbColumn ('int=0 // ID')Parses this.src (where the constructor puts the 1st string argument) into local properties. Used by the constructor.
Slices the this.type part after = into this.default. Used by the constructor.
Slices the this.default or this.type part between the last two /s into this.default. Used by the constructor.
Slices the this.default or this.type part between { and } into this.default. Used by the constructor.
Set the nullable property based on this.default and the last character of this.type. Used by the constructor.
Parses this.type into this.type per se, this.size and this.scale. Used by the constructor.
For the given DbQuery, returns a new DbQueryColumn instance bound to it and representing this column.
With the given DbLang lang, calculates all properties specific to this language/dialect.
In the base implementation:
- sets
qNametolang.quoteName (this.name); - if
typeis defined (which is not the case withreference):- sets
typeDeftolang.getTypeDefinition (this.type); - resets
typetotypeDef.name(so it gets normalized); - sets
typeDimtolang.getDbColumnTypeDim (this).
- sets