@@ -45,11 +45,6 @@ export class DuckDBLogicalType {
45
45
protected constructor ( logical_type : duckdb . LogicalType ) {
46
46
this . logical_type = logical_type ;
47
47
}
48
- static consumeAsType ( logical_type : duckdb . LogicalType ) : DuckDBType {
49
- const logicalType = DuckDBLogicalType . create ( logical_type ) ;
50
- const type = logicalType . asType ( ) ;
51
- return type ;
52
- }
53
48
static create ( logical_type : duckdb . LogicalType ) : DuckDBLogicalType {
54
49
switch ( duckdb . get_type_id ( logical_type ) ) {
55
50
case duckdb . Type . DECIMAL :
@@ -147,60 +142,61 @@ export class DuckDBLogicalType {
147
142
public get typeId ( ) : DuckDBTypeId {
148
143
return duckdb . get_type_id ( this . logical_type ) as number as DuckDBTypeId ;
149
144
}
150
- public get alias ( ) : string | null {
151
- return duckdb . logical_type_get_alias ( this . logical_type ) ;
145
+ public get alias ( ) : string | undefined {
146
+ return duckdb . logical_type_get_alias ( this . logical_type ) || undefined ;
152
147
}
153
148
public set alias ( newAlias : string ) {
154
149
duckdb . logical_type_set_alias ( this . logical_type , newAlias ) ;
155
150
}
156
151
public asType ( ) : DuckDBType {
152
+ const alias = this . alias ;
157
153
switch ( this . typeId ) {
158
154
case DuckDBTypeId . BOOLEAN :
159
- return DuckDBBooleanType . instance ;
155
+ return DuckDBBooleanType . create ( alias ) ;
160
156
case DuckDBTypeId . TINYINT :
161
- return DuckDBTinyIntType . instance ;
157
+ return DuckDBTinyIntType . create ( alias ) ;
162
158
case DuckDBTypeId . SMALLINT :
163
- return DuckDBSmallIntType . instance ;
159
+ return DuckDBSmallIntType . create ( alias ) ;
164
160
case DuckDBTypeId . INTEGER :
165
- return DuckDBIntegerType . instance ;
161
+ return DuckDBIntegerType . create ( alias ) ;
166
162
case DuckDBTypeId . BIGINT :
167
- return DuckDBBigIntType . instance ;
163
+ return DuckDBBigIntType . create ( alias ) ;
168
164
case DuckDBTypeId . UTINYINT :
169
- return DuckDBUTinyIntType . instance ;
165
+ return DuckDBUTinyIntType . create ( alias ) ;
170
166
case DuckDBTypeId . USMALLINT :
171
- return DuckDBUSmallIntType . instance ;
167
+ return DuckDBUSmallIntType . create ( alias ) ;
172
168
case DuckDBTypeId . UINTEGER :
173
- return DuckDBUIntegerType . instance ;
169
+ return DuckDBUIntegerType . create ( alias ) ;
174
170
case DuckDBTypeId . UBIGINT :
175
- return DuckDBUBigIntType . instance ;
171
+ return DuckDBUBigIntType . create ( alias ) ;
176
172
case DuckDBTypeId . FLOAT :
177
- return DuckDBFloatType . instance ;
173
+ return DuckDBFloatType . create ( alias ) ;
178
174
case DuckDBTypeId . DOUBLE :
179
- return DuckDBDoubleType . instance ;
175
+ return DuckDBDoubleType . create ( alias ) ;
180
176
case DuckDBTypeId . TIMESTAMP :
181
- return DuckDBTimestampType . instance ;
177
+ return DuckDBTimestampType . create ( alias ) ;
182
178
case DuckDBTypeId . DATE :
183
- return DuckDBDateType . instance ;
179
+ return DuckDBDateType . create ( alias ) ;
184
180
case DuckDBTypeId . TIME :
185
- return DuckDBTimeType . instance ;
181
+ return DuckDBTimeType . create ( alias ) ;
186
182
case DuckDBTypeId . INTERVAL :
187
- return DuckDBIntervalType . instance ;
183
+ return DuckDBIntervalType . create ( alias ) ;
188
184
case DuckDBTypeId . HUGEINT :
189
- return DuckDBHugeIntType . instance ;
185
+ return DuckDBHugeIntType . create ( alias ) ;
190
186
case DuckDBTypeId . UHUGEINT :
191
- return DuckDBUHugeIntType . instance ;
187
+ return DuckDBUHugeIntType . create ( alias ) ;
192
188
case DuckDBTypeId . VARCHAR :
193
- return DuckDBVarCharType . instance ;
189
+ return DuckDBVarCharType . create ( alias ) ;
194
190
case DuckDBTypeId . BLOB :
195
- return DuckDBBlobType . instance ;
191
+ return DuckDBBlobType . create ( alias ) ;
196
192
case DuckDBTypeId . DECIMAL :
197
193
throw new Error ( 'Expected override' ) ;
198
194
case DuckDBTypeId . TIMESTAMP_S :
199
- return DuckDBTimestampSecondsType . instance ;
195
+ return DuckDBTimestampSecondsType . create ( alias ) ;
200
196
case DuckDBTypeId . TIMESTAMP_MS :
201
- return DuckDBTimestampMillisecondsType . instance ;
197
+ return DuckDBTimestampMillisecondsType . create ( alias ) ;
202
198
case DuckDBTypeId . TIMESTAMP_NS :
203
- return DuckDBTimestampNanosecondsType . instance ;
199
+ return DuckDBTimestampNanosecondsType . create ( alias ) ;
204
200
case DuckDBTypeId . ENUM :
205
201
throw new Error ( 'Expected override' ) ;
206
202
case DuckDBTypeId . LIST :
@@ -212,21 +208,21 @@ export class DuckDBLogicalType {
212
208
case DuckDBTypeId . ARRAY :
213
209
throw new Error ( 'Expected override' ) ;
214
210
case DuckDBTypeId . UUID :
215
- return DuckDBUUIDType . instance ;
211
+ return DuckDBUUIDType . create ( alias ) ;
216
212
case DuckDBTypeId . UNION :
217
213
throw new Error ( 'Expected override' ) ;
218
214
case DuckDBTypeId . BIT :
219
- return DuckDBBitType . instance ;
215
+ return DuckDBBitType . create ( alias ) ;
220
216
case DuckDBTypeId . TIME_TZ :
221
- return DuckDBTimeTZType . instance ;
217
+ return DuckDBTimeTZType . create ( alias ) ;
222
218
case DuckDBTypeId . TIMESTAMP_TZ :
223
- return DuckDBTimestampTZType . instance ;
219
+ return DuckDBTimestampTZType . create ( alias ) ;
224
220
case DuckDBTypeId . ANY :
225
- return DuckDBAnyType . instance ;
221
+ return DuckDBAnyType . create ( alias ) ;
226
222
case DuckDBTypeId . VARINT :
227
- return DuckDBVarIntType . instance ;
223
+ return DuckDBVarIntType . create ( alias ) ;
228
224
case DuckDBTypeId . SQLNULL :
229
- return DuckDBSQLNullType . instance ;
225
+ return DuckDBSQLNullType . create ( alias ) ;
230
226
default :
231
227
throw new Error ( `Unexpected type id: ${ this . typeId } ` ) ;
232
228
}
@@ -246,7 +242,7 @@ export class DuckDBDecimalLogicalType extends DuckDBLogicalType {
246
242
) as number as DuckDBTypeId ;
247
243
}
248
244
public override asType ( ) : DuckDBDecimalType {
249
- return new DuckDBDecimalType ( this . width , this . scale ) ;
245
+ return new DuckDBDecimalType ( this . width , this . scale , this . alias ) ;
250
246
}
251
247
}
252
248
@@ -271,7 +267,7 @@ export class DuckDBEnumLogicalType extends DuckDBLogicalType {
271
267
) as number as DuckDBTypeId ;
272
268
}
273
269
public override asType ( ) : DuckDBEnumType {
274
- return new DuckDBEnumType ( this . values ( ) , this . internalTypeId ) ;
270
+ return new DuckDBEnumType ( this . values ( ) , this . internalTypeId , this . alias ) ;
275
271
}
276
272
}
277
273
@@ -282,7 +278,7 @@ export class DuckDBListLogicalType extends DuckDBLogicalType {
282
278
) ;
283
279
}
284
280
public override asType ( ) : DuckDBListType {
285
- return new DuckDBListType ( this . valueType . asType ( ) ) ;
281
+ return new DuckDBListType ( this . valueType . asType ( ) , this . alias ) ;
286
282
}
287
283
}
288
284
@@ -326,7 +322,7 @@ export class DuckDBStructLogicalType extends DuckDBLogicalType {
326
322
return valueTypes ;
327
323
}
328
324
public override asType ( ) : DuckDBStructType {
329
- return new DuckDBStructType ( this . entryNames ( ) , this . entryTypes ( ) ) ;
325
+ return new DuckDBStructType ( this . entryNames ( ) , this . entryTypes ( ) , this . alias ) ;
330
326
}
331
327
}
332
328
@@ -342,7 +338,7 @@ export class DuckDBMapLogicalType extends DuckDBLogicalType {
342
338
) ;
343
339
}
344
340
public override asType ( ) : DuckDBMapType {
345
- return new DuckDBMapType ( this . keyType . asType ( ) , this . valueType . asType ( ) ) ;
341
+ return new DuckDBMapType ( this . keyType . asType ( ) , this . valueType . asType ( ) , this . alias ) ;
346
342
}
347
343
}
348
344
@@ -356,7 +352,7 @@ export class DuckDBArrayLogicalType extends DuckDBLogicalType {
356
352
return duckdb . array_type_array_size ( this . logical_type ) ;
357
353
}
358
354
public override asType ( ) : DuckDBArrayType {
359
- return new DuckDBArrayType ( this . valueType . asType ( ) , this . length ) ;
355
+ return new DuckDBArrayType ( this . valueType . asType ( ) , this . length , this . alias ) ;
360
356
}
361
357
}
362
358
@@ -400,6 +396,6 @@ export class DuckDBUnionLogicalType extends DuckDBLogicalType {
400
396
return valueTypes ;
401
397
}
402
398
public override asType ( ) : DuckDBUnionType {
403
- return new DuckDBUnionType ( this . memberTags ( ) , this . memberTypes ( ) ) ;
399
+ return new DuckDBUnionType ( this . memberTags ( ) , this . memberTypes ( ) , this . alias ) ;
404
400
}
405
401
}
0 commit comments