Skip to content
Merged
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
61 changes: 18 additions & 43 deletions drizzle-orm/src/googlesql/columns/all.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,32 @@
import { bigint } from './bigint.ts';
import { binary } from './binary.ts';
// import { bigint } from './bigint.ts';
import { bytes } from './bytes.ts';
import { boolean } from './boolean.ts';
import { char } from './char.ts';
import { customType } from './custom.ts';
import { string } from './string.ts';
// import { customType } from './custom.ts';
import { date } from './date.ts';
import { datetime } from './datetime.ts';
import { decimal } from './decimal.ts';
import { double } from './double.ts';
import { googlesqlEnum } from './enum.ts';
import { float } from './float.ts';
import { int } from './int.ts';
import { numeric } from './numeric.ts';
import { float32 } from './float32.ts';
import { int64 } from './int64.ts';
import { json } from './json.ts';
import { mediumint } from './mediumint.ts';
import { real } from './real.ts';
import { serial } from './serial.ts';
import { smallint } from './smallint.ts';
import { longtext, mediumtext, text, tinytext } from './text.ts';
import { time } from './time.ts';
import { timestamp } from './timestamp.ts';
import { tinyint } from './tinyint.ts';
import { varbinary } from './varbinary.ts';
import { varchar } from './varchar.ts';
import { year } from './year.ts';
import { float64 } from './float64.ts';

export function getGoogleSqlColumnBuilders() {
return {
bigint,
binary,
bytes,
boolean,
char,
customType,
string,
date,
datetime,
decimal,
double,
googlesqlEnum,
float,
int,
numeric,
float32,
float64,
int64,
json,
mediumint,
real,
serial,
smallint,
text,
time,
timestamp,
tinyint,
varbinary,
varchar,
year,
longtext,
mediumtext,
tinytext,
// TODO: suppport for more types:
// array,
// proto,
// customType,
};
}

Expand Down
118 changes: 0 additions & 118 deletions drizzle-orm/src/googlesql/columns/bigint.ts

This file was deleted.

69 changes: 0 additions & 69 deletions drizzle-orm/src/googlesql/columns/binary.ts

This file was deleted.

2 changes: 2 additions & 0 deletions drizzle-orm/src/googlesql/columns/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export class GoogleSqlBoolean<T extends ColumnBaseConfig<'boolean', 'GoogleSqlBo
if (typeof value === 'boolean') {
return value;
}

// TODO: SPANNER - check how values are returned from the driver
return value === 1;
}
}
Expand Down
69 changes: 69 additions & 0 deletions drizzle-orm/src/googlesql/columns/bytes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';
import type { ColumnBaseConfig } from '~/column.ts';
import { entityKind } from '~/entity.ts';
import type { AnyGoogleSqlTable } from '~/googlesql/table.ts';
import { getColumnNameAndConfig } from '~/utils.ts';
import { GoogleSqlColumn, GoogleSqlColumnBuilder } from './common.ts';

export type GoogleSqlBytesBuilderInitial<TName extends string> = GoogleSqlBytesBuilder<{
name: TName;
dataType: 'buffer';
columnType: 'GoogleSqlBytes';
data: Buffer;
driverParam: Buffer;
enumValues: undefined;
}>;

export class GoogleSqlBytesBuilder<T extends ColumnBuilderBaseConfig<'buffer', 'GoogleSqlBytes'>>
extends GoogleSqlColumnBuilder<
T,
GoogleSqlBytesConfig
>
{
static override readonly [entityKind]: string = 'GoogleSqlBytesBuilder';

constructor(name: T['name'], length: number | "MAX" | undefined) {
super(name, 'buffer', 'GoogleSqlBytes');
this.config.length = length;
}

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

export class GoogleSqlBytes<T extends ColumnBaseConfig<'buffer', 'GoogleSqlBytes'>> extends GoogleSqlColumn<
T,
GoogleSqlBytesConfig
> {
static override readonly [entityKind]: string = 'GoogleSqlBytes';

length: number | "MAX" | undefined = this.config.length;

getSQLType(): string {
return `bytes(${this.length === undefined ? "MAX" : this.length})`;
}
}

export interface GoogleSqlBytesConfig {
length?: number | "MAX";
}

export function bytes(): GoogleSqlBytesBuilderInitial<''>;
export function bytes(
config?: GoogleSqlBytesConfig,
): GoogleSqlBytesBuilderInitial<''>;
export function bytes<TName extends string>(
name: TName,
config?: GoogleSqlBytesConfig,
): GoogleSqlBytesBuilderInitial<TName>;
export function bytes(a?: string | GoogleSqlBytesConfig, b: GoogleSqlBytesConfig = {}) {
const { name, config } = getColumnNameAndConfig<GoogleSqlBytesConfig>(a, b);
return new GoogleSqlBytesBuilder(name, config.length);
}
Loading