Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions drizzle-arktype/tests/mysql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,10 @@ test('all data types', (t) => {
}) => ({
bigint1: bigint({ mode: 'number' }).notNull(),
bigint2: bigint({ mode: 'bigint' }).notNull(),
bigint3: bigint({ unsigned: true, mode: 'number' }).notNull(),
bigint4: bigint({ unsigned: true, mode: 'bigint' }).notNull(),
bigint3: bigint({ mode: 'string' }).notNull(),
bigint4: bigint({ unsigned: true, mode: 'number' }).notNull(),
bigint5: bigint({ unsigned: true, mode: 'bigint' }).notNull(),
bigint6: bigint({ unsigned: true, mode: 'string' }).notNull(),
binary: binary({ length: 10 }).notNull(),
boolean: boolean().notNull(),
char1: char({ length: 10 }).notNull(),
Expand Down Expand Up @@ -406,8 +408,10 @@ test('all data types', (t) => {
const expected = type({
bigint1: type.keywords.number.integer.atLeast(Number.MIN_SAFE_INTEGER).atMost(Number.MAX_SAFE_INTEGER),
bigint2: type.bigint.narrow(bigintNarrow),
bigint3: type.keywords.number.integer.atLeast(0).atMost(Number.MAX_SAFE_INTEGER),
bigint4: type.bigint.narrow(unsignedBigintNarrow),
bigint3: type.string,
bigint4: type.keywords.number.integer.atLeast(0).atMost(Number.MAX_SAFE_INTEGER),
bigint5: type.bigint.narrow(unsignedBigintNarrow),
bigint6: type.string,
binary: type.string,
boolean: type.boolean,
char1: type.string.exactlyLength(10),
Expand Down
2 changes: 2 additions & 0 deletions drizzle-arktype/tests/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ test('all data types', (t) => {
}) => ({
bigint1: bigint({ mode: 'number' }).notNull(),
bigint2: bigint({ mode: 'bigint' }).notNull(),
bigint3: bigint({ mode: 'string' }).notNull(),
bigserial1: bigserial({ mode: 'number' }).notNull(),
bigserial2: bigserial({ mode: 'bigint' }).notNull(),
bit: bit({ dimensions: 5 }).notNull(),
Expand Down Expand Up @@ -455,6 +456,7 @@ test('all data types', (t) => {
const expected = type({
bigint1: type.keywords.number.integer.atLeast(Number.MIN_SAFE_INTEGER).atMost(Number.MAX_SAFE_INTEGER),
bigint2: type.bigint.narrow(bigintNarrow),
bigint3: type.string,
bigserial1: type.keywords.number.integer.atLeast(Number.MIN_SAFE_INTEGER).atMost(Number.MAX_SAFE_INTEGER),
bigserial2: type.bigint.narrow(bigintNarrow),
bit: type(/^[01]{5}$/).describe('a string containing ones or zeros while being 5 characters long'),
Expand Down
12 changes: 8 additions & 4 deletions drizzle-arktype/tests/singlestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ test('all data types', (t) => {
}) => ({
bigint1: bigint({ mode: 'number' }).notNull(),
bigint2: bigint({ mode: 'bigint' }).notNull(),
bigint3: bigint({ unsigned: true, mode: 'number' }).notNull(),
bigint4: bigint({ unsigned: true, mode: 'bigint' }).notNull(),
bigint3: bigint({ mode: 'string' }).notNull(),
bigint4: bigint({ unsigned: true, mode: 'number' }).notNull(),
bigint5: bigint({ unsigned: true, mode: 'bigint' }).notNull(),
bigint6: bigint({ unsigned: true, mode: 'string' }).notNull(),
binary: binary({ length: 10 }).notNull(),
boolean: boolean().notNull(),
char1: char({ length: 10 }).notNull(),
Expand Down Expand Up @@ -408,8 +410,10 @@ test('all data types', (t) => {
const expected = type({
bigint1: type.keywords.number.integer.atLeast(Number.MIN_SAFE_INTEGER).atMost(Number.MAX_SAFE_INTEGER),
bigint2: type.bigint.narrow(bigintNarrow),
bigint3: type.keywords.number.integer.atLeast(0).atMost(Number.MAX_SAFE_INTEGER),
bigint4: type.bigint.narrow(unsignedBigintNarrow),
bigint3: type.string,
bigint4: type.keywords.number.integer.atLeast(0).atMost(Number.MAX_SAFE_INTEGER),
bigint5: type.bigint.narrow(unsignedBigintNarrow),
bigint6: type.string,
binary: type.string,
boolean: type.boolean,
char1: type.string.exactlyLength(10),
Expand Down
61 changes: 58 additions & 3 deletions drizzle-orm/src/mysql-core/columns/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,52 @@ export class MySqlBigInt53<T extends ColumnBaseConfig<'number', 'MySqlBigInt53'>
}
}

export type MySqlBigIntStringBuilderInitial<TName extends string> = MySqlBigIntStringBuilder<{
name: TName;
dataType: 'string';
columnType: 'MySqlBigIntString';
data: string;
driverParam: string;
enumValues: undefined;
unsigned?: boolean;
}>;

export class MySqlBigIntStringBuilder<T extends ColumnBuilderBaseConfig<'string', 'MySqlBigIntString'>>
extends MySqlColumnBuilderWithAutoIncrement<T, { unsigned: boolean }>
{
static override readonly [entityKind]: string = 'MySqlBigIntStringBuilder';

constructor(name: T['name'], unsigned: boolean = false) {
super(name, 'string', 'MySqlBigIntString');
this.config.unsigned = unsigned;
}

/** @internal */
override build<TTableName extends string>(
table: AnyMySqlTable<{ name: TTableName }>,
): MySqlBigIntString<MakeColumnConfig<T, TTableName>> {
return new MySqlBigIntString<MakeColumnConfig<T, TTableName>>(
table,
this.config as ColumnBuilderRuntimeConfig<any, any>,
);
}
}

export class MySqlBigIntString<T extends ColumnBaseConfig<'string', 'MySqlBigIntString'>>
extends MySqlColumnWithAutoIncrement<T, { unsigned: boolean }>
{
static override readonly [entityKind]: string = 'MySqlBigIntString';

getSQLType(): string {
return `bigint${this.config.unsigned ? ' unsigned' : ''}`;
}

// eslint-disable-next-line unicorn/prefer-native-coercion-functions
override mapFromDriverValue(value: string | number): string {
return String(value);
}
}

export type MySqlBigInt64BuilderInitial<TName extends string> = MySqlBigInt64Builder<{
name: TName;
dataType: 'bigint';
Expand Down Expand Up @@ -97,22 +143,31 @@ export class MySqlBigInt64<T extends ColumnBaseConfig<'bigint', 'MySqlBigInt64'>
}
}

export interface MySqlBigIntConfig<T extends 'number' | 'bigint' = 'number' | 'bigint'> {
export interface MySqlBigIntConfig<T extends 'number' | 'string' | 'bigint' = 'number' | 'string' | 'bigint'> {
mode: T;
unsigned?: boolean;
}

export function bigint<TMode extends MySqlBigIntConfig['mode']>(
config: MySqlBigIntConfig<TMode>,
): TMode extends 'number' ? MySqlBigInt53BuilderInitial<''> : MySqlBigInt64BuilderInitial<''>;
): TMode extends 'number' ? MySqlBigInt53BuilderInitial<''>
: TMode extends 'string' ? MySqlBigIntStringBuilderInitial<''>
: MySqlBigInt64BuilderInitial<''>;

export function bigint<TName extends string, TMode extends MySqlBigIntConfig['mode']>(
name: TName,
config: MySqlBigIntConfig<TMode>,
): TMode extends 'number' ? MySqlBigInt53BuilderInitial<TName> : MySqlBigInt64BuilderInitial<TName>;
): TMode extends 'number' ? MySqlBigInt53BuilderInitial<TName>
: TMode extends 'string' ? MySqlBigIntStringBuilderInitial<TName>
: MySqlBigInt64BuilderInitial<TName>;

export function bigint(a?: string | MySqlBigIntConfig, b?: MySqlBigIntConfig) {
const { name, config } = getColumnNameAndConfig<MySqlBigIntConfig>(a, b);
if (config.mode === 'number') {
return new MySqlBigInt53Builder(name, config.unsigned);
}
if (config.mode === 'string') {
return new MySqlBigIntStringBuilder(name, config.unsigned);
}
return new MySqlBigInt64Builder(name, config.unsigned);
}
56 changes: 53 additions & 3 deletions drizzle-orm/src/pg-core/columns/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,47 @@ export class PgBigInt53<T extends ColumnBaseConfig<'number', 'PgBigInt53'>> exte
}
}

export type PgBigIntStringBuilderInitial<TName extends string> = PgBigIntStringBuilder<{
name: TName;
dataType: 'string';
columnType: 'PgBigIntString';
data: string;
driverParam: string;
enumValues: undefined;
}>;

export class PgBigIntStringBuilder<T extends ColumnBuilderBaseConfig<'string', 'PgBigIntString'>>
extends PgIntColumnBaseBuilder<T>
{
static override readonly [entityKind]: string = 'PgBigIntStringBuilder';

constructor(name: T['name']) {
super(name, 'string', 'PgBigIntString');
}

/** @internal */
override build<TTableName extends string>(
table: AnyPgTable<{ name: TTableName }>,
): PgBigIntString<MakeColumnConfig<T, TTableName>> {
return new PgBigIntString<MakeColumnConfig<T, TTableName>>(
table,
this.config as ColumnBuilderRuntimeConfig<any, any>,
);
}
}

export class PgBigIntString<T extends ColumnBaseConfig<'string', 'PgBigIntString'>> extends PgColumn<T> {
static override readonly [entityKind]: string = 'PgBigIntString';

getSQLType(): string {
return 'bigint';
}

override mapFromDriverValue(value: string): string {
return value;
}
}

export type PgBigInt64BuilderInitial<TName extends string> = PgBigInt64Builder<{
name: TName;
dataType: 'bigint';
Expand Down Expand Up @@ -90,21 +131,30 @@ export class PgBigInt64<T extends ColumnBaseConfig<'bigint', 'PgBigInt64'>> exte
}
}

export interface PgBigIntConfig<T extends 'number' | 'bigint' = 'number' | 'bigint'> {
export interface PgBigIntConfig<T extends 'number' | 'string' | 'bigint' = 'number' | 'string' | 'bigint'> {
mode: T;
}

export function bigint<TMode extends PgBigIntConfig['mode']>(
config: PgBigIntConfig<TMode>,
): TMode extends 'number' ? PgBigInt53BuilderInitial<''> : PgBigInt64BuilderInitial<''>;
): TMode extends 'number' ? PgBigInt53BuilderInitial<''>
: TMode extends 'string' ? PgBigIntStringBuilderInitial<''>
: PgBigInt64BuilderInitial<''>;

export function bigint<TName extends string, TMode extends PgBigIntConfig['mode']>(
name: TName,
config: PgBigIntConfig<TMode>,
): TMode extends 'number' ? PgBigInt53BuilderInitial<TName> : PgBigInt64BuilderInitial<TName>;
): TMode extends 'number' ? PgBigInt53BuilderInitial<TName>
: TMode extends 'string' ? PgBigIntStringBuilderInitial<TName>
: PgBigInt64BuilderInitial<TName>;

export function bigint(a: string | PgBigIntConfig, b?: PgBigIntConfig) {
const { name, config } = getColumnNameAndConfig<PgBigIntConfig>(a, b);
if (config.mode === 'number') {
return new PgBigInt53Builder(name);
}
if (config.mode === 'string') {
return new PgBigIntStringBuilder(name);
}
return new PgBigInt64Builder(name);
}
61 changes: 58 additions & 3 deletions drizzle-orm/src/singlestore-core/columns/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,52 @@ export class SingleStoreBigInt53<T extends ColumnBaseConfig<'number', 'SingleSto
}
}

export type SingleStoreBigIntStringBuilderInitial<TName extends string> = SingleStoreBigIntStringBuilder<{
name: TName;
dataType: 'string';
columnType: 'SingleStoreBigIntString';
data: string;
driverParam: string;
enumValues: undefined;
unsigned?: boolean;
}>;

export class SingleStoreBigIntStringBuilder<T extends ColumnBuilderBaseConfig<'string', 'SingleStoreBigIntString'>>
extends SingleStoreColumnBuilderWithAutoIncrement<T, { unsigned: boolean }>
{
static override readonly [entityKind]: string = 'SingleStoreBigIntStringBuilder';

constructor(name: T['name'], unsigned: boolean = false) {
super(name, 'string', 'SingleStoreBigIntString');
this.config.unsigned = unsigned;
}

/** @internal */
override build<TTableName extends string>(
table: AnySingleStoreTable<{ name: TTableName }>,
): SingleStoreBigIntString<MakeColumnConfig<T, TTableName>> {
return new SingleStoreBigIntString<MakeColumnConfig<T, TTableName>>(
table,
this.config as ColumnBuilderRuntimeConfig<any, any>,
);
}
}

export class SingleStoreBigIntString<T extends ColumnBaseConfig<'string', 'SingleStoreBigIntString'>>
extends SingleStoreColumnWithAutoIncrement<T, { unsigned: boolean }>
{
static override readonly [entityKind]: string = 'SingleStoreBigIntString';

getSQLType(): string {
return `bigint${this.config.unsigned ? ' unsigned' : ''}`;
}

// eslint-disable-next-line unicorn/prefer-native-coercion-functions
override mapFromDriverValue(value: string | number): string {
return String(value);
}
}

export type SingleStoreBigInt64BuilderInitial<TName extends string> = SingleStoreBigInt64Builder<{
name: TName;
dataType: 'bigint';
Expand Down Expand Up @@ -98,22 +144,31 @@ export class SingleStoreBigInt64<T extends ColumnBaseConfig<'bigint', 'SingleSto
}
}

export interface SingleStoreBigIntConfig<T extends 'number' | 'bigint' = 'number' | 'bigint'> {
export interface SingleStoreBigIntConfig<T extends 'number' | 'string' | 'bigint' = 'number' | 'string' | 'bigint'> {
mode: T;
unsigned?: boolean;
}

export function bigint<TMode extends SingleStoreBigIntConfig['mode']>(
config: SingleStoreBigIntConfig<TMode>,
): TMode extends 'number' ? SingleStoreBigInt53BuilderInitial<''> : SingleStoreBigInt64BuilderInitial<''>;
): TMode extends 'number' ? SingleStoreBigInt53BuilderInitial<''>
: TMode extends 'string' ? SingleStoreBigIntStringBuilderInitial<''>
: SingleStoreBigInt64BuilderInitial<''>;

export function bigint<TName extends string, TMode extends SingleStoreBigIntConfig['mode']>(
name: TName,
config: SingleStoreBigIntConfig<TMode>,
): TMode extends 'number' ? SingleStoreBigInt53BuilderInitial<TName> : SingleStoreBigInt64BuilderInitial<TName>;
): TMode extends 'number' ? SingleStoreBigInt53BuilderInitial<TName>
: TMode extends 'string' ? SingleStoreBigIntStringBuilderInitial<TName>
: SingleStoreBigInt64BuilderInitial<TName>;

export function bigint(a?: string | SingleStoreBigIntConfig, b?: SingleStoreBigIntConfig) {
const { name, config } = getColumnNameAndConfig<SingleStoreBigIntConfig>(a, b);
if (config.mode === 'number') {
return new SingleStoreBigInt53Builder(name, config.unsigned);
}
if (config.mode === 'string') {
return new SingleStoreBigIntStringBuilder(name, config.unsigned);
}
return new SingleStoreBigInt64Builder(name, config.unsigned);
}
12 changes: 8 additions & 4 deletions drizzle-typebox/tests/mysql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,10 @@ test('all data types', (tc) => {
}) => ({
bigint1: bigint({ mode: 'number' }).notNull(),
bigint2: bigint({ mode: 'bigint' }).notNull(),
bigint3: bigint({ unsigned: true, mode: 'number' }).notNull(),
bigint4: bigint({ unsigned: true, mode: 'bigint' }).notNull(),
bigint3: bigint({ mode: 'string' }).notNull(),
bigint4: bigint({ unsigned: true, mode: 'number' }).notNull(),
bigint5: bigint({ unsigned: true, mode: 'bigint' }).notNull(),
bigint6: bigint({ unsigned: true, mode: 'string' }).notNull(),
binary: binary({ length: 10 }).notNull(),
boolean: boolean().notNull(),
char1: char({ length: 10 }).notNull(),
Expand Down Expand Up @@ -413,8 +415,10 @@ test('all data types', (tc) => {
const expected = t.Object({
bigint1: t.Integer({ minimum: Number.MIN_SAFE_INTEGER, maximum: Number.MAX_SAFE_INTEGER }),
bigint2: t.BigInt({ minimum: CONSTANTS.INT64_MIN, maximum: CONSTANTS.INT64_MAX }),
bigint3: t.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),
bigint4: t.BigInt({ minimum: 0n, maximum: CONSTANTS.INT64_UNSIGNED_MAX }),
bigint3: t.String(),
bigint4: t.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),
bigint5: t.BigInt({ minimum: 0n, maximum: CONSTANTS.INT64_UNSIGNED_MAX }),
bigint6: t.String(),
binary: t.String(),
boolean: t.Boolean(),
char1: t.String({ minLength: 10, maxLength: 10 }),
Expand Down
2 changes: 2 additions & 0 deletions drizzle-typebox/tests/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ test('all data types', (tc) => {
}) => ({
bigint1: bigint({ mode: 'number' }).notNull(),
bigint2: bigint({ mode: 'bigint' }).notNull(),
bigint3: bigint({ mode: 'string' }).notNull(),
bigserial1: bigserial({ mode: 'number' }).notNull(),
bigserial2: bigserial({ mode: 'bigint' }).notNull(),
bit: bit({ dimensions: 5 }).notNull(),
Expand Down Expand Up @@ -455,6 +456,7 @@ test('all data types', (tc) => {
const expected = t.Object({
bigint1: t.Integer({ minimum: Number.MIN_SAFE_INTEGER, maximum: Number.MAX_SAFE_INTEGER }),
bigint2: t.BigInt({ minimum: CONSTANTS.INT64_MIN, maximum: CONSTANTS.INT64_MAX }),
bigint3: t.String(),
bigserial1: t.Integer({ minimum: Number.MIN_SAFE_INTEGER, maximum: Number.MAX_SAFE_INTEGER }),
bigserial2: t.BigInt({ minimum: CONSTANTS.INT64_MIN, maximum: CONSTANTS.INT64_MAX }),
bit: t.RegExp(/^[01]+$/, { maxLength: 5 }),
Expand Down
12 changes: 8 additions & 4 deletions drizzle-typebox/tests/singlestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,10 @@ test('all data types', (tc) => {
}) => ({
bigint1: bigint({ mode: 'number' }).notNull(),
bigint2: bigint({ mode: 'bigint' }).notNull(),
bigint3: bigint({ unsigned: true, mode: 'number' }).notNull(),
bigint4: bigint({ unsigned: true, mode: 'bigint' }).notNull(),
bigint3: bigint({ mode: 'string' }).notNull(),
bigint4: bigint({ unsigned: true, mode: 'number' }).notNull(),
bigint5: bigint({ unsigned: true, mode: 'bigint' }).notNull(),
bigint6: bigint({ unsigned: true, mode: 'string' }).notNull(),
binary: binary({ length: 10 }).notNull(),
boolean: boolean().notNull(),
char1: char({ length: 10 }).notNull(),
Expand Down Expand Up @@ -415,8 +417,10 @@ test('all data types', (tc) => {
const expected = t.Object({
bigint1: t.Integer({ minimum: Number.MIN_SAFE_INTEGER, maximum: Number.MAX_SAFE_INTEGER }),
bigint2: t.BigInt({ minimum: CONSTANTS.INT64_MIN, maximum: CONSTANTS.INT64_MAX }),
bigint3: t.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),
bigint4: t.BigInt({ minimum: 0n, maximum: CONSTANTS.INT64_UNSIGNED_MAX }),
bigint3: t.String(),
bigint4: t.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }),
bigint5: t.BigInt({ minimum: 0n, maximum: CONSTANTS.INT64_UNSIGNED_MAX }),
bigint6: t.String(),
binary: t.String(),
boolean: t.Boolean(),
char1: t.String({ minLength: 10, maxLength: 10 }),
Expand Down
Loading