Skip to content

Commit

Permalink
Merge pull request #2478 from drizzle-team/prisma-driver
Browse files Browse the repository at this point in the history
Add Prisma driver via extension
  • Loading branch information
dankochetov authored Jun 9, 2024
2 parents bd14b3f + f9f4c2e commit 471ed1b
Show file tree
Hide file tree
Showing 69 changed files with 5,366 additions and 2,160 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ examples
**/*.mjs
**/*.cjs
**/playground
integration-tests/tests/prisma/*/client
integration-tests/tests/prisma/*/drizzle
18 changes: 16 additions & 2 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ plugins:
- import
- unused-imports
- no-instanceof
- drizzle
- drizzle-internal
overrides:
- files:
- '**/tests/**/*.ts'
- '**/type-tests/**/*.ts'
rules:
import/extensions: 'off'
no-instanceof: 'off'
- files: 'eslint-plugin-drizzle/**/*'
rules:
import/extensions: 'off'
rules:
'@typescript-eslint/consistent-type-imports':
- error
Expand All @@ -24,6 +34,10 @@ rules:
import/no-useless-path-segments: error
import/newline-after-import: error
import/no-duplicates: error
import/extensions:
- error
- always
- ignorePackages: true
'@typescript-eslint/no-explicit-any': 'off'
'@typescript-eslint/no-non-null-assertion': 'off'
'@typescript-eslint/no-namespace': 'off'
Expand Down Expand Up @@ -61,7 +75,7 @@ rules:
'unicorn/relative-url-style': 'off'
'eqeqeq': 'error'
'no-instanceof/no-instanceof': 'error'
'drizzle/require-entity-kind': 'error'
'drizzle-internal/require-entity-kind': 'error'
'unicorn/prefer-string-replace-all': 'off'
'unicorn/no-process-exit': 'off'
'@typescript-eslint/ban-ts-comment': 'off'
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 18
node-version: '18.18'
registry-url: 'https://registry.npmjs.org'

- uses: pnpm/action-setup@v3
Expand Down Expand Up @@ -131,6 +131,16 @@ jobs:
- name: Build
if: steps.checks.outputs.has_new_release == 'true'
run: |
(
cd drizzle-orm
pnpm prisma generate --schema src/prisma/schema.prisma
)
(
cd integration-tests
pnpm prisma generate --schema tests/prisma/pg/schema.prisma
pnpm prisma generate --schema tests/prisma/mysql/schema.prisma
pnpm prisma generate --schema tests/prisma/sqlite/schema.prisma
)
pnpm build
- name: Run tests
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/release-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 18
node-version: '18.18'
registry-url: 'https://registry.npmjs.org'

