Skip to content

Commit

Permalink
Merge pull request #2600 from drizzle-team/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
AndriiSherman authored Jul 8, 2024
2 parents 4ecfe1f + a90773c commit f0c5aff
Show file tree
Hide file tree
Showing 152 changed files with 22,768 additions and 45,407 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
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
permissions:
actions: read
contents: read
Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
- 55432:5432
mysql:
image: mysql:8
env:
Expand All @@ -73,13 +73,13 @@ jobs:
--health-timeout 5s
--health-retries 5
ports:
- 3306:3306
- 33306:3306
steps:
- uses: actions/checkout@v4

- 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,15 +131,25 @@ 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
if: steps.checks.outputs.has_new_release == 'true'
env:
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:5432/drizzle
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:55432/drizzle
PG_VECTOR_CONNECTION_STRING: postgres://postgres:postgres@localhost:54321/drizzle
PG_POSTGIS_CONNECTION_STRING: postgres://postgres:postgres@localhost:54322/drizzle
MYSQL_CONNECTION_STRING: mysql://root:root@localhost:3306/drizzle
MYSQL_CONNECTION_STRING: mysql://root:root@localhost:33306/drizzle
PLANETSCALE_CONNECTION_STRING: ${{ secrets.PLANETSCALE_CONNECTION_STRING }}
NEON_CONNECTION_STRING: ${{ secrets.NEON_CONNECTION_STRING }}
TIDB_CONNECTION_STRING: ${{ secrets.TIDB_CONNECTION_STRING }}
Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/release-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
- 55432:5432
mysql:
image: mysql:8
env:
Expand All @@ -66,13 +66,13 @@ jobs:
--health-timeout 5s
--health-retries 5
ports:
- 3306:3306
- 33306:3306
steps:
- uses: actions/checkout@v4

