Skip to content

Commit

Permalink
update singlestore-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguespn committed Nov 13, 2024
1 parent 9e591e6 commit c9f780c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
13 changes: 9 additions & 4 deletions drizzle-orm/src/singlestore-proxy/driver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { entityKind } from '~/entity.ts';
import { DefaultLogger } from '~/logger.ts';
import {
createTableRelationsHelpers,
Expand All @@ -14,9 +15,11 @@ import {
SingleStoreRemoteSession,
} from './session.ts';

export type SingleStoreRemoteDatabase<
export class SingleStoreRemoteDatabase<
TSchema extends Record<string, unknown> = Record<string, never>,
> = SingleStoreDatabase<SingleStoreRemoteQueryResultHKT, SingleStoreRemotePreparedQueryHKT, TSchema>;
> extends SingleStoreDatabase<SingleStoreRemoteQueryResultHKT, SingleStoreRemotePreparedQueryHKT, TSchema> {
static override readonly [entityKind]: string = 'SingleStoreRemoteDatabase';
}

export type RemoteCallback = (
sql: string,
Expand All @@ -28,7 +31,7 @@ export function drizzle<TSchema extends Record<string, unknown> = Record<string,
callback: RemoteCallback,
config: DrizzleConfig<TSchema> = {},
): SingleStoreRemoteDatabase<TSchema> {
const dialect = new SingleStoreDialect();
const dialect = new SingleStoreDialect({ casing: config.casing });
let logger;
if (config.logger === true) {
logger = new DefaultLogger();
Expand All @@ -50,5 +53,7 @@ export function drizzle<TSchema extends Record<string, unknown> = Record<string,
}

const session = new SingleStoreRemoteSession(callback, dialect, schema, { logger });
return new SingleStoreDatabase(dialect, session, schema) as SingleStoreRemoteDatabase<TSchema>;
return new SingleStoreRemoteDatabase(dialect, session, schema as any, 'default') as SingleStoreRemoteDatabase<
TSchema
>;
}
2 changes: 1 addition & 1 deletion drizzle-orm/src/singlestore-proxy/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import type {
SingleStoreTransactionConfig,
} from '~/singlestore-core/session.ts';
import { SingleStorePreparedQuery as PreparedQueryBase, SingleStoreSession } from '~/singlestore-core/session.ts';
import { fillPlaceholders } from '~/sql/sql.ts';
import type { Query, SQL } from '~/sql/sql.ts';
import { fillPlaceholders } from '~/sql/sql.ts';
import { type Assume, mapResultRow } from '~/utils.ts';
import type { RemoteCallback } from './driver.ts';

Expand Down
12 changes: 8 additions & 4 deletions drizzle-orm/src/singlestore/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import type { Connection, Pool } from 'mysql2/promise';
import { entityKind } from '~/entity.ts';
import type { Logger } from '~/logger.ts';
import { DefaultLogger } from '~/logger.ts';
import { SingleStoreDatabase } from '~/singlestore-core/db.ts';
import { SingleStoreDialect } from '~/singlestore-core/dialect.ts';
import type { Mode } from '~/singlestore-core/session.ts';
import {
createTableRelationsHelpers,
extractTablesRelationalConfig,
type RelationalSchemaConfig,
type TablesRelationalConfig,
} from '~/relations.ts';
import { SingleStoreDatabase } from '~/singlestore-core/db.ts';
import { SingleStoreDialect } from '~/singlestore-core/dialect.ts';
import type { Mode } from '~/singlestore-core/session.ts';
import { type DrizzleConfig, type IfNotImported, type ImportTypeError, isConfig } from '~/utils.ts';
import { DrizzleError } from '../errors.ts';
import type { SingleStoreDriverClient, SingleStoreDriverPreparedQueryHKT, SingleStoreDriverQueryResultHKT } from './session.ts';
import type {
SingleStoreDriverClient,
SingleStoreDriverPreparedQueryHKT,
SingleStoreDriverQueryResultHKT,
} from './session.ts';
import { SingleStoreDriverSession } from './session.ts';

export interface SingleStoreDriverOptions {
Expand Down
15 changes: 12 additions & 3 deletions drizzle-orm/src/singlestore/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export type SingleStoreQueryResult<
T = any,
> = [T extends ResultSetHeader ? T : T[], FieldPacket[]];

export class SingleStoreDriverPreparedQuery<T extends SingleStorePreparedQueryConfig> extends SingleStorePreparedQuery<T> {
export class SingleStoreDriverPreparedQuery<T extends SingleStorePreparedQueryConfig>
extends SingleStorePreparedQuery<T>
{
static override readonly [entityKind]: string = 'SingleStoreDriverPreparedQuery';

private rawQuery: QueryOptions;
Expand Down Expand Up @@ -300,10 +302,17 @@ export class SingleStoreDriverSession<
export class SingleStoreDriverTransaction<
TFullSchema extends Record<string, unknown>,
TSchema extends TablesRelationalConfig,
> extends SingleStoreTransaction<SingleStoreDriverQueryResultHKT, SingleStoreDriverPreparedQueryHKT, TFullSchema, TSchema> {
> extends SingleStoreTransaction<
SingleStoreDriverQueryResultHKT,
SingleStoreDriverPreparedQueryHKT,
TFullSchema,
TSchema
> {
static override readonly [entityKind]: string = 'SingleStoreDriverTransaction';

override async transaction<T>(transaction: (tx: SingleStoreDriverTransaction<TFullSchema, TSchema>) => Promise<T>): Promise<T> {
override async transaction<T>(
transaction: (tx: SingleStoreDriverTransaction<TFullSchema, TSchema>) => Promise<T>,
): Promise<T> {
const savepointName = `sp${this.nestedIndex + 1}`;
const tx = new SingleStoreDriverTransaction<TFullSchema, TSchema>(
this.dialect,
Expand Down

0 comments on commit c9f780c

Please sign in to comment.