Skip to content

Commit

Permalink
remove mode from drizzle-orm
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguespn committed Nov 14, 2024
1 parent 0d204bf commit 2816180
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 38 deletions.
3 changes: 0 additions & 3 deletions drizzle-orm/src/singlestore-core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { RelationalQueryBuilder } from './query-builders/query.ts';
import type { SelectedFields } from './query-builders/select.types.ts';
import type {
Mode,
PreparedQueryHKTBase,
SingleStoreQueryResultHKT,
SingleStoreQueryResultKind,
Expand Down Expand Up @@ -55,7 +54,6 @@ export class SingleStoreDatabase<
/** @internal */
readonly session: SingleStoreSession<any, any, any, any>,
schema: RelationalSchemaConfig<TSchema> | undefined,
protected readonly mode: Mode,
) {
this._ = schema
? {
Expand All @@ -80,7 +78,6 @@ export class SingleStoreDatabase<
columns,
dialect,
session,
this.mode,
);
}
}
Expand Down
5 changes: 0 additions & 5 deletions drizzle-orm/src/singlestore-core/query-builders/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { Query, QueryWithTypings, SQL } from '~/sql/sql.ts';
import type { KnownKeysOnly } from '~/utils.ts';
import type { SingleStoreDialect } from '../dialect.ts';
import type {
Mode,
PreparedQueryHKTBase,
PreparedQueryKind,
SingleStorePreparedQueryConfig,
Expand All @@ -35,7 +34,6 @@ export class RelationalQueryBuilder<
private tableConfig: TableRelationalConfig,
private dialect: SingleStoreDialect,
private session: SingleStoreSession,
private mode: Mode,
) {}

findMany<TConfig extends DBQueryConfig<'many', true, TSchema, TFields>>(
Expand All @@ -51,7 +49,6 @@ export class RelationalQueryBuilder<
this.session,
config ? (config as DBQueryConfig<'many', true>) : {},
'many',
this.mode,
);
}

Expand All @@ -68,7 +65,6 @@ export class RelationalQueryBuilder<
this.session,
config ? { ...(config as DBQueryConfig<'many', true> | undefined), limit: 1 } : { limit: 1 },
'first',
this.mode,
);
}
}
Expand All @@ -91,7 +87,6 @@ export class SingleStoreRelationalQuery<
private session: SingleStoreSession,
private config: DBQueryConfig<'many', true> | true,
private queryMode: 'many' | 'first',
private mode?: Mode,
) {
super();
}
Expand Down
5 changes: 1 addition & 4 deletions drizzle-orm/src/singlestore-core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { SingleStoreDatabase } from './db.ts';
import type { SingleStoreDialect } from './dialect.ts';
import type { SelectedFieldsOrdered } from './query-builders/select.types.ts';

export type Mode = 'default';

export interface SingleStoreQueryResultHKT {
readonly $brand: 'SingleStoreQueryResultHKT';
readonly row: unknown;
Expand Down Expand Up @@ -140,9 +138,8 @@ export abstract class SingleStoreTransaction<
session: SingleStoreSession,
protected schema: RelationalSchemaConfig<TSchema> | undefined,
protected readonly nestedIndex: number,
mode: Mode,
) {
super(dialect, session, schema, mode);
super(dialect, session, schema);
}

rollback(): never {
Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/src/singlestore-proxy/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function drizzle<TSchema extends Record<string, unknown> = Record<string,
}

const session = new SingleStoreRemoteSession(callback, dialect, schema, { logger });
return new SingleStoreRemoteDatabase(dialect, session, schema as any, 'default') as SingleStoreRemoteDatabase<
return new SingleStoreRemoteDatabase(dialect, session, schema as any) as SingleStoreRemoteDatabase<
TSchema
>;
}
20 changes: 4 additions & 16 deletions drizzle-orm/src/singlestore/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import {
} 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,
Expand All @@ -37,9 +35,8 @@ export class SingleStoreDriverDriver {

createSession(
schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined,
mode: Mode,
): SingleStoreDriverSession<Record<string, unknown>, TablesRelationalConfig> {
return new SingleStoreDriverSession(this.client, this.dialect, schema, { logger: this.options.logger, mode });
return new SingleStoreDriverSession(this.client, this.dialect, schema, { logger: this.options.logger });
}
}

