diff --git a/drizzle-orm/src/singlestore-core/columns/bson.ts b/drizzle-orm/src/singlestore-core/columns/bson.ts deleted file mode 100644 index 1f2077895..000000000 --- a/drizzle-orm/src/singlestore-core/columns/bson.ts +++ /dev/null @@ -1,53 +0,0 @@ -import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts'; -import type { ColumnBaseConfig } from '~/column.ts'; -import { entityKind } from '~/entity.ts'; -import type { AnySingleStoreTable } from '~/singlestore-core/table.ts'; -import { sql } from '~/sql/sql.ts'; -import { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts'; - -export type SingleStoreBsonBuilderInitial = SingleStoreBsonBuilder<{ - name: TName; - dataType: 'json'; // The bson is stored as a json string the same way binary is stored as a string (check `./binary.ts`) - columnType: 'SingleStoreBson'; - data: unknown; - driverParam: string; - enumValues: undefined; - generated: undefined; -}>; - -export class SingleStoreBsonBuilder> - extends SingleStoreColumnBuilder -{ - static readonly [entityKind]: string = 'SingleStoreBsonBuilder'; - - constructor(name: T['name']) { - super(name, 'json', 'SingleStoreBson'); - } - - /** @internal */ - override build( - table: AnySingleStoreTable<{ name: TTableName }>, - ): SingleStoreBson> { - return new SingleStoreBson>( - table, - this.config as ColumnBuilderRuntimeConfig, - ); - } -} - -export class SingleStoreBson> extends SingleStoreColumn { - static readonly [entityKind]: string = 'SingleStoreBson'; - - getSQLType(): string { - return 'bson'; - } - - override mapToDriverValue(value: T['data']) { - const json = JSON.stringify(value); - return sql`${json}:>BSON`; - } -} - -export function bson(name: TName): SingleStoreBsonBuilderInitial { - return new SingleStoreBsonBuilder(name); -} diff --git a/drizzle-orm/src/singlestore-core/columns/geography.ts b/drizzle-orm/src/singlestore-core/columns/geography.ts deleted file mode 100644 index b7798b4a4..000000000 --- a/drizzle-orm/src/singlestore-core/columns/geography.ts +++ /dev/null @@ -1,147 +0,0 @@ -import type { ColumnBaseConfig } from '~/column'; -import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder'; -import { entityKind } from '~/entity.ts'; -import { DrizzleError } from '~/errors.ts'; -import type { AnySingleStoreTable } from '~/singlestore-core/table'; -import type { SQL } from '~/sql/sql.ts'; -import { sql } from '~/sql/sql.ts'; -import { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts'; - -export type LngLat = [lng: number, lat: number]; - -type GeographyPoint = LngLat; -type GeographyLineString = Array; -type GeographyPolygon = Array>; - -export type SingleStoreGeographyBuilderInitial = SingleStoreGeographyBuilder<{ - name: TName; - dataType: 'array'; - columnType: 'SingleStoreGeography'; - data: GeographyPoint | GeographyLineString | GeographyPolygon; - driverParam: string; - enumValues: undefined; - generated: undefined; -}>; - -export class SingleStoreGeographyBuilder> - extends SingleStoreColumnBuilder -{ - static readonly [entityKind]: string = 'SingleStoreGeographyBuilder'; - - constructor(name: T['name']) { - super(name, 'array', 'SingleStoreGeography'); - } - - /** @internal */ - override build( - table: AnySingleStoreTable<{ name: TTableName }>, - ): SingleStoreGeography> { - return new SingleStoreGeography(table, this.config as ColumnBuilderRuntimeConfig); - } -} - -export class SingleStoreGeography> - extends SingleStoreColumn -{ - static readonly [entityKind]: string = 'SingleStoreGeography'; - - constructor( - table: AnySingleStoreTable<{ name: T['tableName'] }>, - config: SingleStoreGeographyBuilder['config'], - ) { - super(table, config); - } - - getSQLType(): string { - return 'text'; - // TODO `geography` is only supported on rowstore tables. Geography data - // on columnstore should be stored as `text` - // return 'geography'; - } - - override mapToDriverValue(value: GeographyPoint | GeographyLineString | GeographyPolygon) { - if (_isPoint(value)) { - return sql`"POINT(${_toPointSQL(value)})"`; - } else if (_isLineString(value)) { - return sql`"LINESTRING(${_toLineStringSQL(value)})"`; - } else if (_isPolygon(value)) { - return sql`"POLYGON(${_toPolygonSQL(value)})"`; - } else { - throw new DrizzleError({ message: 'value is not Array' }); - } - } - - override mapFromDriverValue(value: string): GeographyPoint | GeographyLineString | GeographyPolygon { - const firstParenIndex = value.indexOf('('); - const __type = value.slice(0, firstParenIndex); - const inner = value.slice(firstParenIndex + 1, -1); - switch (__type) { - case 'POINT': { - return _pointToGeographyPoint(inner); - } - case 'LINESTRING': { - return _linestringToGeographyLineString(inner); - } - case 'POLYGON': { - return _polygonToGeographyPolygon(inner); - } - default: { - throw new DrizzleError({ message: 'Unexpected Geography type' }); - } - } - } -} - -export function geography(name: TName): SingleStoreGeographyBuilderInitial { - return new SingleStoreGeographyBuilder(name); -} - -function _toPointSQL([lng, lat]: GeographyPoint): SQL { - return sql`${lng} ${lat}`; -} - -function _toLineStringSQL(linestring: GeographyLineString): SQL { - const points = linestring.map((point) => _toPointSQL(point)); - return sql.join(points, sql.raw(', ')); -} - -function _toPolygonSQL(polygon: GeographyPolygon): SQL { - const rings = polygon.map((linestring) => sql`(${_toLineStringSQL(linestring)})`); - return sql.join(rings, sql.raw(', ')); -} - -function _pointToGeographyPoint(value: string): GeographyPoint { - return value.split(' ').map(Number) as GeographyPoint; -} - -function _linestringToGeographyLineString(value: string): GeographyLineString { - const pairs = value.split(', '); - return pairs.map((pair) => _pointToGeographyPoint(pair)); -} - -function _polygonToGeographyPolygon(value: string): GeographyPolygon { - const rings = value.slice(1, -1).split('), ('); - return rings.map((ring) => _linestringToGeographyLineString(ring)); -} - -function _isPoint(value: GeographyPoint | GeographyLineString | GeographyPolygon): value is GeographyPoint { - return value.length === 2 && typeof value[0] === 'number'; -} - -function _isLineString(value: GeographyPoint | GeographyLineString | GeographyPolygon): value is GeographyLineString { - try { - const test = value as GeographyLineString; - return typeof test[0]![0] === 'number'; - } catch { - return false; - } -} - -function _isPolygon(value: GeographyPoint | GeographyLineString | GeographyPolygon): value is GeographyPolygon { - try { - const test = value as GeographyPolygon; - return typeof test[0]![0]![0] === 'number'; - } catch { - return false; - } -} diff --git a/drizzle-orm/src/singlestore-core/columns/geographypoint.ts b/drizzle-orm/src/singlestore-core/columns/geographypoint.ts deleted file mode 100644 index 3c027ebe5..000000000 --- a/drizzle-orm/src/singlestore-core/columns/geographypoint.ts +++ /dev/null @@ -1,64 +0,0 @@ -import type { ColumnBaseConfig } from '~/column'; -import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder'; -import { entityKind } from '~/entity.ts'; -import type { AnySingleStoreTable } from '~/singlestore-core/table.ts'; -import { sql } from '~/sql/sql.ts'; -import { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts'; -import type { LngLat } from './geography'; - -export type SingleStoreGeographyPointBuilderInitial = SingleStoreGeographyPointBuilder<{ - name: TName; - dataType: 'array'; - columnType: 'SingleStoreGeographyPoint'; - data: LngLat; - driverParam: string; - enumValues: undefined; - generated: undefined; -}>; - -export class SingleStoreGeographyPointBuilder> - extends SingleStoreColumnBuilder -{ - static readonly [entityKind]: string = 'SingleStoreGeographyPointBuilder'; - - constructor(name: T['name']) { - super(name, 'array', 'SingleStoreGeographyPoint'); - } - - /** @internal */ - override build( - table: AnySingleStoreTable<{ name: TTableName }>, - ): SingleStoreGeographyPoint> { - return new SingleStoreGeographyPoint(table, this.config as ColumnBuilderRuntimeConfig); - } -} - -export class SingleStoreGeographyPoint> - extends SingleStoreColumn -{ - static readonly [entityKind]: string = 'SingleStoreGeographyPoint'; - - constructor( - table: AnySingleStoreTable<{ name: T['tableName'] }>, - config: SingleStoreGeographyPointBuilder['config'], - ) { - super(table, config); - } - - getSQLType(): string { - return 'geographypoint'; - } - - override mapToDriverValue([lon, lat]: LngLat) { - return sql`"POINT(${lon} ${lat})"`; - } - - override mapFromDriverValue(value: string): LngLat { - const numbers = value.slice(value.indexOf('(') + 1, -1); - return numbers.split(' ').map(Number) as LngLat; // driver value will look like `POINT(lon lat)` - } -} - -export function geographypoint(name: TName): SingleStoreGeographyPointBuilderInitial { - return new SingleStoreGeographyPointBuilder(name); -} diff --git a/drizzle-orm/src/singlestore-core/columns/guid.ts b/drizzle-orm/src/singlestore-core/columns/guid.ts deleted file mode 100644 index 39d939fea..000000000 --- a/drizzle-orm/src/singlestore-core/columns/guid.ts +++ /dev/null @@ -1,121 +0,0 @@ -import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder'; -import type { ColumnBaseConfig } from '~/column.ts'; -import { entityKind } from '~/entity.ts'; -import type { AnySingleStoreTable } from '~/singlestore-core/table.ts'; -import { sql } from '~/sql/sql.ts'; -import type { Equal } from '~/utils'; -import { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts'; - -export type SingleStoreGUIDBuilderInitial = SingleStoreGUIDBuilder<{ - name: TName; - dataType: 'buffer'; - columnType: 'SingleStoreGUID'; - data: Uint8Array; - driverParam: string; - enumValues: undefined; - generated: undefined; -}>; - -export class SingleStoreGUIDBuilder> - extends SingleStoreColumnBuilder -{ - static readonly [entityKind]: string = 'SingleStoreGUIDBuilder'; - - constructor(name: T['name'], _config?: SingleStoreGUIDConfig) { - super(name, 'buffer', 'SingleStoreGUID'); - } - - /** @internal */ - override build( - table: AnySingleStoreTable<{ name: TTableName }>, - ): SingleStoreGUID> { - return new SingleStoreGUID(table, this.config as ColumnBuilderRuntimeConfig); - } -} - -export class SingleStoreGUID> extends SingleStoreColumn { - static readonly [entityKind]: string = 'SingleStoreGUID'; - - constructor(table: AnySingleStoreTable<{ name: T['tableName'] }>, config: SingleStoreGUIDBuilder['config']) { - super(table, config); - } - - getSQLType(): string { - return 'binary(16)'; - } - - override mapToDriverValue(value: string) { - return sql`UNHEX(REPLACE(${value}, "-", ""))`; - } -} - -export type SingleStoreGUIDStringBuilderInitial = SingleStoreGUIDStringBuilder<{ - name: TName; - dataType: 'string'; - columnType: 'SingleStoreGUIDString'; - data: string; - driverParam: string; - enumValues: undefined; - generated: undefined; -}>; - -export class SingleStoreGUIDStringBuilder> - extends SingleStoreColumnBuilder -{ - static readonly [entityKind]: string = 'SingleStoreGUIDStringBuilder'; - - constructor(name: T['name'], _config?: SingleStoreGUIDConfig) { - super(name, 'string', 'SingleStoreGUIDString'); - } - - /** @internal */ - override build( - table: AnySingleStoreTable<{ name: TTableName }>, - ): SingleStoreGUIDString> { - return new SingleStoreGUIDString(table, this.config as ColumnBuilderRuntimeConfig); - } -} - -export class SingleStoreGUIDString> - extends SingleStoreColumn -{ - static readonly [entityKind]: string = 'SingleStoreGUIDString'; - - constructor(table: AnySingleStoreTable<{ name: T['tableName'] }>, config: SingleStoreGUIDStringBuilder['config']) { - super(table, config); - } - - getSQLType(): string { - return 'binary(16)'; - } - - override mapToDriverValue(value: string) { - return sql`UNHEX(REPLACE(${value}, "-", ""))`; - } - - override mapFromDriverValue(value: Uint8Array): string { - const hex = Buffer.from(value).toString('hex'); - return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`; - } -} - -export interface SingleStoreGUIDConfig { - mode?: TMode; -} - -/** - * Creates a column with the data type `BINARY(16)` - * - * Use config `{ mode: "string" }` for a string representation of the GUID - */ -export function guid( - name: TName, - config?: SingleStoreGUIDConfig, -): Equal extends true ? SingleStoreGUIDStringBuilderInitial - : SingleStoreGUIDBuilderInitial; -export function guid(name: string, config?: SingleStoreGUIDConfig) { - if (config?.mode === 'string') { - return new SingleStoreGUIDStringBuilder(name, config); - } - return new SingleStoreGUIDBuilder(name, config); -} diff --git a/drizzle-orm/src/singlestore-core/columns/index.ts b/drizzle-orm/src/singlestore-core/columns/index.ts index 18d27e0fb..b51f0fac4 100644 --- a/drizzle-orm/src/singlestore-core/columns/index.ts +++ b/drizzle-orm/src/singlestore-core/columns/index.ts @@ -1,7 +1,6 @@ export * from './bigint.ts'; export * from './binary.ts'; export * from './boolean.ts'; -export * from './bson.ts'; export * from './char.ts'; export * from './common.ts'; export * from './custom.ts'; @@ -11,9 +10,6 @@ export * from './decimal.ts'; export * from './double.ts'; export * from './enum.ts'; export * from './float.ts'; -export * from './geography.ts'; -export * from './geographypoint.ts'; -export * from './guid.ts'; export * from './int.ts'; export * from './json.ts'; export * from './mediumint.ts'; @@ -24,7 +20,6 @@ export * from './text.ts'; export * from './time.ts'; export * from './timestamp.ts'; export * from './tinyint.ts'; -export * from './uuid.ts'; export * from './varbinary.ts'; export * from './varchar.ts'; export * from './year.ts'; diff --git a/drizzle-orm/src/singlestore-core/columns/uuid.ts b/drizzle-orm/src/singlestore-core/columns/uuid.ts deleted file mode 100644 index aec204e12..000000000 --- a/drizzle-orm/src/singlestore-core/columns/uuid.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { ColumnBaseConfig } from '~/column'; -import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder'; -import { entityKind } from '~/entity.ts'; -import type { AnySingleStoreTable } from '~/singlestore-core/table.ts'; -import { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts'; - -export type SingleStoreUUIDBuilderInitial = SingleStoreUUIDBuilder<{ - name: TName; - dataType: 'string'; - columnType: 'SingleStoreUUID'; - data: string; - driverParam: string; - enumValues: undefined; - generated: undefined; -}>; - -export class SingleStoreUUIDBuilder> - extends SingleStoreColumnBuilder -{ - static readonly [entityKind]: string = 'SingleStoreUUIDBuilder'; - - constructor(name: T['name']) { - super(name, 'string', 'SingleStoreUUID'); - } - - /** @internal */ - override build( - table: AnySingleStoreTable<{ name: TTableName }>, - ): SingleStoreUUID> { - return new SingleStoreUUID(table, this.config as ColumnBuilderRuntimeConfig); - } -} - -export class SingleStoreUUID> extends SingleStoreColumn { - static readonly [entityKind]: string = 'SingleStoreUUID'; - - constructor(table: AnySingleStoreTable<{ name: T['tableName'] }>, config: SingleStoreUUIDBuilder['config']) { - super(table, config); - } - - getSQLType(): string { - return 'varchar(36)'; - } -} - -export function uuid(name: TName): SingleStoreUUIDBuilderInitial { - return new SingleStoreUUIDBuilder(name); -} diff --git a/drizzle-orm/src/singlestore-core/columns/vector.ts b/drizzle-orm/src/singlestore-core/columns/vector.ts deleted file mode 100644 index cae2b2205..000000000 --- a/drizzle-orm/src/singlestore-core/columns/vector.ts +++ /dev/null @@ -1,74 +0,0 @@ -import type { ColumnBaseConfig } from '~/column'; -import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder'; -import { entityKind } from '~/entity.ts'; -import type { AnySingleStoreTable } from '~/singlestore-core/table.ts'; -import { SingleStoreColumn, SingleStoreColumnBuilder } from './common.ts'; - -export type SingleStoreVectorBuilderInitial = SingleStoreVectorBuilder<{ - name: TName; - dataType: 'array'; - columnType: 'SingleStoreVector'; - data: Array; - driverParam: Array; - enumValues: undefined; - generated: undefined; -}>; - -export class SingleStoreVectorBuilder> - extends SingleStoreColumnBuilder -{ - static readonly [entityKind]: string = 'SingleStoreVectorBuilder'; - - constructor(name: T['name'], config: SingleStoreVectorConfig) { - super(name, 'array', 'SingleStoreVector'); - this.config.dimensions = config.dimensions; - this.config.elementType = config.elementType; - } - - /** @internal */ - override build( - table: AnySingleStoreTable<{ name: TTableName }>, - ): SingleStoreVector> { - return new SingleStoreVector(table, this.config as ColumnBuilderRuntimeConfig); - } -} - -export class SingleStoreVector> extends SingleStoreColumn { - static readonly [entityKind]: string = 'SingleStoreVector'; - - readonly dimensions: number; - readonly elementType: ElementType | undefined; - - constructor(table: AnySingleStoreTable<{ name: T['tableName'] }>, config: SingleStoreVectorBuilder['config']) { - super(table, config); - this.dimensions = config.dimensions; - this.elementType = config.elementType; - } - - getSQLType(): string { - const et = this.elementType === undefined ? '' : `, ${this.elementType}`; - return `vector(${this.dimensions}${et})`; - } - - override mapToDriverValue(value: Array) { - return JSON.stringify(value); - } - - override mapFromDriverValue(value: string): Array { - return JSON.parse(value); - } -} - -type ElementType = 'I8' | 'I16' | 'I32' | 'I64' | 'F32' | 'F64'; - -export interface SingleStoreVectorConfig { - dimensions: number; - elementType?: ElementType; -} - -export function vector( - name: TName, - config: SingleStoreVectorConfig, -): SingleStoreVectorBuilderInitial { - return new SingleStoreVectorBuilder(name, config); -} diff --git a/drizzle-orm/src/singlestore-core/expressions.ts b/drizzle-orm/src/singlestore-core/expressions.ts index 5f70c5c5a..6d4284d18 100644 --- a/drizzle-orm/src/singlestore-core/expressions.ts +++ b/drizzle-orm/src/singlestore-core/expressions.ts @@ -23,13 +23,3 @@ export function substring( chunks.push(sql`)`); return sql.join(chunks); } - -// Vectors - -export function dotProduct(column: SingleStoreColumn | SQL.Aliased, value: Array) { - return sql`${column} <*> ${JSON.stringify(value)}`; -} - -export function euclideanDistance(column: SingleStoreColumn | SQL.Aliased, value: Array) { - return sql`${column} <-> ${JSON.stringify(value)}`; -}