Skip to content

Commit

Permalink
Merge branch 'main' into fix/branch-clean-up-for-pr-integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguespn authored Oct 1, 2024
2 parents 4447f14 + d0fb8cd commit 0f4fdf7
Show file tree
Hide file tree
Showing 44 changed files with 74 additions and 1,169 deletions.
20 changes: 11 additions & 9 deletions drizzle-kit/src/cli/schema.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { boolean, command, number, string } from '@drizzle-team/brocli';
import chalk from 'chalk';
import 'dotenv/config';
import { mkdirSync } from 'fs';
import { renderWithTask } from 'hanji';
import { dialects } from 'src/schemaValidator';
import { checkHandler } from './commands/check';
import { assertOrmCoreVersion, assertPackages, assertStudioNodeVersion, ormVersionGt } from './utils';
import '../@types/utils';
import { assertUnreachable } from '../global';
import { type Setup } from '../serializer/studio';
import { assertV1OutFolder } from '../utils';
import { certs } from '../utils/certs';
import { checkHandler } from './commands/check';
import { dropMigration } from './commands/drop';
import { upMysqlHandler } from './commands/mysqlUp';
import { upPgHandler } from './commands/pgUp';
import { upSinglestoreHandler } from './commands/singlestoreUp';
import { upSqliteHandler } from './commands/sqliteUp';
import {
prepareCheckParams,
Expand All @@ -24,9 +18,17 @@ import {
preparePushConfig,
prepareStudioConfig,
} from './commands/utils';
import { assertOrmCoreVersion, assertPackages, assertStudioNodeVersion, ormVersionGt } from './utils';
import { assertCollisions, drivers, prefixes } from './validations/common';
import { withStyle } from './validations/outputs';
import 'dotenv/config';
import { boolean, command, number, string } from '@drizzle-team/brocli';
import { mkdirSync } from 'fs';
import { renderWithTask } from 'hanji';
import { dialects } from 'src/schemaValidator';
import { assertUnreachable } from '../global';
import { drizzleForSingleStore, prepareSingleStoreSchema, type Setup } from '../serializer/studio';
import { certs } from '../utils/certs';
import { upSinglestoreHandler } from './commands/singlestoreUp';
import { grey, MigrateProgress } from './views';

const optionDialect = string('dialect')
Expand Down
6 changes: 3 additions & 3 deletions drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.34.0",
"version": "0.33.0",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
Expand Down Expand Up @@ -46,7 +46,7 @@
"@aws-sdk/client-rds-data": ">=3",
"@cloudflare/workers-types": ">=3",
"@electric-sql/pglite": ">=0.1.1",
"@libsql/client": ">=0.10.0",
"@libsql/client": "*",
"@neondatabase/serverless": ">=0.1",
"@op-engineering/op-sqlite": ">=2",
"@opentelemetry/api": "^1.4.1",
Expand Down Expand Up @@ -161,7 +161,7 @@
"@aws-sdk/client-rds-data": "^3.549.0",
"@cloudflare/workers-types": "^4.20230904.0",
"@electric-sql/pglite": "^0.1.1",
"@libsql/client": "^0.10.0",
"@libsql/client": "^0.5.6",
"@neondatabase/serverless": "^0.9.0",
"@op-engineering/op-sqlite": "^2.0.16",
"@opentelemetry/api": "^1.4.1",
Expand Down
11 changes: 4 additions & 7 deletions drizzle-orm/src/better-sqlite3/driver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Database, RunResult } from 'better-sqlite3';
import { entityKind } from '~/entity.ts';
import { DefaultLogger } from '~/logger.ts';
import {
createTableRelationsHelpers,
Expand All @@ -12,11 +11,9 @@ import { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';
import type { DrizzleConfig } from '~/utils.ts';
import { BetterSQLiteSession } from './session.ts';

export class BetterSQLite3Database<TSchema extends Record<string, unknown> = Record<string, never>>
extends BaseSQLiteDatabase<'sync', RunResult, TSchema>
{
static readonly [entityKind]: string = 'BetterSQLite3Database';
}
export type BetterSQLite3Database<
TSchema extends Record<string, unknown> = Record<string, never>,
> = BaseSQLiteDatabase<'sync', RunResult, TSchema>;

export function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(
client: Database,
Expand Down Expand Up @@ -44,5 +41,5 @@ export function drizzle<TSchema extends Record<string, unknown> = Record<string,
}

const session = new BetterSQLiteSession(client, dialect, schema, { logger });
return new BetterSQLite3Database('sync', dialect, session, schema) as BetterSQLite3Database<TSchema>;
return new BaseSQLiteDatabase('sync', dialect, session, schema) as BetterSQLite3Database<TSchema>;
}
9 changes: 3 additions & 6 deletions drizzle-orm/src/bun-sqlite/driver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="bun-types" />

import type { Database } from 'bun:sqlite';
import { entityKind } from '~/entity.ts';
import { DefaultLogger } from '~/logger.ts';
import {
createTableRelationsHelpers,
Expand All @@ -14,11 +13,9 @@ import { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';
import type { DrizzleConfig } from '~/utils.ts';
import { SQLiteBunSession } from './session.ts';

export class BunSQLiteDatabase<
export type BunSQLiteDatabase<
TSchema extends Record<string, unknown> = Record<string, never>,
> extends BaseSQLiteDatabase<'sync', void, TSchema> {
static readonly [entityKind]: string = 'BunSQLiteDatabase';
}
> = BaseSQLiteDatabase<'sync', void, TSchema>;

export function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(
client: Database,
Expand Down Expand Up @@ -46,5 +43,5 @@ export function drizzle<TSchema extends Record<string, unknown> = Record<string,
}

const session = new SQLiteBunSession(client, dialect, schema, { logger });
return new BunSQLiteDatabase('sync', dialect, session, schema) as BunSQLiteDatabase<TSchema>;
return new BaseSQLiteDatabase('sync', dialect, session, schema) as BunSQLiteDatabase<TSchema>;
}
11 changes: 4 additions & 7 deletions drizzle-orm/src/expo-sqlite/driver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { SQLiteDatabase, SQLiteRunResult } from 'expo-sqlite/next';
import { entityKind } from '~/entity.ts';
import { DefaultLogger } from '~/logger.ts';
import {
createTableRelationsHelpers,
Expand All @@ -12,11 +11,9 @@ import { SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';
import type { DrizzleConfig } from '~/utils.ts';
import { ExpoSQLiteSession } from './session.ts';

export class ExpoSQLiteDatabase<TSchema extends Record<string, unknown> = Record<string, never>>
extends BaseSQLiteDatabase<'sync', SQLiteRunResult, TSchema>
{
static readonly [entityKind]: string = 'ExpoSQLiteDatabase';
}
export type ExpoSQLiteDatabase<
TSchema extends Record<string, unknown> = Record<string, never>,
> = BaseSQLiteDatabase<'sync', SQLiteRunResult, TSchema>;

export function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(
client: SQLiteDatabase,
Expand Down Expand Up @@ -44,5 +41,5 @@ export function drizzle<TSchema extends Record<string, unknown> = Record<string,
}

const session = new ExpoSQLiteSession(client, dialect, schema, { logger });
return new ExpoSQLiteDatabase('sync', dialect, session, schema) as ExpoSQLiteDatabase<TSchema>;
return new BaseSQLiteDatabase('sync', dialect, session, schema) as ExpoSQLiteDatabase<TSchema>;
}
2 changes: 0 additions & 2 deletions drizzle-orm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export * from './entity.ts';
export * from './errors.ts';
export * from './expressions.ts';
export * from './logger.ts';
export * from './monodriver.ts';
export * from './monomigrator.ts';
export * from './operations.ts';
export * from './query-promise.ts';
export * from './relations.ts';
Expand Down
4 changes: 2 additions & 2 deletions drizzle-orm/src/libsql/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { LibSQLDatabase } from './driver.ts';

export async function migrate<TSchema extends Record<string, unknown>>(
db: LibSQLDatabase<TSchema>,
config: MigrationConfig | string,
config: MigrationConfig,
) {
const migrations = readMigrationFiles(config);
const migrationsTable = config === undefined
Expand Down Expand Up @@ -47,5 +47,5 @@ export async function migrate<TSchema extends Record<string, unknown>>(
}
}

await db.session.migrate(statementToBatch);
await db.session.batch(statementToBatch);
}
15 changes: 0 additions & 15 deletions drizzle-orm/src/libsql/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,6 @@ export class LibSQLSession<
return batchResults.map((result, i) => preparedQueries[i]!.mapResult(result, true));
}

async migrate<T extends BatchItem<'sqlite'>[] | readonly BatchItem<'sqlite'>[]>(queries: T) {
const preparedQueries: PreparedQuery[] = [];
const builtQueries: InStatement[] = [];

for (const query of queries) {
const preparedQuery = query._prepare();
const builtQuery = preparedQuery.getQuery();
preparedQueries.push(preparedQuery);
builtQueries.push({ sql: builtQuery.sql, args: builtQuery.params as InArgs });
}

const batchResults = await this.client.migrate(builtQueries);
return batchResults.map((result, i) => preparedQueries[i]!.mapResult(result, true));
}

override async transaction<T>(
transaction: (db: LibSQLTransaction<TFullSchema, TSchema>) => T | Promise<T>,
_config?: SQLiteTransactionConfig,
Expand Down
Loading

0 comments on commit 0f4fdf7

Please sign in to comment.