- 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,15 +134,25 @@ 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
if: steps.checks.outputs.has_new_release == 'true'
env:
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:5432/drizzle
PG_CONNECTION_STRING: postgres://postgres:postgres@localhost:55432/drizzle
PG_VECTOR_CONNECTION_STRING: postgres://postgres:postgres@localhost:54321/drizzle
PG_POSTGIS_CONNECTION_STRING: postgres://postgres:postgres@localhost:54322/drizzle
MYSQL_CONNECTION_STRING: mysql://root:root@localhost:3306/drizzle
MYSQL_CONNECTION_STRING: mysql://root:root@localhost:33306/drizzle
PLANETSCALE_CONNECTION_STRING: ${{ secrets.PLANETSCALE_CONNECTION_STRING }}
NEON_CONNECTION_STRING: ${{ secrets.NEON_CONNECTION_STRING }}
TIDB_CONNECTION_STRING: ${{ secrets.TIDB_CONNECTION_STRING }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unpublish-release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

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

- name: Unpublish
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ dist.new
.rollup.cache
dist-dts
rollup.config-*.mjs
*.log
.DS_Store
2 changes: 2 additions & 0 deletions changelogs/drizzle-orm/0.31.0-beta.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ db.select({ innerProduct: sql`(${maxInnerProduct(items.embedding, [3,1,2])}) * -

// and more!
```

- 🛠️ Fixed RQB behavior for tables with same names in different schemas
17 changes: 17 additions & 0 deletions changelogs/drizzle-orm/0.31.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Bug fixed

- 🛠️ Fixed RQB behavior for tables with same names in different schemas
- 🛠️ Fixed [BUG]: Mismatched type hints when using RDS Data API - #2097

### New Prisma-Drizzle extension

```ts
import { PrismaClient } from '@prisma/client';
import { drizzle } from 'drizzle-orm/prisma/pg';
import { User } from './drizzle';

const prisma = new PrismaClient().$extends(drizzle());
const users = await prisma.$drizzle.select().from(User);
```

For more info, check docs: https://orm.drizzle.team/docs/prisma
10 changes: 6 additions & 4 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
"**/*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",
"https://plugins.dprint.dev/json-0.19.2.wasm",
"https://plugins.dprint.dev/markdown-0.15.2.wasm"
"https://plugins.dprint.dev/typescript-0.91.1.wasm",
"https://plugins.dprint.dev/json-0.19.3.wasm",
"https://plugins.dprint.dev/markdown-0.17.1.wasm"
]
}
13 changes: 8 additions & 5 deletions drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.31.2",
"version": "0.31.3",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
Expand Down 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
8 changes: 4 additions & 4 deletions drizzle-orm/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ await fs.remove('dist.new');

await Promise.all([
(async () => {
await $`tsup`;
await $`tsup`.stdio('pipe', 'pipe', 'pipe');
})(),
(async () => {
await $`tsc -p tsconfig.dts.json`;
await $`tsc -p tsconfig.dts.json`.stdio('pipe', 'pipe', 'pipe');
await cpy('dist-dts/**/*.d.ts', 'dist.new', {
rename: (basename) => basename.replace(/\.d\.ts$/, '.d.cts'),
});
Expand All @@ -64,8 +64,8 @@ await Promise.all([
]);

await Promise.all([
$`tsup src/version.ts --no-config --dts --format esm --outDir dist.new`,
$`tsup src/version.ts --no-config --dts --format cjs --outDir dist.new`,
$`tsup src/version.ts --no-config --dts --format esm --outDir dist.new`.stdio('pipe', 'pipe', 'pipe'),
$`tsup src/version.ts --no-config --dts --format cjs --outDir dist.new`.stdio('pipe', 'pipe', 'pipe'),
]);

await $`scripts/fix-imports.ts`;
Expand Down
11 changes: 3 additions & 8 deletions drizzle-orm/src/aws-data-api/pg/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,14 @@ export class AwsPgDialect extends PgDialect {
{ table, values, onConflict, returning }: PgInsertConfig<PgTable<TableConfig>>,
): SQL<unknown> {
const columns: Record<string, PgColumn> = table[Table.Symbol.Columns];
const colEntries: [string, PgColumn][] = Object.entries(columns);
for (const value of values) {
for (const [fieldName, col] of colEntries) {
for (const fieldName of Object.keys(columns)) {
const colValue = value[fieldName];
if (
is(colValue, Param) && colValue.value !== undefined && is(colValue.encoder, PgArray)
&& Array.isArray(colValue.value)
) {
value[fieldName] = sql`cast(${col.mapToDriverValue(colValue.value)} as ${
sql.raw(colValue.encoder.getSQLType())
})`;
value[fieldName] = sql`cast(${colValue} as ${sql.raw(colValue.encoder.getSQLType())})`;
}
}
}
Expand All @@ -83,9 +80,7 @@ export class AwsPgDialect extends PgDialect {
currentColumn && is(colValue, Param) && colValue.value !== undefined && is(colValue.encoder, PgArray)
&& Array.isArray(colValue.value)
) {
set[colName] = sql`cast(${currentColumn?.mapToDriverValue(colValue.value)} as ${
sql.raw(colValue.encoder.getSQLType())
})`;
set[colName] = sql`cast(${colValue} as ${sql.raw(colValue.encoder.getSQLType())})`;
}
}
return super.buildUpdateSet(table, set);
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>;
}
4 changes: 2 additions & 2 deletions drizzle-orm/src/d1/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function d1ToRawMapping(results: any) {
}

export class D1PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends SQLitePreparedQuery<
{ type: 'async'; run: D1Result; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }
{ type: 'async'; run: D1Response; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }
> {
static readonly [entityKind]: string = 'D1PreparedQuery';

Expand Down Expand Up @@ -177,7 +177,7 @@ export class D1PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig
this.stmt = stmt;
}

run(placeholderValues?: Record<string, unknown>): Promise<D1Result> {
run(placeholderValues?: Record<string, unknown>): Promise<D1Response> {
const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
this.logger.logQuery(this.query.sql, params);
return this.stmt.bind(...params).run();
Expand Down
Loading

0 comments on commit f0c5aff

Please sign in to comment.