Expand All @@ -53,7 +50,7 @@ export class SingleStoreDriverDatabase<

export type SingleStoreDriverDrizzleConfig<TSchema extends Record<string, unknown> = Record<string, never>> =
& Omit<DrizzleConfig<TSchema>, 'schema'>
& ({ schema: TSchema; mode: Mode } | { schema?: undefined; mode?: Mode });
& ({ schema: TSchema } | { schema?: undefined });

function construct<
TSchema extends Record<string, unknown> = Record<string, never>,
Expand All @@ -76,13 +73,6 @@ function construct<

let schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;
if (config.schema) {
if (config.mode === undefined) {
throw new DrizzleError({
message:
'You need to specify "mode": "planetscale" or "default" when providing a schema. Read more: https://orm.drizzle.team/docs/rqb#modes',
});
}

const tablesConfig = extractTablesRelationalConfig(
config.schema,
createTableRelationsHelpers,
Expand All @@ -94,11 +84,9 @@ function construct<
};
}

const mode = config.mode ?? 'default';

const driver = new SingleStoreDriverDriver(clientForInstance as SingleStoreDriverClient, dialect, { logger });
const session = driver.createSession(schema, mode);
const db = new SingleStoreDriverDatabase(dialect, session, schema as any, mode) as SingleStoreDriverDatabase<TSchema>;
const session = driver.createSession(schema);
const db = new SingleStoreDriverDatabase(dialect, session, schema as any) as SingleStoreDriverDatabase<TSchema>;
(<any> db).$client = client;

return db as any;
Expand Down
6 changes: 0 additions & 6 deletions drizzle-orm/src/singlestore/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations
import type { SingleStoreDialect } from '~/singlestore-core/dialect.ts';
import type { SelectedFieldsOrdered } from '~/singlestore-core/query-builders/select.types.ts';
import {
type Mode,
type PreparedQueryKind,
SingleStorePreparedQuery,
type SingleStorePreparedQueryConfig,
Expand Down Expand Up @@ -185,7 +184,6 @@ export class SingleStoreDriverPreparedQuery<T extends SingleStorePreparedQueryCo

export interface SingleStoreDriverSessionOptions {
logger?: Logger;
mode: Mode;
}

export class SingleStoreDriverSession<
Expand All @@ -195,7 +193,6 @@ export class SingleStoreDriverSession<
static override readonly [entityKind]: string = 'SingleStoreDriverSession';

private logger: Logger;
private mode: Mode;

constructor(
private client: SingleStoreDriverClient,
Expand All @@ -205,7 +202,6 @@ export class SingleStoreDriverSession<
) {
super(dialect);
this.logger = options.logger ?? new NoopLogger();
this.mode = options.mode;
}

prepareQuery<T extends SingleStorePreparedQueryConfig>(
Expand Down Expand Up @@ -272,7 +268,6 @@ export class SingleStoreDriverSession<
session as SingleStoreSession<any, any, any, any>,
this.schema,
0,
this.mode,
);
if (config) {
const setTransactionConfigSql = this.getSetTransactionSQL(config);
Expand Down Expand Up @@ -319,7 +314,6 @@ export class SingleStoreDriverTransaction<
this.session,
this.schema,
this.nestedIndex + 1,
this.mode,
);
await tx.execute(sql.raw(`savepoint ${savepointName}`));
try {
Expand Down
5 changes: 2 additions & 3 deletions drizzle-orm/type-tests/singlestore/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export const db = drizzle(pool);

{
drizzle(pool);
// @ts-expect-error - missing mode
drizzle(pool, { schema: {} });
drizzle(pool, { schema: {}, mode: 'default' });
drizzle(pool, { mode: 'default' });
drizzle(pool, { schema: {} });
drizzle(pool, {});
}

0 comments on commit 2816180

Please sign in to comment.