mythix-orm 1.5.6 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/connection/connection-base.d.ts +180 -0
- package/lib/connection/connection-base.js +242 -16
- package/lib/connection/index.d.ts +5 -0
- package/lib/connection/literals/average-literal.d.ts +5 -0
- package/lib/connection/literals/count-literal.d.ts +5 -0
- package/lib/connection/literals/distinct-literal.d.ts +5 -0
- package/lib/connection/literals/field-literal.d.ts +5 -0
- package/lib/connection/literals/index.d.ts +10 -0
- package/lib/connection/literals/literal-base.d.ts +22 -0
- package/lib/connection/literals/literal-base.js +2 -2
- package/lib/connection/literals/literal-field-base.d.ts +17 -0
- package/lib/connection/literals/literal-field-base.js +4 -4
- package/lib/connection/literals/literal.d.ts +5 -0
- package/lib/connection/literals/max-literal.d.ts +5 -0
- package/lib/connection/literals/min-literal.d.ts +5 -0
- package/lib/connection/literals/sum-literal.d.ts +5 -0
- package/lib/connection/query-generator-base.d.ts +121 -0
- package/lib/connection/query-generator-base.js +5 -6
- package/lib/field.d.ts +61 -0
- package/lib/field.js +9 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +7 -1
- package/lib/interfaces/common.ts +3 -0
- package/lib/model.d.ts +205 -0
- package/lib/model.js +136 -32
- package/lib/proxy-class/proxy-class.js +6 -6
- package/lib/query-engine/index.d.ts +1 -0
- package/lib/query-engine/model-scope.js +2 -2
- package/lib/query-engine/query-engine-base.js +2 -2
- package/lib/query-engine/query-engine.d.ts +144 -0
- package/lib/query-engine/query-engine.js +4 -0
- package/lib/types/concrete/bigint-type.d.ts +16 -0
- package/lib/types/concrete/bigint-type.js +8 -5
- package/lib/types/concrete/blob-type.d.ts +11 -0
- package/lib/types/concrete/blob-type.js +5 -4
- package/lib/types/concrete/boolean-type.d.ts +11 -0
- package/lib/types/concrete/boolean-type.js +4 -4
- package/lib/types/concrete/char-type.d.ts +11 -0
- package/lib/types/concrete/char-type.js +4 -4
- package/lib/types/concrete/date-type.d.ts +16 -0
- package/lib/types/concrete/date-type.js +9 -4
- package/lib/types/concrete/datetime-type.d.ts +16 -0
- package/lib/types/concrete/datetime-type.js +9 -4
- package/lib/types/concrete/foreign-key-type.d.ts +32 -0
- package/lib/types/concrete/foreign-key-type.js +274 -10
- package/lib/types/concrete/index.d.ts +19 -0
- package/lib/types/concrete/index.js +2 -0
- package/lib/types/concrete/integer-type.d.ts +16 -0
- package/lib/types/concrete/integer-type.js +6 -4
- package/lib/types/concrete/numeric-type.d.ts +11 -0
- package/lib/types/concrete/numeric-type.js +6 -4
- package/lib/types/concrete/real-type.d.ts +11 -0
- package/lib/types/concrete/real-type.js +111 -4
- package/lib/types/concrete/serialized-type.d.ts +25 -0
- package/lib/types/concrete/serialized-type.js +287 -5
- package/lib/types/concrete/string-type.d.ts +11 -0
- package/lib/types/concrete/string-type.js +0 -4
- package/lib/types/concrete/text-type.d.ts +11 -0
- package/lib/types/concrete/text-type.js +0 -4
- package/lib/types/concrete/uuid-base.d.ts +13 -0
- package/lib/types/concrete/uuid-base.js +4 -1
- package/lib/types/concrete/uuid-v1-type.d.ts +31 -0
- package/lib/types/concrete/uuid-v1-type.js +0 -4
- package/lib/types/concrete/uuid-v3-type.d.ts +27 -0
- package/lib/types/concrete/uuid-v3-type.js +0 -4
- package/lib/types/concrete/uuid-v4-type.d.ts +27 -0
- package/lib/types/concrete/uuid-v4-type.js +0 -4
- package/lib/types/concrete/uuid-v5-type.d.ts +27 -0
- package/lib/types/concrete/uuid-v5-type.js +0 -4
- package/lib/types/concrete/xid-type.d.ts +17 -0
- package/lib/types/concrete/xid-type.js +0 -4
- package/lib/types/helpers/default-helpers.d.ts +61 -0
- package/lib/types/helpers/index.d.ts +1 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.js +2 -0
- package/lib/types/type.d.ts +89 -0
- package/lib/types/type.js +57 -25
- package/lib/types/virtual/index.d.ts +4 -0
- package/lib/types/virtual/model-type.d.ts +15 -0
- package/lib/types/virtual/model-type.js +2 -2
- package/lib/types/virtual/models-type.d.ts +15 -0
- package/lib/types/virtual/models-type.js +5 -5
- package/lib/types/virtual/relational-type-base.d.ts +46 -0
- package/lib/types/virtual/relational-type-base.js +12 -20
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +1 -4
- package/lib/utils/misc-utils.d.ts +4 -0
- package/lib/utils/misc-utils.js +0 -35
- package/lib/utils/model-utils.d.ts +90 -0
- package/lib/utils/model-utils.js +4 -4
- package/lib/utils/query-utils.d.ts +11 -0
- package/package.json +3 -2
- package/.biblorc.js +0 -29
- package/docs/Associations.md +0 -539
- package/docs/Certifications.md +0 -22
- package/docs/Home.md +0 -54
- package/docs/Query Engine.md +0 -428
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import ConnectionBase from '../../connection/connection-base';
|
|
2
|
+
import Field from '../../field';
|
|
3
|
+
import { ModelClass } from '../../model';
|
|
4
|
+
import Type, { TypeWrapper } from '../type';
|
|
5
|
+
|
|
6
|
+
export declare interface ForeignKeyTypeWrapper extends TypeWrapper<ForeignKeyType> {
|
|
7
|
+
(fullyQualifiedName: string | ForeignKeyTypeOptions, options?: ForeignKeyTypeOptions): ForeignKeyType;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export declare interface ForeignKeyTypeOptions {
|
|
11
|
+
Field?: Field;
|
|
12
|
+
modelName?: string;
|
|
13
|
+
fieldName?: string;
|
|
14
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT' | 'RESTRICT'
|
|
15
|
+
onUpdate?: 'CASCADE' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT' | 'RESTRICT'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare class ForeignKeyType extends Type {
|
|
19
|
+
public constructor(fullyQualifiedName: string | ForeignKeyTypeOptions, options?: ForeignKeyTypeOptions);
|
|
20
|
+
public parseOptionsAndCheckForErrors(SourceModel: ModelClass, sourceField: Field, connection: ConnectionBase): { Model: ModelClass, Field: Field };
|
|
21
|
+
public getOptions(): ForeignKeyTypeOptions;
|
|
22
|
+
public getTargetModel(connection?: ConnectionBase): ModelClass;
|
|
23
|
+
public getTargetModelName(connection?: ConnectionBase): string;
|
|
24
|
+
public getTargetField(connection?: ConnectionBase): Field;
|
|
25
|
+
public getTargetFieldName(connection?: ConnectionBase): string;
|
|
26
|
+
|
|
27
|
+
declare public targetModel: ModelClass | undefined;
|
|
28
|
+
declare public targetField: Field | undefined;
|
|
29
|
+
declare public fullyQualifiedName: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const FOREIGN_KEY: ForeignKeyTypeWrapper;
|
|
@@ -4,19 +4,127 @@ const Nife = require('nife');
|
|
|
4
4
|
const Type = require('../type');
|
|
5
5
|
const ModelUtils = require('../../utils/model-utils');
|
|
6
6
|
|
|
7
|
+
/// `FOREIGN_KEY` type.
|
|
8
|
+
///
|
|
9
|
+
/// This represents a foreign key to another column. It takes
|
|
10
|
+
/// on the type of the column it points to. For example, if it
|
|
11
|
+
/// points to an INTEGER column, then it will also be the same
|
|
12
|
+
/// type of integer.
|
|
13
|
+
///
|
|
14
|
+
/// Foreign keys are one of the ways Mythix ORM knows that models
|
|
15
|
+
/// are related, along with the `Model` and `Models` virtual types.
|
|
16
|
+
/// The "target" field must be a fully qualified field name. A
|
|
17
|
+
/// fully qualified field name is a name that is also prefixed by
|
|
18
|
+
/// the model that owns it. For example, `'User:firstName'` would
|
|
19
|
+
/// be a fully qualified field name, but `'firstName'` would not be.
|
|
20
|
+
///
|
|
21
|
+
/// Client-side storage for this field will be backed by
|
|
22
|
+
/// the same type as the field the foreign key targets.
|
|
23
|
+
///
|
|
24
|
+
/// Example:
|
|
25
|
+
/// class Role extends Model {
|
|
26
|
+
/// static fields = {
|
|
27
|
+
/// userID: {
|
|
28
|
+
/// type: Types.FOREIGN_KEY('User:id', {
|
|
29
|
+
/// onDelete: 'CASCADE',
|
|
30
|
+
/// onUpdate: 'CASCADE',
|
|
31
|
+
/// }),
|
|
32
|
+
/// allowNull: false,
|
|
33
|
+
/// },
|
|
34
|
+
/// roleMetaID: {
|
|
35
|
+
/// type: Types.FOREIGN_KEY({
|
|
36
|
+
/// modelName: 'RoleMeta',
|
|
37
|
+
/// fieldName: 'id',
|
|
38
|
+
/// onDelete: 'CASCADE',
|
|
39
|
+
/// onUpdate: 'CASCADE',
|
|
40
|
+
/// }),
|
|
41
|
+
/// allowNull: false,
|
|
42
|
+
/// },
|
|
43
|
+
/// };
|
|
44
|
+
/// }
|
|
45
|
+
///
|
|
46
|
+
/// See: Type
|
|
7
47
|
class ForeignKeyType extends Type {
|
|
48
|
+
/// Check if this is a foreign key type.
|
|
49
|
+
///
|
|
50
|
+
/// There are multiple different "type checking"
|
|
51
|
+
/// static methods that exist for all field types.
|
|
52
|
+
/// This is one of them. It checks if the type
|
|
53
|
+
/// class is a foreign key type. This returns
|
|
54
|
+
/// `true` for `FOREIGN_KEY`.
|
|
55
|
+
///
|
|
56
|
+
/// Return: boolean
|
|
57
|
+
/// Return `true`, as the `FOREIGN_KEY` type is a
|
|
58
|
+
/// foreign key field.
|
|
8
59
|
static isForeignKey() {
|
|
9
60
|
return true;
|
|
10
61
|
}
|
|
11
62
|
|
|
63
|
+
/// Get the "display" name for this type.
|
|
64
|
+
///
|
|
65
|
+
/// This method is called from <see>Model.toString</see>
|
|
66
|
+
/// when stringifying the model for representation.
|
|
67
|
+
///
|
|
68
|
+
/// Note:
|
|
69
|
+
/// This is also an instance method that can be called from
|
|
70
|
+
/// an instance of the type.
|
|
71
|
+
///
|
|
72
|
+
/// Return: string
|
|
73
|
+
/// Return the string value `'FOREIGN_KEY'`
|
|
12
74
|
static getDisplayName() {
|
|
13
75
|
return 'FOREIGN_KEY';
|
|
14
76
|
}
|
|
15
77
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
78
|
+
/// Construct a new `ForeignKeyType` type.
|
|
79
|
+
///
|
|
80
|
+
/// This constructor has two call patterns.
|
|
81
|
+
/// First, it can be called the shorthand way
|
|
82
|
+
/// with a string (a fully qualified field name)
|
|
83
|
+
/// as the first argument, and the field `options`
|
|
84
|
+
/// as the second argument. Or, you can simply pass
|
|
85
|
+
/// a single `options` argument, that must contain
|
|
86
|
+
/// a `modelName` and `fieldName` property that are
|
|
87
|
+
/// strings.
|
|
88
|
+
///
|
|
89
|
+
/// Interface:
|
|
90
|
+
/// interface ForeignKeyTypeOptions {
|
|
91
|
+
/// // A direct field from a model, used for the target field
|
|
92
|
+
/// // directly. i.e. `Field: User.fields.id`.
|
|
93
|
+
/// // If this is present and valid then it
|
|
94
|
+
/// // will supersede the `modelName` and `fieldName`
|
|
95
|
+
/// // properties.
|
|
96
|
+
/// Field?: Field;
|
|
97
|
+
///
|
|
98
|
+
/// // The model name that owns the target field
|
|
99
|
+
/// modelName?: string;
|
|
100
|
+
///
|
|
101
|
+
/// // The field name of the target field on the
|
|
102
|
+
/// // target `modelName`.
|
|
103
|
+
/// fieldName?: string;
|
|
104
|
+
///
|
|
105
|
+
/// // onDelete specifies what action to take when
|
|
106
|
+
/// // a row in the target table is deleted.
|
|
107
|
+
/// onDelete?: 'CASCADE' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT' | 'RESTRICT'
|
|
108
|
+
///
|
|
109
|
+
/// // onUpdate specifies what action to take when
|
|
110
|
+
/// // a row in the target table is updated
|
|
111
|
+
/// // (specifically the target column).
|
|
112
|
+
/// onUpdate?: 'CASCADE' | 'SET NULL' | 'NO ACTION' | 'SET DEFAULT' | 'RESTRICT'
|
|
113
|
+
/// }
|
|
114
|
+
///
|
|
115
|
+
/// Return: ForeignKeyType
|
|
116
|
+
/// A new instance of the `ForeignKeyType` type.
|
|
117
|
+
///
|
|
118
|
+
/// Arguments:
|
|
119
|
+
/// fullyQualifiedName: string | object
|
|
120
|
+
/// 1) The fully qualified name of the target field as
|
|
121
|
+
/// a string (i.e. `'User:id'`), optionally followed
|
|
122
|
+
/// an `options` argument, or 2) the one and only
|
|
123
|
+
/// `options` argument requiring `modelName` and
|
|
124
|
+
/// `fieldName` properties.
|
|
125
|
+
/// options?: object
|
|
126
|
+
/// If `fullyQualifiedName` is defined as a string, then
|
|
127
|
+
/// this will be the options to the field.
|
|
20
128
|
constructor(_fullyQualifiedName, _options) {
|
|
21
129
|
if (arguments.length === 0)
|
|
22
130
|
throw new TypeError('ForeignKeyType::constructor: You must specify a fully qualified field name, or provide complete options.');
|
|
@@ -49,6 +157,22 @@ class ForeignKeyType extends Type {
|
|
|
49
157
|
this.fullyQualifiedName = fullyQualifiedName;
|
|
50
158
|
}
|
|
51
159
|
|
|
160
|
+
/// Cast provided value to underlying type.
|
|
161
|
+
///
|
|
162
|
+
/// This will cast the incoming value to the
|
|
163
|
+
/// underlying type of this field, which is
|
|
164
|
+
/// the type of the field that it targets.
|
|
165
|
+
///
|
|
166
|
+
/// See <see>Type.castToType</see> for a more
|
|
167
|
+
/// detailed description.
|
|
168
|
+
///
|
|
169
|
+
/// Return: any
|
|
170
|
+
/// Return the incoming `value`, cast to this
|
|
171
|
+
/// type. `null` and `undefined` are simply
|
|
172
|
+
/// returned without casting.
|
|
173
|
+
///
|
|
174
|
+
/// Arguments:
|
|
175
|
+
/// context: <see name="CastToTypeContext">Type.castToType</see>
|
|
52
176
|
castToType(args) {
|
|
53
177
|
let { value } = args;
|
|
54
178
|
if (value == null)
|
|
@@ -71,6 +195,18 @@ class ForeignKeyType extends Type {
|
|
|
71
195
|
return targetField.type.castToType(args);
|
|
72
196
|
}
|
|
73
197
|
|
|
198
|
+
/// Check if the provided value is valid.
|
|
199
|
+
///
|
|
200
|
+
/// This will check if the provided value valid.
|
|
201
|
+
/// It does so by calling the `isValidValue` of
|
|
202
|
+
/// the type that it inherits from its target
|
|
203
|
+
/// field.
|
|
204
|
+
///
|
|
205
|
+
/// Return: boolean
|
|
206
|
+
///
|
|
207
|
+
/// Arguments:
|
|
208
|
+
/// value: any
|
|
209
|
+
/// The value to check.
|
|
74
210
|
isValidValue(value, options) {
|
|
75
211
|
let targetField = this.getTargetField(options && options.connection);
|
|
76
212
|
if (!targetField)
|
|
@@ -79,12 +215,29 @@ class ForeignKeyType extends Type {
|
|
|
79
215
|
return targetField.type.isValidValue(value, options);
|
|
80
216
|
}
|
|
81
217
|
|
|
218
|
+
/// This is called when the field is first initialized on
|
|
219
|
+
/// any model instance. It will verify the options provided
|
|
220
|
+
/// to the field, and ensure that it can find the target
|
|
221
|
+
/// field requested. If it can't find the target field
|
|
222
|
+
/// requested for any reason, then it will throw an exception.
|
|
223
|
+
///
|
|
224
|
+
/// Return: { Model: ModelClass, Field: Field }
|
|
225
|
+
/// Return the target model and field.
|
|
226
|
+
///
|
|
227
|
+
/// Arguments:
|
|
228
|
+
/// SourceModel: ModelClass
|
|
229
|
+
/// The source model (model owning this foreign key field).
|
|
230
|
+
/// sourceField:
|
|
231
|
+
/// The source field (the field containing this foreign key type).
|
|
232
|
+
/// connection: <see>Connection</see>
|
|
233
|
+
/// The database connection. This is needed to fetch the target
|
|
234
|
+
/// field and model.
|
|
82
235
|
parseOptionsAndCheckForErrors(SourceModel, sourceField, connection) {
|
|
83
236
|
let options = this.options;
|
|
84
237
|
let fullyQualifiedName = this.fullyQualifiedName;
|
|
85
|
-
let Model = options.Model;
|
|
86
238
|
let Field = options.Field;
|
|
87
239
|
let fieldName = options.fieldName;
|
|
240
|
+
let Model = (Field && Field.Model);
|
|
88
241
|
|
|
89
242
|
if (!Model) {
|
|
90
243
|
if (options.modelName) {
|
|
@@ -98,9 +251,6 @@ class ForeignKeyType extends Type {
|
|
|
98
251
|
}
|
|
99
252
|
}
|
|
100
253
|
|
|
101
|
-
if (!Model)
|
|
102
|
-
throw new TypeError(`ForeignKeyType::parseOptionsAndCheckForErrors: No target model found for field "${SourceModel.getModelName()}:${sourceField.fieldName}". You must specify a model.`);
|
|
103
|
-
|
|
104
254
|
if (!Field) {
|
|
105
255
|
let modelName = Model.getModelName();
|
|
106
256
|
|
|
@@ -115,12 +265,42 @@ class ForeignKeyType extends Type {
|
|
|
115
265
|
if (!Field)
|
|
116
266
|
throw new TypeError(`ForeignKeyType::parseOptionsAndCheckForErrors: No target field found for "${SourceModel.getModelName()}:${sourceField.fieldName}". You must specify a field.`);
|
|
117
267
|
|
|
268
|
+
if (!Model)
|
|
269
|
+
Model = Field.Model;
|
|
270
|
+
|
|
271
|
+
if (!Model)
|
|
272
|
+
throw new TypeError(`ForeignKeyType::parseOptionsAndCheckForErrors: No target model found for field "${SourceModel.getModelName()}:${sourceField.fieldName}". You must specify a model.`);
|
|
273
|
+
|
|
118
274
|
return {
|
|
119
275
|
Model,
|
|
120
276
|
Field,
|
|
121
277
|
};
|
|
122
278
|
}
|
|
123
279
|
|
|
280
|
+
/// Initialize a model instance against this type.
|
|
281
|
+
///
|
|
282
|
+
/// Initialize is called whenever a model instance is
|
|
283
|
+
/// created. Note that the type instance is shared
|
|
284
|
+
/// across all model instances. `initialize` is still
|
|
285
|
+
/// called for every model instance that is created however,
|
|
286
|
+
/// because the type class can modify the model it
|
|
287
|
+
/// exists on. For example, the `Model` and `Models` type
|
|
288
|
+
/// inject custom relational methods onto each model instance.
|
|
289
|
+
///
|
|
290
|
+
/// This specific `initialize` for the `ForeignKeyType`
|
|
291
|
+
/// only runs once however. The first owning model instance
|
|
292
|
+
/// that is created will call this method, and at that point
|
|
293
|
+
/// the target field will be looked up and found. After this
|
|
294
|
+
/// first lookup, the target field will be cached for all
|
|
295
|
+
/// future model instances of the same type.
|
|
296
|
+
///
|
|
297
|
+
/// Return: undefined
|
|
298
|
+
///
|
|
299
|
+
/// Arguments:
|
|
300
|
+
/// connection: <see>Connection</see>
|
|
301
|
+
/// The database connection of the calling model instance.
|
|
302
|
+
/// self: Model
|
|
303
|
+
/// The actual model instance that is calling this method.
|
|
124
304
|
initialize(connection, self) {
|
|
125
305
|
if (this.targetModel)
|
|
126
306
|
return;
|
|
@@ -138,23 +318,43 @@ class ForeignKeyType extends Type {
|
|
|
138
318
|
Object.defineProperties(this, {
|
|
139
319
|
'targetModel': {
|
|
140
320
|
writable: true,
|
|
141
|
-
|
|
321
|
+
enumerable: false,
|
|
142
322
|
configurable: true,
|
|
143
323
|
value: Model,
|
|
144
324
|
},
|
|
145
325
|
'targetField': {
|
|
146
326
|
writable: true,
|
|
147
|
-
|
|
327
|
+
enumerable: false,
|
|
148
328
|
configurable: true,
|
|
149
329
|
value: Field,
|
|
150
330
|
},
|
|
151
331
|
});
|
|
152
332
|
}
|
|
153
333
|
|
|
334
|
+
/// Get the options that were passed to the
|
|
335
|
+
/// `ForeignKeyType` on creation.
|
|
336
|
+
///
|
|
337
|
+
/// Return: object
|
|
338
|
+
/// The options object that was given to the field.
|
|
154
339
|
getOptions() {
|
|
155
340
|
return this.options;
|
|
156
341
|
}
|
|
157
342
|
|
|
343
|
+
/// Fetch the target model, which is the model
|
|
344
|
+
/// owning the target field.
|
|
345
|
+
///
|
|
346
|
+
/// Note:
|
|
347
|
+
/// If this is called before any model has been initialized,
|
|
348
|
+
/// or before a connection has been bound to your models, then
|
|
349
|
+
/// you **must** provide a `connection` or this method will fail.
|
|
350
|
+
///
|
|
351
|
+
/// Return: ModelClass
|
|
352
|
+
/// The target field's owning model.
|
|
353
|
+
///
|
|
354
|
+
/// Arguments:
|
|
355
|
+
/// connection?: <see>Connection</see>
|
|
356
|
+
/// A database connection, which will be used to fiend the
|
|
357
|
+
/// target field and owning model.
|
|
158
358
|
getTargetModel(connection) {
|
|
159
359
|
if (connection && !this.targetModel)
|
|
160
360
|
this.initialize(connection);
|
|
@@ -162,11 +362,42 @@ class ForeignKeyType extends Type {
|
|
|
162
362
|
return this.targetModel;
|
|
163
363
|
}
|
|
164
364
|
|
|
365
|
+
/// Fetch the name of target model, which is the model
|
|
366
|
+
/// owning the target field.
|
|
367
|
+
///
|
|
368
|
+
/// Note:
|
|
369
|
+
/// If this is called before any model has been initialized,
|
|
370
|
+
/// or before a connection has been bound to your models, then
|
|
371
|
+
/// you **must** provide a `connection` or this method will fail.
|
|
372
|
+
///
|
|
373
|
+
/// Return: string
|
|
374
|
+
/// The target field's owning model name.
|
|
375
|
+
///
|
|
376
|
+
/// Arguments:
|
|
377
|
+
/// connection?: <see>Connection</see>
|
|
378
|
+
/// A database connection, which will be used to fiend the
|
|
379
|
+
/// target field and owning model.
|
|
165
380
|
getTargetModelName(connection) {
|
|
166
381
|
let targetModel = this.getTargetModel(connection);
|
|
167
382
|
return targetModel.getModelName();
|
|
168
383
|
}
|
|
169
384
|
|
|
385
|
+
/// Fetch the target field. You can always access
|
|
386
|
+
/// the owning model via the `field.Model` property
|
|
387
|
+
/// on the field.
|
|
388
|
+
///
|
|
389
|
+
/// Note:
|
|
390
|
+
/// If this is called before any model has been initialized,
|
|
391
|
+
/// or before a connection has been bound to your models, then
|
|
392
|
+
/// you **must** provide a `connection` or this method will fail.
|
|
393
|
+
///
|
|
394
|
+
/// Return: <see>Field</see>
|
|
395
|
+
/// The target field from the target model.
|
|
396
|
+
///
|
|
397
|
+
/// Arguments:
|
|
398
|
+
/// connection?: <see>Connection</see>
|
|
399
|
+
/// A database connection, which will be used to fiend the
|
|
400
|
+
/// target field.
|
|
170
401
|
getTargetField(connection) {
|
|
171
402
|
if (connection && !this.targetModel)
|
|
172
403
|
this.initialize(connection);
|
|
@@ -174,6 +405,20 @@ class ForeignKeyType extends Type {
|
|
|
174
405
|
return this.targetField;
|
|
175
406
|
}
|
|
176
407
|
|
|
408
|
+
/// Fetch the target field's name.
|
|
409
|
+
///
|
|
410
|
+
/// Note:
|
|
411
|
+
/// If this is called before any model has been initialized,
|
|
412
|
+
/// or before a connection has been bound to your models, then
|
|
413
|
+
/// you **must** provide a `connection` or this method will fail.
|
|
414
|
+
///
|
|
415
|
+
/// Return: string
|
|
416
|
+
/// The target field's name.
|
|
417
|
+
///
|
|
418
|
+
/// Arguments:
|
|
419
|
+
/// connection?: <see>Connection</see>
|
|
420
|
+
/// A database connection, which will be used to fiend the
|
|
421
|
+
/// target field.
|
|
177
422
|
getTargetFieldName(connection) {
|
|
178
423
|
let targetField = this.getTargetField(connection);
|
|
179
424
|
if (!targetField)
|
|
@@ -190,6 +435,25 @@ class ForeignKeyType extends Type {
|
|
|
190
435
|
return targetField.type.toConnectionType(connection, options);
|
|
191
436
|
}
|
|
192
437
|
|
|
438
|
+
/// Stringify the type itself. **This will be
|
|
439
|
+
/// the type of the target field**.
|
|
440
|
+
///
|
|
441
|
+
/// If a `connection` argument is provided, then this
|
|
442
|
+
/// will go through the connection to generate the type
|
|
443
|
+
/// for the underlying database. If no connection is
|
|
444
|
+
/// provided, then a "standard" SQL type will be returned
|
|
445
|
+
/// for target field type instead.
|
|
446
|
+
///
|
|
447
|
+
/// Return: string
|
|
448
|
+
///
|
|
449
|
+
/// Arguments:
|
|
450
|
+
/// connection?: <see>Connection</see>
|
|
451
|
+
/// An optional connection. If provided, send this
|
|
452
|
+
/// type through <see>Type.toConnectionType</see>
|
|
453
|
+
/// to have the connection itself generate the underlying
|
|
454
|
+
/// type for the database. If `connection` is not provided,
|
|
455
|
+
/// then this will simply return a "standard" generic matching
|
|
456
|
+
/// SQL type of the target field type.
|
|
193
457
|
toString(...args) {
|
|
194
458
|
if (args.length === 0)
|
|
195
459
|
return 'ForeignKeyType {}';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export * from './bigint-type';
|
|
2
|
+
export * from './blob-type';
|
|
3
|
+
export * from './boolean-type';
|
|
4
|
+
export * from './char-type';
|
|
5
|
+
export * from './date-type';
|
|
6
|
+
export * from './datetime-type';
|
|
7
|
+
export * from './foreign-key-type';
|
|
8
|
+
export * from './integer-type';
|
|
9
|
+
export * from './numeric-type';
|
|
10
|
+
export * from './real-type';
|
|
11
|
+
export * from './serialized-type';
|
|
12
|
+
export * from './string-type';
|
|
13
|
+
export * from './text-type';
|
|
14
|
+
export * from './uuid-v1-type';
|
|
15
|
+
export * from './uuid-v3-type';
|
|
16
|
+
export * from './uuid-v4-type';
|
|
17
|
+
export * from './uuid-v5-type';
|
|
18
|
+
export * from './xid-type';
|
|
19
|
+
export { default as UUIDBaseType } from './uuid-base';
|
|
@@ -18,6 +18,7 @@ const { UUIDV3, UUIDV3Type } = require('./uuid-v3-type');
|
|
|
18
18
|
const { UUIDV4, UUIDV4Type } = require('./uuid-v4-type');
|
|
19
19
|
const { UUIDV5, UUIDV5Type } = require('./uuid-v5-type');
|
|
20
20
|
const { XID, XIDType } = require('./xid-type');
|
|
21
|
+
const UUIDBaseType = require('./uuid-base');
|
|
21
22
|
|
|
22
23
|
module.exports = {
|
|
23
24
|
BigIntType,
|
|
@@ -38,6 +39,7 @@ module.exports = {
|
|
|
38
39
|
UUIDV4Type,
|
|
39
40
|
UUIDV5Type,
|
|
40
41
|
XIDType,
|
|
42
|
+
UUIDBaseType,
|
|
41
43
|
BIGINT,
|
|
42
44
|
BLOB,
|
|
43
45
|
BOOLEAN,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AutoIncrementDefaultValueProvider } from '../helpers/default-helpers';
|
|
2
|
+
import Type, { TypeWrapper } from '../type';
|
|
3
|
+
|
|
4
|
+
export declare interface IntegerTypeWrapper extends TypeWrapper<IntegerType> {
|
|
5
|
+
(length?: number): IntegerType;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare class IntegerType extends Type {
|
|
9
|
+
declare public static Default: {
|
|
10
|
+
AUTO_INCREMENT: AutoIncrementDefaultValueProvider;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
public constructor(length?: number);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const INTEGER: IntegerTypeWrapper;
|
|
@@ -33,6 +33,7 @@ const { AUTO_INCREMENT } = require('../helpers/default-helpers');
|
|
|
33
33
|
/// Default: object = { AUTO_INCREMENT }
|
|
34
34
|
/// `AUTO_INCREMENT` is a method that can be used as the `defaultValue` of a <see>Field</see>
|
|
35
35
|
/// to have this field auto-increment in the underlying database.
|
|
36
|
+
///
|
|
36
37
|
/// See: Type
|
|
37
38
|
class IntegerType extends Type {
|
|
38
39
|
static Default = {
|
|
@@ -47,16 +48,13 @@ class IntegerType extends Type {
|
|
|
47
48
|
/// Note:
|
|
48
49
|
/// This is also an instance method that can be called from
|
|
49
50
|
/// an instance of the type.
|
|
51
|
+
///
|
|
50
52
|
/// Return: string
|
|
51
53
|
/// Return the string value `'INTEGER'`
|
|
52
54
|
static getDisplayName() {
|
|
53
55
|
return 'INTEGER';
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
getDisplayName() {
|
|
57
|
-
return this.constructor.getDisplayName();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
58
|
/// Construct a new `BIGINT` type.
|
|
61
59
|
///
|
|
62
60
|
/// The `length` argument--as on all
|
|
@@ -67,6 +65,7 @@ class IntegerType extends Type {
|
|
|
67
65
|
/// makes sense to the database.
|
|
68
66
|
///
|
|
69
67
|
/// Return: IntegerType
|
|
68
|
+
///
|
|
70
69
|
/// Arguments:
|
|
71
70
|
/// length?: number
|
|
72
71
|
/// How many bytes to use in the underlying database to store the value.
|
|
@@ -92,6 +91,7 @@ class IntegerType extends Type {
|
|
|
92
91
|
/// Return the incoming `value`, cast to this
|
|
93
92
|
/// type. `null` and `undefined` are simply
|
|
94
93
|
/// returned without casting.
|
|
94
|
+
///
|
|
95
95
|
/// Arguments:
|
|
96
96
|
/// context: <see name="CastToTypeContext">Type.castToType</see>
|
|
97
97
|
castToType({ value }) {
|
|
@@ -113,6 +113,7 @@ class IntegerType extends Type {
|
|
|
113
113
|
/// return `true`.
|
|
114
114
|
///
|
|
115
115
|
/// Return: boolean
|
|
116
|
+
///
|
|
116
117
|
/// Arguments:
|
|
117
118
|
/// value: any
|
|
118
119
|
/// The value to check.
|
|
@@ -130,6 +131,7 @@ class IntegerType extends Type {
|
|
|
130
131
|
/// when no `connection` is provided is `'INTEGER'`.
|
|
131
132
|
///
|
|
132
133
|
/// Return: string
|
|
134
|
+
///
|
|
133
135
|
/// Arguments:
|
|
134
136
|
/// connection?: <see>Connection</see>
|
|
135
137
|
/// An optional connection. If provided, send this
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Type, { TypeWrapper } from '../type';
|
|
2
|
+
|
|
3
|
+
export declare interface NumericTypeWrapper extends TypeWrapper<NumericType> {
|
|
4
|
+
(precision?: number, scale?: number): NumericType;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export declare class NumericType extends Type {
|
|
8
|
+
public constructor(precision?: number, scale?: number);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const NUMERIC: NumericTypeWrapper;
|
|
@@ -35,6 +35,7 @@ const DEFAULT_DECIMAL_PLACES = 6;
|
|
|
35
35
|
/// numeric3: new Types.NumericType(10, 3),
|
|
36
36
|
/// };
|
|
37
37
|
/// }
|
|
38
|
+
///
|
|
38
39
|
/// See: Type
|
|
39
40
|
class NumericType extends Type {
|
|
40
41
|
/// Get the "display" name for this type.
|
|
@@ -45,16 +46,13 @@ class NumericType extends Type {
|
|
|
45
46
|
/// Note:
|
|
46
47
|
/// This is also an instance method that can be called from
|
|
47
48
|
/// an instance of the type.
|
|
49
|
+
///
|
|
48
50
|
/// Return: string
|
|
49
51
|
/// Return the string value `'NUMERIC'`
|
|
50
52
|
static getDisplayName() {
|
|
51
53
|
return 'NUMERIC';
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
getDisplayName() {
|
|
55
|
-
return this.constructor.getDisplayName();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
56
|
/// Construct a new `NUMERIC` type.
|
|
59
57
|
///
|
|
60
58
|
/// The `precision` argument specifies the
|
|
@@ -65,6 +63,7 @@ class NumericType extends Type {
|
|
|
65
63
|
/// digits after the decimal point.
|
|
66
64
|
///
|
|
67
65
|
/// Return: NumericType
|
|
66
|
+
///
|
|
68
67
|
/// Arguments:
|
|
69
68
|
/// precision?: number = 20
|
|
70
69
|
/// The total number of allowed digits in the number. This
|
|
@@ -97,6 +96,7 @@ class NumericType extends Type {
|
|
|
97
96
|
/// Return the incoming `value`, cast to this
|
|
98
97
|
/// type. `null` and `undefined` are simply
|
|
99
98
|
/// returned without casting.
|
|
99
|
+
///
|
|
100
100
|
/// Arguments:
|
|
101
101
|
/// context: <see name="CastToTypeContext">Type.castToType</see>
|
|
102
102
|
castToType({ value }) {
|
|
@@ -118,6 +118,7 @@ class NumericType extends Type {
|
|
|
118
118
|
/// return `true`.
|
|
119
119
|
///
|
|
120
120
|
/// Return: boolean
|
|
121
|
+
///
|
|
121
122
|
/// Arguments:
|
|
122
123
|
/// value: any
|
|
123
124
|
/// The value to check.
|
|
@@ -135,6 +136,7 @@ class NumericType extends Type {
|
|
|
135
136
|
/// when no `connection` is provided is `'NUMERIC'`.
|
|
136
137
|
///
|
|
137
138
|
/// Return: string
|
|
139
|
+
///
|
|
138
140
|
/// Arguments:
|
|
139
141
|
/// connection?: <see>Connection</see>
|
|
140
142
|
/// An optional connection. If provided, send this
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Type, { TypeWrapper } from '../type';
|
|
2
|
+
|
|
3
|
+
export declare interface RealTypeWrapper extends TypeWrapper<RealType> {
|
|
4
|
+
(length?: number, scale?: number): RealType;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export declare class RealType extends Type {
|
|
8
|
+
public constructor(length?: number, scale?: number);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const REAL: RealTypeWrapper;
|