UNPKG

9.64 kBTypeScriptView Raw
1import { ColumnType } from "../driver/types/ColumnTypes";
2import { EntityMetadata } from "./EntityMetadata";
3import { EmbeddedMetadata } from "./EmbeddedMetadata";
4import { RelationMetadata } from "./RelationMetadata";
5import { ObjectLiteral } from "../common/ObjectLiteral";
6import { ColumnMetadataArgs } from "../metadata-args/ColumnMetadataArgs";
7import { Connection } from "../connection/Connection";
8import { ValueTransformer } from "../decorator/options/ValueTransformer";
9/**
10 * This metadata contains all information about entity's column.
11 */
12export declare class ColumnMetadata {
13 /**
14 * Target class where column decorator is used.
15 * This may not be always equal to entity metadata (for example embeds or inheritance cases).
16 */
17 target: Function | string;
18 /**
19 * Entity metadata where this column metadata is.
20 *
21 * For example for @Column() name: string in Post, entityMetadata will be metadata of Post entity.
22 */
23 entityMetadata: EntityMetadata;
24 /**
25 * Embedded metadata where this column metadata is.
26 * If this column is not in embed then this property value is undefined.
27 */
28 embeddedMetadata?: EmbeddedMetadata;
29 /**
30 * If column is a foreign key of some relation then this relation's metadata will be there.
31 * If this column does not have a foreign key then this property value is undefined.
32 */
33 relationMetadata?: RelationMetadata;
34 /**
35 * Class's property name on which this column is applied.
36 */
37 propertyName: string;
38 /**
39 * The database type of the column.
40 */
41 type: ColumnType;
42 /**
43 * Type's length in the database.
44 */
45 length: string;
46 /**
47 * Type's display width in the database.
48 */
49 width?: number;
50 /**
51 * Defines column character set.
52 */
53 charset?: string;
54 /**
55 * Defines column collation.
56 */
57 collation?: string;
58 /**
59 * Indicates if this column is a primary key.
60 */
61 isPrimary: boolean;
62 /**
63 * Indicates if this column is generated (auto increment or generated other way).
64 */
65 isGenerated: boolean;
66 /**
67 * Indicates if column can contain nulls or not.
68 */
69 isNullable: boolean;
70 /**
71 * Indicates if column is selected by query builder or not.
72 */
73 isSelect: boolean;
74 /**
75 * Indicates if column is inserted by default or not.
76 */
77 isInsert: boolean;
78 /**
79 * Indicates if column allows updates or not.
80 */
81 isUpdate: boolean;
82 /**
83 * Specifies generation strategy if this column will use auto increment.
84 */
85 generationStrategy?: "uuid" | "increment" | "rowid";
86 /**
87 * Column comment.
88 * This feature is not supported by all databases.
89 */
90 comment: string;
91 /**
92 * Default database value.
93 */
94 default?: any;
95 /**
96 * ON UPDATE trigger. Works only for MySQL.
97 */
98 onUpdate?: string;
99 /**
100 * The precision for a decimal (exact numeric) column (applies only for decimal column),
101 * which is the maximum number of digits that are stored for the values.
102 */
103 precision?: number | null;
104 /**
105 * The scale for a decimal (exact numeric) column (applies only for decimal column),
106 * which represents the number of digits to the right of the decimal point and must not be greater than precision.
107 */
108 scale?: number;
109 /**
110 * Puts ZEROFILL attribute on to numeric column. Works only for MySQL.
111 * If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column
112 */
113 zerofill: boolean;
114 /**
115 * Puts UNSIGNED attribute on to numeric column. Works only for MySQL.
116 */
117 unsigned: boolean;
118 /**
119 * Array of possible enumerated values.
120 *
121 * `postgres` and `mysql` store enum values as strings but we want to keep support
122 * for numeric and heterogeneous based typescript enums, so we need (string|number)[]
123 */
124 enum?: (string | number)[];
125 /**
126 * Exact name of enum
127 */
128 enumName?: string;
129 /**
130 * Generated column expression. Supports only in MySQL.
131 */
132 asExpression?: string;
133 /**
134 * Generated column type. Supports only in MySQL.
135 */
136 generatedType?: "VIRTUAL" | "STORED";
137 /**
138 * Return type of HSTORE column.
139 * Returns value as string or as object.
140 */
141 hstoreType?: "object" | "string";
142 /**
143 * Indicates if this column is an array.
144 */
145 isArray: boolean;
146 /**
147 * Gets full path to this column property (including column property name).
148 * Full path is relevant when column is used in embeds (one or multiple nested).
149 * For example it will return "counters.subcounters.likes".
150 * If property is not in embeds then it returns just property name of the column.
151 */
152 propertyPath: string;
153 /**
154 * Same as property path, but dots are replaced with '_'.
155 * Used in query builder statements.
156 */
157 propertyAliasName: string;
158 /**
159 * Gets full path to this column database name (including column database name).
160 * Full path is relevant when column is used in embeds (one or multiple nested).
161 * For example it will return "counters.subcounters.likes".
162 * If property is not in embeds then it returns just database name of the column.
163 */
164 databasePath: string;
165 /**
166 * Complete column name in the database including its embedded prefixes.
167 */
168 databaseName: string;
169 /**
170 * Database name in the database without embedded prefixes applied.
171 */
172 databaseNameWithoutPrefixes: string;
173 /**
174 * Database name set by entity metadata builder, not yet passed naming strategy process and without embedded prefixes.
175 */
176 givenDatabaseName?: string;
177 /**
178 * Indicates if column is virtual. Virtual columns are not mapped to the entity.
179 */
180 isVirtual: boolean;
181 /**
182 * Indicates if column is discriminator. Discriminator columns are not mapped to the entity.
183 */
184 isDiscriminator: boolean;
185 /**
186 * Indicates if column is tree-level column. Tree-level columns are used in closure entities.
187 */
188 isTreeLevel: boolean;
189 /**
190 * Indicates if this column contains an entity creation date.
191 */
192 isCreateDate: boolean;
193 /**
194 * Indicates if this column contains an entity update date.
195 */
196 isUpdateDate: boolean;
197 /**
198 * Indicates if this column contains an entity version.
199 */
200 isVersion: boolean;
201 /**
202 * Indicates if this column contains an object id.
203 */
204 isObjectId: boolean;
205 /**
206 * If this column is foreign key then it references some other column,
207 * and this property will contain reference to this column.
208 */
209 referencedColumn: ColumnMetadata | undefined;
210 /**
211 * Specifies a value transformer that is to be used to (un)marshal
212 * this column when reading or writing to the database.
213 */
214 transformer?: ValueTransformer | ValueTransformer[];
215 /**
216 * Column type in the case if this column is in the closure table.
217 * Column can be ancestor or descendant in the closure tables.
218 */
219 closureType?: "ancestor" | "descendant";
220 /**
221 * Indicates if this column is nested set's left column.
222 * Used only in tree entities with nested-set type.
223 */
224 isNestedSetLeft: boolean;
225 /**
226 * Indicates if this column is nested set's right column.
227 * Used only in tree entities with nested-set type.
228 */
229 isNestedSetRight: boolean;
230 /**
231 * Indicates if this column is materialized path's path column.
232 * Used only in tree entities with materialized path type.
233 */
234 isMaterializedPath: boolean;
235 /**
236 * Spatial Feature Type (Geometry, Point, Polygon, etc.)
237 */
238 spatialFeatureType?: string;
239 /**
240 * SRID (Spatial Reference ID (EPSG code))
241 */
242 srid?: number;
243 constructor(options: {
244 connection: Connection;
245 entityMetadata: EntityMetadata;
246 embeddedMetadata?: EmbeddedMetadata;
247 referencedColumn?: ColumnMetadata;
248 args: ColumnMetadataArgs;
249 closureType?: "ancestor" | "descendant";
250 nestedSetLeft?: boolean;
251 nestedSetRight?: boolean;
252 materializedPath?: boolean;
253 });
254 /**
255 * Creates entity id map from the given entity ids array.
256 */
257 createValueMap(value: any, useDatabaseName?: boolean): any;
258 /**
259 * Extracts column value and returns its column name with this value in a literal object.
260 * If column is in embedded (or recursive embedded) it returns complex literal object.
261 *
262 * Examples what this method can return depend if this column is in embeds.
263 * { id: 1 } or { title: "hello" }, { counters: { code: 1 } }, { data: { information: { counters: { code: 1 } } } }
264 */
265 getEntityValueMap(entity: ObjectLiteral, options?: {
266 skipNulls?: boolean;
267 }): ObjectLiteral | undefined;
268 /**
269 * Extracts column value from the given entity.
270 * If column is in embedded (or recursive embedded) it extracts its value from there.
271 */
272 getEntityValue(entity: ObjectLiteral, transform?: boolean): any | undefined;
273 /**
274 * Sets given entity's column value.
275 * Using of this method helps to set entity relation's value of the lazy and non-lazy relations.
276 */
277 setEntityValue(entity: ObjectLiteral, value: any): void;
278 build(connection: Connection): this;
279 protected buildPropertyPath(): string;
280 protected buildDatabasePath(): string;
281 protected buildDatabaseName(connection: Connection): string;
282}