Skip to content

Commit

Permalink
fix: remove incorrect ColumnType deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinBlomberg committed Sep 18, 2024
1 parent 0a7cfdb commit e4f54f4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;

export type Timestamp = ColumnType<Date, Date | string>;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;

export interface Company {
id: Generated<number>;
Expand Down
22 changes: 22 additions & 0 deletions src/generator/dialects/postgres/postgres-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export class PostgresAdapter extends Adapter {
new IdentifierNode('number'),
new IdentifierNode('bigint'),
]),
new UnionExpressionNode([
new IdentifierNode('string'),
new IdentifierNode('number'),
new IdentifierNode('bigint'),
]),
),
Interval: new ColumnTypeNode(
new IdentifierNode('IPostgresInterval'),
Expand All @@ -47,6 +52,11 @@ export class PostgresAdapter extends Adapter {
new IdentifierNode('number'),
new IdentifierNode('string'),
]),
new UnionExpressionNode([
new IdentifierNode('IPostgresInterval'),
new IdentifierNode('number'),
new IdentifierNode('string'),
]),
),
Json: JSON_DEFINITION,
JsonArray: JSON_ARRAY_DEFINITION,
Expand All @@ -59,6 +69,10 @@ export class PostgresAdapter extends Adapter {
new IdentifierNode('number'),
new IdentifierNode('string'),
]),
new UnionExpressionNode([
new IdentifierNode('number'),
new IdentifierNode('string'),
]),
),
Point: new ObjectExpressionNode([
new PropertyNode('x', new IdentifierNode('number')),
Expand All @@ -70,6 +84,10 @@ export class PostgresAdapter extends Adapter {
new IdentifierNode('Date'),
new IdentifierNode('string'),
]),
new UnionExpressionNode([
new IdentifierNode('Date'),
new IdentifierNode('string'),
]),
),
};
override readonly imports = {
Expand Down Expand Up @@ -126,6 +144,10 @@ export class PostgresAdapter extends Adapter {
new IdentifierNode('number'),
new IdentifierNode('string'),
]),
new UnionExpressionNode([
new IdentifierNode('number'),
new IdentifierNode('string'),
]),
);
} else if (options?.numericParser === NumericParser.NUMBER_OR_STRING) {
this.definitions.Numeric = new ColumnTypeNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;

export type Interval = ColumnType<IPostgresInterval, IPostgresInterval | number | string>;
export type Interval = ColumnType<IPostgresInterval, IPostgresInterval | number | string, IPostgresInterval | number | string>;

export type Json = JsonValue;

Expand All @@ -44,7 +44,7 @@ export type JsonValue = JsonArray | JsonObject | JsonPrimitive;

export type Numeric = ColumnType<number | string>;

export type Timestamp = ColumnType<Date, Date | string>;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;

export interface FooBar {
array: string[] | null;
Expand Down
4 changes: 2 additions & 2 deletions src/generator/generator/snapshots/postgres.snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
? ColumnType<S, I | undefined, U>
: ColumnType<T, T | undefined, T>;

export type Interval = ColumnType<IPostgresInterval, IPostgresInterval | number | string>;
export type Interval = ColumnType<IPostgresInterval, IPostgresInterval | number | string, IPostgresInterval | number | string>;

export type Json = JsonValue;

Expand All @@ -38,7 +38,7 @@ export type Status = "CONFIRMED" | "UNCONFIRMED";

export type TestStatus = "ABC_DEF" | "GHI_JKL";

export type Timestamp = ColumnType<Date, Date | string>;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;

export interface FooBar {
array: string[] | null;
Expand Down
21 changes: 11 additions & 10 deletions src/generator/transformer/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ArrayExpressionNode } from '../ast/array-expression-node';
import { ColumnTypeNode } from '../ast/column-type-node';
import type { DefinitionNode } from '../ast/definition-node';
import { ExtendsClauseNode } from '../ast/extends-clause-node';
import { GenericExpressionNode } from '../ast/generic-expression-node';
Expand Down Expand Up @@ -28,44 +29,44 @@ export const GLOBAL_DEFINITIONS = {
['T'],
new ExtendsClauseNode(
new IdentifierNode('T'),
new GenericExpressionNode('ColumnType', [
new ColumnTypeNode(
new InferClauseNode('S'),
new InferClauseNode('I'),
new InferClauseNode('U'),
]),
new GenericExpressionNode('ColumnType', [
),
new ColumnTypeNode(
new ArrayExpressionNode(new IdentifierNode('S')),
new ArrayExpressionNode(new IdentifierNode('I')),
new ArrayExpressionNode(new IdentifierNode('U')),
]),
),
new ArrayExpressionNode(new IdentifierNode('T')),
),
),
Generated: new TemplateNode(
['T'],
new ExtendsClauseNode(
new IdentifierNode('T'),
new GenericExpressionNode('ColumnType', [
new ColumnTypeNode(
new InferClauseNode('S'),
new InferClauseNode('I'),
new InferClauseNode('U'),
]),
new GenericExpressionNode('ColumnType', [
),
new ColumnTypeNode(
new IdentifierNode('S'),
new UnionExpressionNode([
new IdentifierNode('I'),
new IdentifierNode('undefined'),
]),
new IdentifierNode('U'),
]),
new GenericExpressionNode('ColumnType', [
),
new ColumnTypeNode(
new IdentifierNode('T'),
new UnionExpressionNode([
new IdentifierNode('T'),
new IdentifierNode('undefined'),
]),
new IdentifierNode('T'),
]),
),
),
),
};
Expand Down

0 comments on commit e4f54f4

Please sign in to comment.