- uses: pnpm/action-setup@v3
Expand Down Expand Up @@ -134,6 +134,16 @@ jobs:
- name: Build
if: steps.checks.outputs.has_new_release == 'true'
run: |
(
cd drizzle-orm
pnpm prisma generate --schema src/prisma/schema.prisma
)
(
cd integration-tests
pnpm prisma generate --schema tests/prisma/pg/schema.prisma
pnpm prisma generate --schema tests/prisma/mysql/schema.prisma
pnpm prisma generate --schema tests/prisma/sqlite/schema.prisma
)
pnpm build
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist.new
.rollup.cache
dist-dts
rollup.config-*.mjs
.DS_Store
4 changes: 3 additions & 1 deletion dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"**/*snapshot.json",
"**/_journal.json",
"**/tsup.config*.mjs",
"**/.sst"
"**/.sst",
"integration-tests/tests/prisma/*/client",
"integration-tests/tests/prisma/*/drizzle"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.83.0.wasm",
Expand Down
11 changes: 7 additions & 4 deletions drizzle-orm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"@op-engineering/op-sqlite": ">=2",
"@opentelemetry/api": "^1.4.1",
"@planetscale/database": ">=1",
"@prisma/client": "*",
"@tidbcloud/serverless": "*",
"@types/better-sqlite3": "*",
"@types/pg": "*",
"@types/react": ">=18",
Expand All @@ -67,8 +69,7 @@
"postgres": ">=3",
"react": ">=18",
"sql.js": ">=1",
"sqlite3": ">=5",
"@tidbcloud/serverless": "*"
"sqlite3": ">=5"
},
"peerDependenciesMeta": {
"mysql2": {
Expand Down Expand Up @@ -160,6 +161,7 @@
"@opentelemetry/api": "^1.4.1",
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@planetscale/database": "^1.16.0",
"@prisma/client": "5.14.0",
"@tidbcloud/serverless": "^0.1.1",
"@types/better-sqlite3": "^7.6.4",
"@types/node": "^20.2.5",
Expand All @@ -177,13 +179,14 @@
"mysql2": "^3.3.3",
"pg": "^8.11.0",
"postgres": "^3.3.5",
"prisma": "5.14.0",
"react": "^18.2.0",
"sql.js": "^1.8.0",
"sqlite3": "^5.1.2",
"tslib": "^2.5.2",
"tsx": "^3.12.7",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.31.4",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0",
"zod": "^3.20.2",
"zx": "^7.2.2"
}
Expand Down
4 changes: 2 additions & 2 deletions drizzle-orm/src/aws-data-api/pg/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import type { Logger } from '~/logger.ts';
import {
type PgDialect,
PgPreparedQuery,
type PgQueryResultHKT,
PgSession,
PgTransaction,
type PgTransactionConfig,
type PreparedQueryConfig,
type QueryResultHKT,
} from '~/pg-core/index.ts';
import type { SelectedFieldsOrdered } from '~/pg-core/query-builders/select.types.ts';
import type { RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';
Expand Down Expand Up @@ -265,6 +265,6 @@ export class AwsDataApiTransaction<

export type AwsDataApiPgQueryResult<T> = ExecuteStatementCommandOutput & { rows: T[] };

export interface AwsDataApiPgQueryResultHKT extends QueryResultHKT {
export interface AwsDataApiPgQueryResultHKT extends PgQueryResultHKT {
type: AwsDataApiPgQueryResult<any>;
}
10 changes: 5 additions & 5 deletions drizzle-orm/src/mysql-core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import { RelationalQueryBuilder } from './query-builders/query.ts';
import type { SelectedFields } from './query-builders/select.types.ts';
import type {
Mode,
MySqlQueryResultHKT,
MySqlQueryResultKind,
MySqlSession,
MySqlTransaction,
MySqlTransactionConfig,
PreparedQueryHKTBase,
QueryResultHKT,
QueryResultKind,
} from './session.ts';
import type { WithSubqueryWithSelection } from './subquery.ts';
import type { MySqlTable } from './table.ts';

export class MySqlDatabase<
TQueryResult extends QueryResultHKT,
TQueryResult extends MySqlQueryResultHKT,
TPreparedQueryHKT extends PreparedQueryHKTBase,
TFullSchema extends Record<string, unknown> = {},
TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,
Expand Down Expand Up @@ -452,7 +452,7 @@ export class MySqlDatabase<

execute<T extends { [column: string]: any } = ResultSetHeader>(
query: SQLWrapper,
): Promise<QueryResultKind<TQueryResult, T>> {
): Promise<MySqlQueryResultKind<TQueryResult, T>> {
return this.session.execute(query.getSQL());
}

Expand All @@ -470,7 +470,7 @@ export class MySqlDatabase<
export type MySQLWithReplicas<Q> = Q & { $primary: Q };

export const withReplicas = <
HKT extends QueryResultHKT,
HKT extends MySqlQueryResultHKT,
TPreparedQueryHKT extends PreparedQueryHKTBase,
TFullSchema extends Record<string, unknown>,
TSchema extends TablesRelationalConfig,
Expand Down
22 changes: 11 additions & 11 deletions drizzle-orm/src/mysql-core/query-builders/delete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { entityKind } from '~/entity.ts';
import type { MySqlDialect } from '~/mysql-core/dialect.ts';
import type {
AnyQueryResultHKT,
AnyMySqlQueryResultHKT,
MySqlPreparedQueryConfig,
MySqlQueryResultHKT,
MySqlQueryResultKind,
MySqlSession,
PreparedQueryConfig,
PreparedQueryHKTBase,
PreparedQueryKind,
QueryResultHKT,
QueryResultKind,
} from '~/mysql-core/session.ts';
import type { MySqlTable } from '~/mysql-core/table.ts';
import { QueryPromise } from '~/query-promise.ts';
Expand All @@ -33,7 +33,7 @@ export type MySqlDeleteWithout<

export type MySqlDelete<
TTable extends MySqlTable = MySqlTable,
TQueryResult extends QueryResultHKT = AnyQueryResultHKT,
TQueryResult extends MySqlQueryResultHKT = AnyMySqlQueryResultHKT,
TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,
> = MySqlDeleteBase<TTable, TQueryResult, TPreparedQueryHKT, true, never>;

Expand All @@ -46,8 +46,8 @@ export interface MySqlDeleteConfig {

export type MySqlDeletePrepare<T extends AnyMySqlDeleteBase> = PreparedQueryKind<
T['_']['preparedQueryHKT'],
PreparedQueryConfig & {
execute: QueryResultKind<T['_']['queryResult'], never>;
MySqlPreparedQueryConfig & {
execute: MySqlQueryResultKind<T['_']['queryResult'], never>;
iterator: never;
},
true
Expand All @@ -63,11 +63,11 @@ type AnyMySqlDeleteBase = MySqlDeleteBase<any, any, any, any, any>;

export interface MySqlDeleteBase<
TTable extends MySqlTable,
TQueryResult extends QueryResultHKT,
TQueryResult extends MySqlQueryResultHKT,
TPreparedQueryHKT extends PreparedQueryHKTBase,
TDynamic extends boolean = false,
TExcludedMethods extends string = never,
> extends QueryPromise<QueryResultKind<TQueryResult, never>> {
> extends QueryPromise<MySqlQueryResultKind<TQueryResult, never>> {
readonly _: {
readonly table: TTable;
readonly queryResult: TQueryResult;
Expand All @@ -79,13 +79,13 @@ export interface MySqlDeleteBase<

export class MySqlDeleteBase<
TTable extends MySqlTable,
TQueryResult extends QueryResultHKT,
TQueryResult extends MySqlQueryResultHKT,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
TPreparedQueryHKT extends PreparedQueryHKTBase,
TDynamic extends boolean = false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
TExcludedMethods extends string = never,
> extends QueryPromise<QueryResultKind<TQueryResult, never>> implements SQLWrapper {
> extends QueryPromise<MySqlQueryResultKind<TQueryResult, never>> implements SQLWrapper {
static readonly [entityKind]: string = 'MySqlDelete';

private config: MySqlDeleteConfig;
Expand Down
24 changes: 12 additions & 12 deletions drizzle-orm/src/mysql-core/query-builders/insert.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { entityKind, is } from '~/entity.ts';
import type { MySqlDialect } from '~/mysql-core/dialect.ts';
import type {
AnyQueryResultHKT,
AnyMySqlQueryResultHKT,
MySqlPreparedQueryConfig,
MySqlQueryResultHKT,
MySqlQueryResultKind,
MySqlSession,
PreparedQueryConfig,
PreparedQueryHKTBase,
PreparedQueryKind,
QueryResultHKT,
QueryResultKind,
} from '~/mysql-core/session.ts';
import type { MySqlTable } from '~/mysql-core/table.ts';
import { QueryPromise } from '~/query-promise.ts';
Expand All @@ -34,7 +34,7 @@ export type MySqlInsertValue<TTable extends MySqlTable> =

export class MySqlInsertBuilder<
TTable extends MySqlTable,
TQueryResult extends QueryResultHKT,
TQueryResult extends MySqlQueryResultHKT,
TPreparedQueryHKT extends PreparedQueryHKTBase,
> {
static readonly [entityKind]: string = 'MySqlInsertBuilder';
Expand Down Expand Up @@ -96,8 +96,8 @@ export type MySqlInsertDynamic<T extends AnyMySqlInsert> = MySqlInsert<

export type MySqlInsertPrepare<T extends AnyMySqlInsert> = PreparedQueryKind<
T['_']['preparedQueryHKT'],
PreparedQueryConfig & {
execute: QueryResultKind<T['_']['queryResult'], never>;
MySqlPreparedQueryConfig & {
execute: MySqlQueryResultKind<T['_']['queryResult'], never>;
iterator: never;
},
true
Expand All @@ -109,19 +109,19 @@ export type MySqlInsertOnDuplicateKeyUpdateConfig<T extends AnyMySqlInsert> = {

export type MySqlInsert<
TTable extends MySqlTable = MySqlTable,
TQueryResult extends QueryResultHKT = AnyQueryResultHKT,
TQueryResult extends MySqlQueryResultHKT = AnyMySqlQueryResultHKT,
TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,
> = MySqlInsertBase<TTable, TQueryResult, TPreparedQueryHKT, true, never>;

export type AnyMySqlInsert = MySqlInsertBase<any, any, any, any, any>;

export interface MySqlInsertBase<
TTable extends MySqlTable,
TQueryResult extends QueryResultHKT,
TQueryResult extends MySqlQueryResultHKT,
TPreparedQueryHKT extends PreparedQueryHKTBase,
TDynamic extends boolean = false,
TExcludedMethods extends string = never,
> extends QueryPromise<QueryResultKind<TQueryResult, never>>, SQLWrapper {
> extends QueryPromise<MySqlQueryResultKind<TQueryResult, never>>, SQLWrapper {
readonly _: {
readonly table: TTable;
readonly queryResult: TQueryResult;
Expand All @@ -133,14 +133,14 @@ export interface MySqlInsertBase<

export class MySqlInsertBase<
TTable extends MySqlTable,
TQueryResult extends QueryResultHKT,
TQueryResult extends MySqlQueryResultHKT,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
TPreparedQueryHKT extends PreparedQueryHKTBase,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
TDynamic extends boolean = false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
TExcludedMethods extends string = never,
> extends QueryPromise<QueryResultKind<TQueryResult, never>> implements SQLWrapper {
> extends QueryPromise<MySqlQueryResultKind<TQueryResult, never>> implements SQLWrapper {
static readonly [entityKind]: string = 'MySqlInsert';

declare protected $table: TTable;
Expand Down
10 changes: 8 additions & 2 deletions drizzle-orm/src/mysql-core/query-builders/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import {
import type { Query, QueryWithTypings, SQL } from '~/sql/sql.ts';
import type { KnownKeysOnly } from '~/utils.ts';
import type { MySqlDialect } from '../dialect.ts';
import type { Mode, MySqlSession, PreparedQueryConfig, PreparedQueryHKTBase, PreparedQueryKind } from '../session.ts';
import type {
Mode,
MySqlPreparedQueryConfig,
MySqlSession,
PreparedQueryHKTBase,
PreparedQueryKind,
} from '../session.ts';
import type { MySqlTable } from '../table.ts';

export class RelationalQueryBuilder<
Expand Down Expand Up @@ -102,7 +108,7 @@ export class MySqlRelationalQuery<
}
return rows as TResult;
},
) as PreparedQueryKind<TPreparedQueryHKT, PreparedQueryConfig & { execute: TResult }, true>;
) as PreparedQueryKind<TPreparedQueryHKT, MySqlPreparedQueryConfig & { execute: TResult }, true>;
}

private _getQuery() {
Expand Down
Loading

0 comments on commit 471ed1b

Please sign in to comment.