Skip to content

Commit

Permalink
Fix/branch clean up for pr drizzle orm (#30)
Browse files Browse the repository at this point in the history
* branch clean up for pr

* wip [last visited drizzle-kit/src/cli/validations/common.ts

* wip [last visited drizzle-kit/src/schemaValidator.ts

* drizzle kit cleaning

* lint fix

* remove unecessary readme.md

* replace prepareAndMigrateSqlite for prepareAndMigrateSingleStore when dialect is singlestore

* drizzle orm cleaning
  • Loading branch information
Rodriguespn authored Oct 1, 2024
1 parent 281c633 commit d0fb8cd
Show file tree
Hide file tree
Showing 42 changed files with 62 additions and 1,159 deletions.
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 d0fb8cd

Please sign in to comment.