Skip to content

Commit

Permalink
many more types
Browse files Browse the repository at this point in the history
  • Loading branch information
jraymakers committed Jan 12, 2025
1 parent 2d28c1e commit 34fb19d
Show file tree
Hide file tree
Showing 6 changed files with 424 additions and 94 deletions.
9 changes: 9 additions & 0 deletions api/src/DuckDBType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ export const TIMESTAMP_NS = DuckDBTimestampNanosecondsType.instance;

export class DuckDBEnumType extends BaseDuckDBType<DuckDBTypeId.ENUM> {
public readonly values: readonly string[];
public readonly valueIndexes: Readonly<Record<string, number>>;
public readonly internalTypeId: DuckDBTypeId;
public constructor(
values: readonly string[],
Expand All @@ -493,8 +494,16 @@ export class DuckDBEnumType extends BaseDuckDBType<DuckDBTypeId.ENUM> {
) {
super(DuckDBTypeId.ENUM, alias);
this.values = values;
const valueIndexes: Record<string, number> = {};
for (let i = 0; i < values.length; i++) {
valueIndexes[values[i]] = i;
}
this.valueIndexes = valueIndexes;
this.internalTypeId = internalTypeId;
}
public indexForValue(value: string): number {
return this.valueIndexes[value];
}
public toString(): string {
return `ENUM(${this.values.map(quotedString).join(', ')})`;
}
Expand Down
Loading

0 comments on commit 34fb19d

Please sign in to comment.