drizzle-orm 1.0.0-beta.1-867d080 → 1.0.0-beta.1-e5790ad
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/mysql-core/columns/decimal.cjs +1 -86
- package/mysql-core/columns/decimal.cjs.map +1 -1
- package/mysql-core/columns/decimal.d.cts +3 -47
- package/mysql-core/columns/decimal.d.ts +3 -47
- package/mysql-core/columns/decimal.js +1 -82
- package/mysql-core/columns/decimal.js.map +1 -1
- package/mysql-core/dialect.cjs +0 -3
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.js +0 -3
- package/mysql-core/dialect.js.map +1 -1
- package/neon-http/session.cjs +12 -8
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +2 -0
- package/neon-http/session.d.ts +2 -0
- package/neon-http/session.js +12 -8
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/session.cjs +0 -6
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.js +0 -6
- package/neon-serverless/session.js.map +1 -1
- package/node-postgres/session.cjs +0 -6
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.js +0 -6
- package/node-postgres/session.js.map +1 -1
- package/package.json +1 -1
- package/pg-core/columns/numeric.cjs +1 -86
- package/pg-core/columns/numeric.cjs.map +1 -1
- package/pg-core/columns/numeric.d.cts +6 -61
- package/pg-core/columns/numeric.d.ts +6 -61
- package/pg-core/columns/numeric.js +1 -82
- package/pg-core/columns/numeric.js.map +1 -1
- package/pg-core/dialect.cjs +0 -2
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.js +0 -2
- package/pg-core/dialect.js.map +1 -1
- package/pglite/session.cjs +0 -8
- package/pglite/session.cjs.map +1 -1
- package/pglite/session.js +0 -8
- package/pglite/session.js.map +1 -1
- package/postgres-js/driver.cjs +1 -1
- package/postgres-js/driver.cjs.map +1 -1
- package/postgres-js/driver.js +1 -1
- package/postgres-js/driver.js.map +1 -1
- package/sqlite-core/columns/numeric.cjs +2 -64
- package/sqlite-core/columns/numeric.cjs.map +1 -1
- package/sqlite-core/columns/numeric.d.cts +2 -43
- package/sqlite-core/columns/numeric.d.ts +2 -43
- package/sqlite-core/columns/numeric.js +2 -60
- package/sqlite-core/columns/numeric.js.map +1 -1
- package/sqlite-core/dialect.cjs +0 -5
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.js +0 -5
- package/sqlite-core/dialect.js.map +1 -1
- package/vercel-postgres/session.cjs +0 -6
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.js +0 -6
- package/vercel-postgres/session.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -19,11 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var numeric_exports = {};
|
|
20
20
|
__export(numeric_exports, {
|
|
21
21
|
PgNumeric: () => PgNumeric,
|
|
22
|
-
PgNumericBigInt: () => PgNumericBigInt,
|
|
23
|
-
PgNumericBigIntBuilder: () => PgNumericBigIntBuilder,
|
|
24
22
|
PgNumericBuilder: () => PgNumericBuilder,
|
|
25
|
-
PgNumericNumber: () => PgNumericNumber,
|
|
26
|
-
PgNumericNumberBuilder: () => PgNumericNumberBuilder,
|
|
27
23
|
decimal: () => decimal,
|
|
28
24
|
numeric: () => numeric
|
|
29
25
|
});
|
|
@@ -67,96 +63,15 @@ class PgNumeric extends import_common.PgColumn {
|
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
|
-
class PgNumericNumberBuilder extends import_common.PgColumnBuilder {
|
|
71
|
-
static [import_entity.entityKind] = "PgNumericNumberBuilder";
|
|
72
|
-
constructor(name, precision, scale) {
|
|
73
|
-
super(name, "number", "PgNumericNumber");
|
|
74
|
-
this.config.precision = precision;
|
|
75
|
-
this.config.scale = scale;
|
|
76
|
-
}
|
|
77
|
-
/** @internal */
|
|
78
|
-
build(table) {
|
|
79
|
-
return new PgNumericNumber(
|
|
80
|
-
table,
|
|
81
|
-
this.config
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
class PgNumericNumber extends import_common.PgColumn {
|
|
86
|
-
static [import_entity.entityKind] = "PgNumericNumber";
|
|
87
|
-
precision;
|
|
88
|
-
scale;
|
|
89
|
-
constructor(table, config) {
|
|
90
|
-
super(table, config);
|
|
91
|
-
this.precision = config.precision;
|
|
92
|
-
this.scale = config.scale;
|
|
93
|
-
}
|
|
94
|
-
mapFromDriverValue(value) {
|
|
95
|
-
if (typeof value === "number")
|
|
96
|
-
return value;
|
|
97
|
-
return Number(value);
|
|
98
|
-
}
|
|
99
|
-
mapToDriverValue = String;
|
|
100
|
-
getSQLType() {
|
|
101
|
-
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
102
|
-
return `numeric(${this.precision}, ${this.scale})`;
|
|
103
|
-
} else if (this.precision === void 0) {
|
|
104
|
-
return "numeric";
|
|
105
|
-
} else {
|
|
106
|
-
return `numeric(${this.precision})`;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
class PgNumericBigIntBuilder extends import_common.PgColumnBuilder {
|
|
111
|
-
static [import_entity.entityKind] = "PgNumericBigIntBuilder";
|
|
112
|
-
constructor(name, precision, scale) {
|
|
113
|
-
super(name, "bigint", "PgNumericBigInt");
|
|
114
|
-
this.config.precision = precision;
|
|
115
|
-
this.config.scale = scale;
|
|
116
|
-
}
|
|
117
|
-
/** @internal */
|
|
118
|
-
build(table) {
|
|
119
|
-
return new PgNumericBigInt(
|
|
120
|
-
table,
|
|
121
|
-
this.config
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
class PgNumericBigInt extends import_common.PgColumn {
|
|
126
|
-
static [import_entity.entityKind] = "PgNumericBigInt";
|
|
127
|
-
precision;
|
|
128
|
-
scale;
|
|
129
|
-
constructor(table, config) {
|
|
130
|
-
super(table, config);
|
|
131
|
-
this.precision = config.precision;
|
|
132
|
-
this.scale = config.scale;
|
|
133
|
-
}
|
|
134
|
-
mapFromDriverValue = BigInt;
|
|
135
|
-
mapToDriverValue = String;
|
|
136
|
-
getSQLType() {
|
|
137
|
-
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
138
|
-
return `numeric(${this.precision}, ${this.scale})`;
|
|
139
|
-
} else if (this.precision === void 0) {
|
|
140
|
-
return "numeric";
|
|
141
|
-
} else {
|
|
142
|
-
return `numeric(${this.precision})`;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
66
|
function numeric(a, b) {
|
|
147
67
|
const { name, config } = (0, import_utils.getColumnNameAndConfig)(a, b);
|
|
148
|
-
|
|
149
|
-
return mode === "number" ? new PgNumericNumberBuilder(name, config?.precision, config?.scale) : mode === "bigint" ? new PgNumericBigIntBuilder(name, config?.precision, config?.scale) : new PgNumericBuilder(name, config?.precision, config?.scale);
|
|
68
|
+
return new PgNumericBuilder(name, config?.precision, config?.scale);
|
|
150
69
|
}
|
|
151
70
|
const decimal = numeric;
|
|
152
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
153
72
|
0 && (module.exports = {
|
|
154
73
|
PgNumeric,
|
|
155
|
-
PgNumericBigInt,
|
|
156
|
-
PgNumericBigIntBuilder,
|
|
157
74
|
PgNumericBuilder,
|
|
158
|
-
PgNumericNumber,
|
|
159
|
-
PgNumericNumberBuilder,
|
|
160
75
|
decimal,
|
|
161
76
|
numeric
|
|
162
77
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/pg-core/columns/numeric.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnyPgTable } from '~/pg-core/table.ts';\nimport { type Equal, getColumnNameAndConfig } from '~/utils.ts';\nimport { PgColumn, PgColumnBuilder } from './common.ts';\n\nexport type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'PgNumeric';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBuilder<T extends ColumnBuilderBaseConfig<'string', 'PgNumeric'>> extends PgColumnBuilder<\n\tT,\n\t{\n\t\tprecision: number | undefined;\n\t\tscale: number | undefined;\n\t}\n> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'string', 'PgNumeric');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumeric<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumeric<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumeric';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): string {\n\t\tif (typeof value === 'string') return value;\n\n\t\treturn String(value);\n\t}\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericNumberBuilderInitial<TName extends string> = PgNumericNumberBuilder<{\n\tname: TName;\n\tdataType: 'number';\n\tcolumnType: 'PgNumericNumber';\n\tdata: number;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'PgNumericNumber'>>\n\textends PgColumnBuilder<\n\t\tT,\n\t\t{\n\t\t\tprecision: number | undefined;\n\t\t\tscale: number | undefined;\n\t\t}\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'PgNumericNumberBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'number', 'PgNumericNumber');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumericNumber<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumericNumber<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class PgNumericNumber<T extends ColumnBaseConfig<'number', 'PgNumericNumber'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumericNumber';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericNumberBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): number {\n\t\tif (typeof value === 'number') return value;\n\n\t\treturn Number(value);\n\t}\n\n\toverride mapToDriverValue = String;\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericBigIntBuilderInitial<TName extends string> = PgNumericBigIntBuilder<{\n\tname: TName;\n\tdataType: 'bigint';\n\tcolumnType: 'PgNumericBigInt';\n\tdata: bigint;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'PgNumericBigInt'>>\n\textends PgColumnBuilder<\n\t\tT,\n\t\t{\n\t\t\tprecision: number | undefined;\n\t\t\tscale: number | undefined;\n\t\t}\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'PgNumericBigIntBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'bigint', 'PgNumericBigInt');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumericBigInt<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumericBigInt<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class PgNumericBigInt<T extends ColumnBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBigInt';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBigIntBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue = BigInt;\n\n\toverride mapToDriverValue = String;\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> =\n\t| { precision: number; scale?: number; mode?: T }\n\t| { precision?: number; scale: number; mode?: T }\n\t| { precision?: number; scale?: number; mode: T };\n\nexport function numeric<TMode extends 'string' | 'number' | 'bigint'>(\n\tconfig?: PgNumericConfig<TMode>,\n): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<''>\n\t: Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<''>\n\t: PgNumericBuilderInitial<''>;\nexport function numeric<TName extends string, TMode extends 'string' | 'number' | 'bigint'>(\n\tname: TName,\n\tconfig?: PgNumericConfig<TMode>,\n): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<TName>\n\t: Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<TName>\n\t: PgNumericBuilderInitial<TName>;\nexport function numeric(a?: string | PgNumericConfig, b?: PgNumericConfig) {\n\tconst { name, config } = getColumnNameAndConfig<PgNumericConfig>(a, b);\n\tconst mode = config?.mode;\n\treturn mode === 'number'\n\t\t? new PgNumericNumberBuilder(name, config?.precision, config?.scale)\n\t\t: mode === 'bigint'\n\t\t? new PgNumericBigIntBuilder(name, config?.precision, config?.scale)\n\t\t: new PgNumericBuilder(name, config?.precision, config?.scale);\n}\n\nexport const decimal = numeric;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,mBAAmD;AACnD,oBAA0C;AAWnC,MAAM,yBAAmF,8BAM9F;AAAA,EACD,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,WAAoB,OAAgB;AAChE,UAAM,MAAM,UAAU,WAAW;AACjC,SAAK,OAAO,YAAY;AACxB,SAAK,OAAO,QAAQ;AAAA,EACrB;AAAA;AAAA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AuB,MAAM,QAAQ,WAAW,QAAQ,KAAK,IACjE,IAAI,iBAAiB,MAAM,QAAQ,WAAW,QAAQ,KAAK;AAC/D;AAEO,MAAM,UAAU;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/pg-core/columns/numeric.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnyPgTable } from '~/pg-core/table.ts';\nimport { getColumnNameAndConfig } from '~/utils.ts';\nimport { PgColumn, PgColumnBuilder } from './common.ts';\n\nexport type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'PgNumeric';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBuilder<T extends ColumnBuilderBaseConfig<'string', 'PgNumeric'>> extends PgColumnBuilder<\n\tT,\n\t{\n\t\tprecision: number | undefined;\n\t\tscale: number | undefined;\n\t}\n> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'string', 'PgNumeric');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumeric<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumeric<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumeric';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): string {\n\t\tif (typeof value === 'string') return value;\n\n\t\treturn String(value);\n\t}\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericConfig =\n\t| { precision: number; scale?: number }\n\t| { precision?: number; scale: number }\n\t| { precision: number; scale: number };\n\nexport function numeric(): PgNumericBuilderInitial<''>;\nexport function numeric(\n\tconfig?: PgNumericConfig,\n): PgNumericBuilderInitial<''>;\nexport function numeric<TName extends string>(\n\tname: TName,\n\tconfig?: PgNumericConfig,\n): PgNumericBuilderInitial<TName>;\nexport function numeric(a?: string | PgNumericConfig, b?: PgNumericConfig) {\n\tconst { name, config } = getColumnNameAndConfig<PgNumericConfig>(a, b);\n\treturn new PgNumericBuilder(name, config?.precision, config?.scale);\n}\n\nexport const decimal = numeric;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAA2B;AAE3B,mBAAuC;AACvC,oBAA0C;AAWnC,MAAM,yBAAmF,8BAM9F;AAAA,EACD,QAA0B,wBAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,WAAoB,OAAgB;AAChE,UAAM,MAAM,UAAU,WAAW;AACjC,SAAK,OAAO,YAAY;AACxB,SAAK,OAAO,QAAQ;AAAA,EACrB;AAAA;AAAA,EAGS,MACR,OAC6C;AAC7C,WAAO,IAAI,UAA2C,OAAO,KAAK,MAA8C;AAAA,EACjH;AACD;AAEO,MAAM,kBAAqE,uBAAY;AAAA,EAC7F,QAA0B,wBAAU,IAAY;AAAA,EAEvC;AAAA,EACA;AAAA,EAET,YAAY,OAA6C,QAAuC;AAC/F,UAAM,OAAO,MAAM;AACnB,SAAK,YAAY,OAAO;AACxB,SAAK,QAAQ,OAAO;AAAA,EACrB;AAAA,EAES,mBAAmB,OAAwB;AACnD,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,WAAO,OAAO,KAAK;AAAA,EACpB;AAAA,EAEA,aAAqB;AACpB,QAAI,KAAK,cAAc,UAAa,KAAK,UAAU,QAAW;AAC7D,aAAO,WAAW,KAAK,SAAS,KAAK,KAAK,KAAK;AAAA,IAChD,WAAW,KAAK,cAAc,QAAW;AACxC,aAAO;AAAA,IACR,OAAO;AACN,aAAO,WAAW,KAAK,SAAS;AAAA,IACjC;AAAA,EACD;AACD;AAeO,SAAS,QAAQ,GAA8B,GAAqB;AAC1E,QAAM,EAAE,MAAM,OAAO,QAAI,qCAAwC,GAAG,CAAC;AACrE,SAAO,IAAI,iBAAiB,MAAM,QAAQ,WAAW,QAAQ,KAAK;AACnE;AAEO,MAAM,UAAU;","names":[]}
|
|
@@ -2,7 +2,6 @@ import type { ColumnBuilderBaseConfig } from "../../column-builder.cjs";
|
|
|
2
2
|
import type { ColumnBaseConfig } from "../../column.cjs";
|
|
3
3
|
import { entityKind } from "../../entity.cjs";
|
|
4
4
|
import type { AnyPgTable } from "../table.cjs";
|
|
5
|
-
import { type Equal } from "../../utils.cjs";
|
|
6
5
|
import { PgColumn, PgColumnBuilder } from "./common.cjs";
|
|
7
6
|
export type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{
|
|
8
7
|
name: TName;
|
|
@@ -29,71 +28,17 @@ export declare class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>
|
|
|
29
28
|
mapFromDriverValue(value: unknown): string;
|
|
30
29
|
getSQLType(): string;
|
|
31
30
|
}
|
|
32
|
-
export type
|
|
33
|
-
name: TName;
|
|
34
|
-
dataType: 'number';
|
|
35
|
-
columnType: 'PgNumericNumber';
|
|
36
|
-
data: number;
|
|
37
|
-
driverParam: string;
|
|
38
|
-
enumValues: undefined;
|
|
39
|
-
}>;
|
|
40
|
-
export declare class PgNumericNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'PgNumericNumber'>> extends PgColumnBuilder<T, {
|
|
41
|
-
precision: number | undefined;
|
|
42
|
-
scale: number | undefined;
|
|
43
|
-
}> {
|
|
44
|
-
static readonly [entityKind]: string;
|
|
45
|
-
constructor(name: T['name'], precision?: number, scale?: number);
|
|
46
|
-
}
|
|
47
|
-
export declare class PgNumericNumber<T extends ColumnBaseConfig<'number', 'PgNumericNumber'>> extends PgColumn<T> {
|
|
48
|
-
static readonly [entityKind]: string;
|
|
49
|
-
readonly precision: number | undefined;
|
|
50
|
-
readonly scale: number | undefined;
|
|
51
|
-
constructor(table: AnyPgTable<{
|
|
52
|
-
name: T['tableName'];
|
|
53
|
-
}>, config: PgNumericNumberBuilder<T>['config']);
|
|
54
|
-
mapFromDriverValue(value: unknown): number;
|
|
55
|
-
mapToDriverValue: StringConstructor;
|
|
56
|
-
getSQLType(): string;
|
|
57
|
-
}
|
|
58
|
-
export type PgNumericBigIntBuilderInitial<TName extends string> = PgNumericBigIntBuilder<{
|
|
59
|
-
name: TName;
|
|
60
|
-
dataType: 'bigint';
|
|
61
|
-
columnType: 'PgNumericBigInt';
|
|
62
|
-
data: bigint;
|
|
63
|
-
driverParam: string;
|
|
64
|
-
enumValues: undefined;
|
|
65
|
-
}>;
|
|
66
|
-
export declare class PgNumericBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumnBuilder<T, {
|
|
67
|
-
precision: number | undefined;
|
|
68
|
-
scale: number | undefined;
|
|
69
|
-
}> {
|
|
70
|
-
static readonly [entityKind]: string;
|
|
71
|
-
constructor(name: T['name'], precision?: number, scale?: number);
|
|
72
|
-
}
|
|
73
|
-
export declare class PgNumericBigInt<T extends ColumnBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumn<T> {
|
|
74
|
-
static readonly [entityKind]: string;
|
|
75
|
-
readonly precision: number | undefined;
|
|
76
|
-
readonly scale: number | undefined;
|
|
77
|
-
constructor(table: AnyPgTable<{
|
|
78
|
-
name: T['tableName'];
|
|
79
|
-
}>, config: PgNumericBigIntBuilder<T>['config']);
|
|
80
|
-
mapFromDriverValue: BigIntConstructor;
|
|
81
|
-
mapToDriverValue: StringConstructor;
|
|
82
|
-
getSQLType(): string;
|
|
83
|
-
}
|
|
84
|
-
export type PgNumericConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> = {
|
|
31
|
+
export type PgNumericConfig = {
|
|
85
32
|
precision: number;
|
|
86
33
|
scale?: number;
|
|
87
|
-
mode?: T;
|
|
88
34
|
} | {
|
|
89
35
|
precision?: number;
|
|
90
36
|
scale: number;
|
|
91
|
-
mode?: T;
|
|
92
37
|
} | {
|
|
93
|
-
precision
|
|
94
|
-
scale
|
|
95
|
-
mode: T;
|
|
38
|
+
precision: number;
|
|
39
|
+
scale: number;
|
|
96
40
|
};
|
|
97
|
-
export declare function numeric
|
|
98
|
-
export declare function numeric
|
|
41
|
+
export declare function numeric(): PgNumericBuilderInitial<''>;
|
|
42
|
+
export declare function numeric(config?: PgNumericConfig): PgNumericBuilderInitial<''>;
|
|
43
|
+
export declare function numeric<TName extends string>(name: TName, config?: PgNumericConfig): PgNumericBuilderInitial<TName>;
|
|
99
44
|
export declare const decimal: typeof numeric;
|
|
@@ -2,7 +2,6 @@ import type { ColumnBuilderBaseConfig } from "../../column-builder.js";
|
|
|
2
2
|
import type { ColumnBaseConfig } from "../../column.js";
|
|
3
3
|
import { entityKind } from "../../entity.js";
|
|
4
4
|
import type { AnyPgTable } from "../table.js";
|
|
5
|
-
import { type Equal } from "../../utils.js";
|
|
6
5
|
import { PgColumn, PgColumnBuilder } from "./common.js";
|
|
7
6
|
export type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{
|
|
8
7
|
name: TName;
|
|
@@ -29,71 +28,17 @@ export declare class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>
|
|
|
29
28
|
mapFromDriverValue(value: unknown): string;
|
|
30
29
|
getSQLType(): string;
|
|
31
30
|
}
|
|
32
|
-
export type
|
|
33
|
-
name: TName;
|
|
34
|
-
dataType: 'number';
|
|
35
|
-
columnType: 'PgNumericNumber';
|
|
36
|
-
data: number;
|
|
37
|
-
driverParam: string;
|
|
38
|
-
enumValues: undefined;
|
|
39
|
-
}>;
|
|
40
|
-
export declare class PgNumericNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'PgNumericNumber'>> extends PgColumnBuilder<T, {
|
|
41
|
-
precision: number | undefined;
|
|
42
|
-
scale: number | undefined;
|
|
43
|
-
}> {
|
|
44
|
-
static readonly [entityKind]: string;
|
|
45
|
-
constructor(name: T['name'], precision?: number, scale?: number);
|
|
46
|
-
}
|
|
47
|
-
export declare class PgNumericNumber<T extends ColumnBaseConfig<'number', 'PgNumericNumber'>> extends PgColumn<T> {
|
|
48
|
-
static readonly [entityKind]: string;
|
|
49
|
-
readonly precision: number | undefined;
|
|
50
|
-
readonly scale: number | undefined;
|
|
51
|
-
constructor(table: AnyPgTable<{
|
|
52
|
-
name: T['tableName'];
|
|
53
|
-
}>, config: PgNumericNumberBuilder<T>['config']);
|
|
54
|
-
mapFromDriverValue(value: unknown): number;
|
|
55
|
-
mapToDriverValue: StringConstructor;
|
|
56
|
-
getSQLType(): string;
|
|
57
|
-
}
|
|
58
|
-
export type PgNumericBigIntBuilderInitial<TName extends string> = PgNumericBigIntBuilder<{
|
|
59
|
-
name: TName;
|
|
60
|
-
dataType: 'bigint';
|
|
61
|
-
columnType: 'PgNumericBigInt';
|
|
62
|
-
data: bigint;
|
|
63
|
-
driverParam: string;
|
|
64
|
-
enumValues: undefined;
|
|
65
|
-
}>;
|
|
66
|
-
export declare class PgNumericBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumnBuilder<T, {
|
|
67
|
-
precision: number | undefined;
|
|
68
|
-
scale: number | undefined;
|
|
69
|
-
}> {
|
|
70
|
-
static readonly [entityKind]: string;
|
|
71
|
-
constructor(name: T['name'], precision?: number, scale?: number);
|
|
72
|
-
}
|
|
73
|
-
export declare class PgNumericBigInt<T extends ColumnBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumn<T> {
|
|
74
|
-
static readonly [entityKind]: string;
|
|
75
|
-
readonly precision: number | undefined;
|
|
76
|
-
readonly scale: number | undefined;
|
|
77
|
-
constructor(table: AnyPgTable<{
|
|
78
|
-
name: T['tableName'];
|
|
79
|
-
}>, config: PgNumericBigIntBuilder<T>['config']);
|
|
80
|
-
mapFromDriverValue: BigIntConstructor;
|
|
81
|
-
mapToDriverValue: StringConstructor;
|
|
82
|
-
getSQLType(): string;
|
|
83
|
-
}
|
|
84
|
-
export type PgNumericConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> = {
|
|
31
|
+
export type PgNumericConfig = {
|
|
85
32
|
precision: number;
|
|
86
33
|
scale?: number;
|
|
87
|
-
mode?: T;
|
|
88
34
|
} | {
|
|
89
35
|
precision?: number;
|
|
90
36
|
scale: number;
|
|
91
|
-
mode?: T;
|
|
92
37
|
} | {
|
|
93
|
-
precision
|
|
94
|
-
scale
|
|
95
|
-
mode: T;
|
|
38
|
+
precision: number;
|
|
39
|
+
scale: number;
|
|
96
40
|
};
|
|
97
|
-
export declare function numeric
|
|
98
|
-
export declare function numeric
|
|
41
|
+
export declare function numeric(): PgNumericBuilderInitial<''>;
|
|
42
|
+
export declare function numeric(config?: PgNumericConfig): PgNumericBuilderInitial<''>;
|
|
43
|
+
export declare function numeric<TName extends string>(name: TName, config?: PgNumericConfig): PgNumericBuilderInitial<TName>;
|
|
99
44
|
export declare const decimal: typeof numeric;
|
|
@@ -37,95 +37,14 @@ class PgNumeric extends PgColumn {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
class PgNumericNumberBuilder extends PgColumnBuilder {
|
|
41
|
-
static [entityKind] = "PgNumericNumberBuilder";
|
|
42
|
-
constructor(name, precision, scale) {
|
|
43
|
-
super(name, "number", "PgNumericNumber");
|
|
44
|
-
this.config.precision = precision;
|
|
45
|
-
this.config.scale = scale;
|
|
46
|
-
}
|
|
47
|
-
/** @internal */
|
|
48
|
-
build(table) {
|
|
49
|
-
return new PgNumericNumber(
|
|
50
|
-
table,
|
|
51
|
-
this.config
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
class PgNumericNumber extends PgColumn {
|
|
56
|
-
static [entityKind] = "PgNumericNumber";
|
|
57
|
-
precision;
|
|
58
|
-
scale;
|
|
59
|
-
constructor(table, config) {
|
|
60
|
-
super(table, config);
|
|
61
|
-
this.precision = config.precision;
|
|
62
|
-
this.scale = config.scale;
|
|
63
|
-
}
|
|
64
|
-
mapFromDriverValue(value) {
|
|
65
|
-
if (typeof value === "number")
|
|
66
|
-
return value;
|
|
67
|
-
return Number(value);
|
|
68
|
-
}
|
|
69
|
-
mapToDriverValue = String;
|
|
70
|
-
getSQLType() {
|
|
71
|
-
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
72
|
-
return `numeric(${this.precision}, ${this.scale})`;
|
|
73
|
-
} else if (this.precision === void 0) {
|
|
74
|
-
return "numeric";
|
|
75
|
-
} else {
|
|
76
|
-
return `numeric(${this.precision})`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
class PgNumericBigIntBuilder extends PgColumnBuilder {
|
|
81
|
-
static [entityKind] = "PgNumericBigIntBuilder";
|
|
82
|
-
constructor(name, precision, scale) {
|
|
83
|
-
super(name, "bigint", "PgNumericBigInt");
|
|
84
|
-
this.config.precision = precision;
|
|
85
|
-
this.config.scale = scale;
|
|
86
|
-
}
|
|
87
|
-
/** @internal */
|
|
88
|
-
build(table) {
|
|
89
|
-
return new PgNumericBigInt(
|
|
90
|
-
table,
|
|
91
|
-
this.config
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
class PgNumericBigInt extends PgColumn {
|
|
96
|
-
static [entityKind] = "PgNumericBigInt";
|
|
97
|
-
precision;
|
|
98
|
-
scale;
|
|
99
|
-
constructor(table, config) {
|
|
100
|
-
super(table, config);
|
|
101
|
-
this.precision = config.precision;
|
|
102
|
-
this.scale = config.scale;
|
|
103
|
-
}
|
|
104
|
-
mapFromDriverValue = BigInt;
|
|
105
|
-
mapToDriverValue = String;
|
|
106
|
-
getSQLType() {
|
|
107
|
-
if (this.precision !== void 0 && this.scale !== void 0) {
|
|
108
|
-
return `numeric(${this.precision}, ${this.scale})`;
|
|
109
|
-
} else if (this.precision === void 0) {
|
|
110
|
-
return "numeric";
|
|
111
|
-
} else {
|
|
112
|
-
return `numeric(${this.precision})`;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
40
|
function numeric(a, b) {
|
|
117
41
|
const { name, config } = getColumnNameAndConfig(a, b);
|
|
118
|
-
|
|
119
|
-
return mode === "number" ? new PgNumericNumberBuilder(name, config?.precision, config?.scale) : mode === "bigint" ? new PgNumericBigIntBuilder(name, config?.precision, config?.scale) : new PgNumericBuilder(name, config?.precision, config?.scale);
|
|
42
|
+
return new PgNumericBuilder(name, config?.precision, config?.scale);
|
|
120
43
|
}
|
|
121
44
|
const decimal = numeric;
|
|
122
45
|
export {
|
|
123
46
|
PgNumeric,
|
|
124
|
-
PgNumericBigInt,
|
|
125
|
-
PgNumericBigIntBuilder,
|
|
126
47
|
PgNumericBuilder,
|
|
127
|
-
PgNumericNumber,
|
|
128
|
-
PgNumericNumberBuilder,
|
|
129
48
|
decimal,
|
|
130
49
|
numeric
|
|
131
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/pg-core/columns/numeric.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnyPgTable } from '~/pg-core/table.ts';\nimport { type Equal, getColumnNameAndConfig } from '~/utils.ts';\nimport { PgColumn, PgColumnBuilder } from './common.ts';\n\nexport type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'PgNumeric';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBuilder<T extends ColumnBuilderBaseConfig<'string', 'PgNumeric'>> extends PgColumnBuilder<\n\tT,\n\t{\n\t\tprecision: number | undefined;\n\t\tscale: number | undefined;\n\t}\n> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'string', 'PgNumeric');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumeric<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumeric<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumeric';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): string {\n\t\tif (typeof value === 'string') return value;\n\n\t\treturn String(value);\n\t}\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericNumberBuilderInitial<TName extends string> = PgNumericNumberBuilder<{\n\tname: TName;\n\tdataType: 'number';\n\tcolumnType: 'PgNumericNumber';\n\tdata: number;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericNumberBuilder<T extends ColumnBuilderBaseConfig<'number', 'PgNumericNumber'>>\n\textends PgColumnBuilder<\n\t\tT,\n\t\t{\n\t\t\tprecision: number | undefined;\n\t\t\tscale: number | undefined;\n\t\t}\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'PgNumericNumberBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'number', 'PgNumericNumber');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumericNumber<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumericNumber<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class PgNumericNumber<T extends ColumnBaseConfig<'number', 'PgNumericNumber'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumericNumber';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericNumberBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): number {\n\t\tif (typeof value === 'number') return value;\n\n\t\treturn Number(value);\n\t}\n\n\toverride mapToDriverValue = String;\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericBigIntBuilderInitial<TName extends string> = PgNumericBigIntBuilder<{\n\tname: TName;\n\tdataType: 'bigint';\n\tcolumnType: 'PgNumericBigInt';\n\tdata: bigint;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBigIntBuilder<T extends ColumnBuilderBaseConfig<'bigint', 'PgNumericBigInt'>>\n\textends PgColumnBuilder<\n\t\tT,\n\t\t{\n\t\t\tprecision: number | undefined;\n\t\t\tscale: number | undefined;\n\t\t}\n\t>\n{\n\tstatic override readonly [entityKind]: string = 'PgNumericBigIntBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'bigint', 'PgNumericBigInt');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumericBigInt<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumericBigInt<MakeColumnConfig<T, TTableName>>(\n\t\t\ttable,\n\t\t\tthis.config as ColumnBuilderRuntimeConfig<any, any>,\n\t\t);\n\t}\n}\n\nexport class PgNumericBigInt<T extends ColumnBaseConfig<'bigint', 'PgNumericBigInt'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBigInt';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBigIntBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue = BigInt;\n\n\toverride mapToDriverValue = String;\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericConfig<T extends 'string' | 'number' | 'bigint' = 'string' | 'number' | 'bigint'> =\n\t| { precision: number; scale?: number; mode?: T }\n\t| { precision?: number; scale: number; mode?: T }\n\t| { precision?: number; scale?: number; mode: T };\n\nexport function numeric<TMode extends 'string' | 'number' | 'bigint'>(\n\tconfig?: PgNumericConfig<TMode>,\n): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<''>\n\t: Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<''>\n\t: PgNumericBuilderInitial<''>;\nexport function numeric<TName extends string, TMode extends 'string' | 'number' | 'bigint'>(\n\tname: TName,\n\tconfig?: PgNumericConfig<TMode>,\n): Equal<TMode, 'number'> extends true ? PgNumericNumberBuilderInitial<TName>\n\t: Equal<TMode, 'bigint'> extends true ? PgNumericBigIntBuilderInitial<TName>\n\t: PgNumericBuilderInitial<TName>;\nexport function numeric(a?: string | PgNumericConfig, b?: PgNumericConfig) {\n\tconst { name, config } = getColumnNameAndConfig<PgNumericConfig>(a, b);\n\tconst mode = config?.mode;\n\treturn mode === 'number'\n\t\t? new PgNumericNumberBuilder(name, config?.precision, config?.scale)\n\t\t: mode === 'bigint'\n\t\t? new PgNumericBigIntBuilder(name, config?.precision, config?.scale)\n\t\t: new PgNumericBuilder(name, config?.precision, config?.scale);\n}\n\nexport const decimal = numeric;\n"],"mappings":"AAEA,SAAS,kBAAkB;AAE3B,SAAqB,8BAA8B;AACnD,SAAS,UAAU,uBAAuB;AAWnC,MAAM,yBAAmF,gBAM9F;AAAA,EACD,QAA0B,UAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,WAAoB,OAAgB;AAChE,UAAM,MAAM,UAAU,WAAW;AACjC,SAAK,OAAO,YAAY;AACxB,SAAK,OAAO,QAAQ;AAAA,EACrB;AAA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B,MAAM,QAAQ,WAAW,QAAQ,KAAK,IACjE,IAAI,iBAAiB,MAAM,QAAQ,WAAW,QAAQ,KAAK;AAC/D;AAEO,MAAM,UAAU;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/pg-core/columns/numeric.ts"],"sourcesContent":["import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';\nimport type { ColumnBaseConfig } from '~/column.ts';\nimport { entityKind } from '~/entity.ts';\nimport type { AnyPgTable } from '~/pg-core/table.ts';\nimport { getColumnNameAndConfig } from '~/utils.ts';\nimport { PgColumn, PgColumnBuilder } from './common.ts';\n\nexport type PgNumericBuilderInitial<TName extends string> = PgNumericBuilder<{\n\tname: TName;\n\tdataType: 'string';\n\tcolumnType: 'PgNumeric';\n\tdata: string;\n\tdriverParam: string;\n\tenumValues: undefined;\n}>;\n\nexport class PgNumericBuilder<T extends ColumnBuilderBaseConfig<'string', 'PgNumeric'>> extends PgColumnBuilder<\n\tT,\n\t{\n\t\tprecision: number | undefined;\n\t\tscale: number | undefined;\n\t}\n> {\n\tstatic override readonly [entityKind]: string = 'PgNumericBuilder';\n\n\tconstructor(name: T['name'], precision?: number, scale?: number) {\n\t\tsuper(name, 'string', 'PgNumeric');\n\t\tthis.config.precision = precision;\n\t\tthis.config.scale = scale;\n\t}\n\n\t/** @internal */\n\toverride build<TTableName extends string>(\n\t\ttable: AnyPgTable<{ name: TTableName }>,\n\t): PgNumeric<MakeColumnConfig<T, TTableName>> {\n\t\treturn new PgNumeric<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);\n\t}\n}\n\nexport class PgNumeric<T extends ColumnBaseConfig<'string', 'PgNumeric'>> extends PgColumn<T> {\n\tstatic override readonly [entityKind]: string = 'PgNumeric';\n\n\treadonly precision: number | undefined;\n\treadonly scale: number | undefined;\n\n\tconstructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgNumericBuilder<T>['config']) {\n\t\tsuper(table, config);\n\t\tthis.precision = config.precision;\n\t\tthis.scale = config.scale;\n\t}\n\n\toverride mapFromDriverValue(value: unknown): string {\n\t\tif (typeof value === 'string') return value;\n\n\t\treturn String(value);\n\t}\n\n\tgetSQLType(): string {\n\t\tif (this.precision !== undefined && this.scale !== undefined) {\n\t\t\treturn `numeric(${this.precision}, ${this.scale})`;\n\t\t} else if (this.precision === undefined) {\n\t\t\treturn 'numeric';\n\t\t} else {\n\t\t\treturn `numeric(${this.precision})`;\n\t\t}\n\t}\n}\n\nexport type PgNumericConfig =\n\t| { precision: number; scale?: number }\n\t| { precision?: number; scale: number }\n\t| { precision: number; scale: number };\n\nexport function numeric(): PgNumericBuilderInitial<''>;\nexport function numeric(\n\tconfig?: PgNumericConfig,\n): PgNumericBuilderInitial<''>;\nexport function numeric<TName extends string>(\n\tname: TName,\n\tconfig?: PgNumericConfig,\n): PgNumericBuilderInitial<TName>;\nexport function numeric(a?: string | PgNumericConfig, b?: PgNumericConfig) {\n\tconst { name, config } = getColumnNameAndConfig<PgNumericConfig>(a, b);\n\treturn new PgNumericBuilder(name, config?.precision, config?.scale);\n}\n\nexport const decimal = numeric;\n"],"mappings":"AAEA,SAAS,kBAAkB;AAE3B,SAAS,8BAA8B;AACvC,SAAS,UAAU,uBAAuB;AAWnC,MAAM,yBAAmF,gBAM9F;AAAA,EACD,QAA0B,UAAU,IAAY;AAAA,EAEhD,YAAY,MAAiB,WAAoB,OAAgB;AAChE,UAAM,MAAM,UAAU,WAAW;AACjC,SAAK,OAAO,YAAY;AACxB,SAAK,OAAO,QAAQ;AAAA,EACrB;AAAA;AAAA,EAGS,MACR,OAC6C;AAC7C,WAAO,IAAI,UAA2C,OAAO,KAAK,MAA8C;AAAA,EACjH;AACD;AAEO,MAAM,kBAAqE,SAAY;AAAA,EAC7F,QAA0B,UAAU,IAAY;AAAA,EAEvC;AAAA,EACA;AAAA,EAET,YAAY,OAA6C,QAAuC;AAC/F,UAAM,OAAO,MAAM;AACnB,SAAK,YAAY,OAAO;AACxB,SAAK,QAAQ,OAAO;AAAA,EACrB;AAAA,EAES,mBAAmB,OAAwB;AACnD,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,WAAO,OAAO,KAAK;AAAA,EACpB;AAAA,EAEA,aAAqB;AACpB,QAAI,KAAK,cAAc,UAAa,KAAK,UAAU,QAAW;AAC7D,aAAO,WAAW,KAAK,SAAS,KAAK,KAAK,KAAK;AAAA,IAChD,WAAW,KAAK,cAAc,QAAW;AACxC,aAAO;AAAA,IACR,OAAO;AACN,aAAO,WAAW,KAAK,SAAS;AAAA,IACjC;AAAA,EACD;AACD;AAeO,SAAS,QAAQ,GAA8B,GAAqB;AAC1E,QAAM,EAAE,MAAM,OAAO,IAAI,uBAAwC,GAAG,CAAC;AACrE,SAAO,IAAI,iBAAiB,MAAM,QAAQ,WAAW,QAAQ,KAAK;AACnE;AAEO,MAAM,UAAU;","names":[]}
|