Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta #1577

Merged
merged 79 commits into from
Nov 29, 2023
Merged

Beta #1577

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
ba389d5
fix: Fix proxy migrators and tests
RomanNabukhotnyi Oct 21, 2023
ed33301
Merge branch 'beta' into proxies
RomanNabukhotnyi Oct 21, 2023
6e97888
fix: Fix snapshots
RomanNabukhotnyi Oct 23, 2023
0183e82
fixes d1 example
domlen2003 Oct 24, 2023
fbf2627
Add `sql` to `distinct on` column separator
L-Mario564 Nov 4, 2023
36910d7
Update `select distinct` PG test
L-Mario564 Nov 4, 2023
73981dc
Implement PG aggregate functions
L-Mario564 Nov 9, 2023
11ab158
Implement MySQL and SQLite aggregate functions
L-Mario564 Nov 9, 2023
d4eb356
Create tests for aggregate functions
L-Mario564 Nov 10, 2023
5b62339
Merge remote-tracking branch 'upstream/beta' into add-aggregate-funct…
L-Mario564 Nov 10, 2023
824462a
Merge remote-tracking branch 'upstream/beta' into beta
L-Mario564 Nov 11, 2023
a6b1e68
Fix linting issues
L-Mario564 Nov 11, 2023
8eebe5b
Moved eslint-plugin-drizzle to drizzle-orm repository
Angelelz Nov 15, 2023
b5c8fe9
added to release feature branch and unpublish release branch workflows
Angelelz Nov 15, 2023
641b779
Refactor aggregate functions
L-Mario564 Nov 15, 2023
73c7af9
Added cpy-cli for a crossplatform build
Angelelz Nov 15, 2023
6aa0cd7
fixed lock file
Angelelz Nov 15, 2023
f4156aa
Add jsdoc for Pg delete
realmikesolo Nov 16, 2023
610acea
Update jsdoc for Pg delete
realmikesolo Nov 17, 2023
8fd0a47
Remove mentions of `BuiltInFunction`
L-Mario564 Nov 18, 2023
7e2166f
Make aggregate functions common across dialects
L-Mario564 Nov 18, 2023
bca8684
Update integration tests
L-Mario564 Nov 18, 2023
08f6a10
Merge branch 'beta' into proxies
AndriiSherman Nov 19, 2023
165f99e
Add getSQL to PostgreSQL and MySQL
AndriiSherman Nov 19, 2023
48d0d7a
Add jsdoc for Pg insert & update;
realmikesolo Nov 19, 2023
b2224bf
Add jsdoc for MySQL delete, insert & update
realmikesolo Nov 19, 2023
69193e4
Add jsdoc for SQLite delete, update & insert
realmikesolo Nov 19, 2023
7eef222
[MySql] fix correct args passed to the functions and added tests
Angelelz Nov 21, 2023
bb9da24
[MySql] replaced the proxy in the replica for a getter
Angelelz Nov 21, 2023
135c46f
[sqlite] fixed arguments passed correctly, eliminated proxy from with…
Angelelz Nov 21, 2023
08996b4
Add jsdoc for Pg select
realmikesolo Nov 22, 2023
cca2c44
Add await in examples
realmikesolo Nov 22, 2023
475a531
Add jsdoc for MySQL select
realmikesolo Nov 22, 2023
f34576f
fix example
realmikesolo Nov 22, 2023
0872c4f
Add jsdoc for SQLite select
realmikesolo Nov 22, 2023
30bbc1a
Remove unnecessary comments
L-Mario564 Nov 23, 2023
5d51ab5
Add jsdoc for Pg joins
realmikesolo Nov 23, 2023
b2fac79
Add jsdoc for MySQL joins
realmikesolo Nov 24, 2023
38ae3e1
Add jsdoc for SQLite joins
realmikesolo Nov 24, 2023
32cde36
Add jsdoc for Pg union, intersect, except
realmikesolo Nov 24, 2023
eb24d74
Add jsdoc for Pg set operations (functions)
realmikesolo Nov 27, 2023
aec895c
Refactor jsdoc for Pg set operators
realmikesolo Nov 27, 2023
190159e
Add jsdoc for MySQL set operations
realmikesolo Nov 27, 2023
2aa47c5
Add jsdoc for SQLite set operations
realmikesolo Nov 27, 2023
d14c86d
Add jsdoc for Pg with clause
realmikesolo Nov 27, 2023
6071b5f
Add jsdoc for MySQL, SQLite with clause
realmikesolo Nov 27, 2023
e4ad266
Merge pull request #1522 from realmikesolo/beta
AndriiSherman Nov 27, 2023
c209b17
Merge branch 'beta' into fix-with-recursive-args
AndriiSherman Nov 27, 2023
cb3dd40
Merge branch 'beta' into proxies
AndriiSherman Nov 27, 2023
42c8588
Merge branch 'main' into main
AndriiSherman Nov 27, 2023
703e7eb
Merge branch 'beta' into main
AndriiSherman Nov 27, 2023
8ce46e5
Merge branch 'beta' into beta
AndriiSherman Nov 27, 2023
f3a39e9
Merge branch 'beta' into add-aggregate-functions
AndriiSherman Nov 27, 2023
aad4fe0
Merge pull request #1399 from RomanNabukhotnyi/proxies
AndriiSherman Nov 27, 2023
15b28ea
Merge branch 'beta' into main
AndriiSherman Nov 27, 2023
b5eb2c2
Merge branch 'beta' into beta
AndriiSherman Nov 27, 2023
501e283
Merge pull request #1466 from L-Mario564/beta
AndriiSherman Nov 27, 2023
a4b7a0a
Merge branch 'beta' into main
AndriiSherman Nov 27, 2023
c695972
Merge branch 'beta' into add-aggregate-functions
AndriiSherman Nov 27, 2023
142bc1f
Merge pull request #1411 from domlen2003/main
AndriiSherman Nov 27, 2023
0606ccb
Merge branch 'beta' into add-aggregate-functions
AndriiSherman Nov 27, 2023
6efb423
Merge branch 'beta' into feat-eslint-plugin
AndriiSherman Nov 27, 2023
255a7c8
Merge pull request #1487 from L-Mario564/add-aggregate-functions
AndriiSherman Nov 27, 2023
d615df5
Merge branch 'beta' of github.com:drizzle-team/drizzle-orm into patch…
AndriiSherman Nov 27, 2023
32f3f47
Merge pull request #1567 from drizzle-team/patch-sql
AndriiSherman Nov 27, 2023
4dc8c14
[Pg] fixed arguments passed correctly, eliminated proxy from with rep…
Angelelz Nov 28, 2023
5ab7930
Added new option to define the name of the db object on delete
Angelelz Nov 28, 2023
6855278
Added test for new option on delete
Angelelz Nov 28, 2023
3aa90ed
Added option to update and added tests
Angelelz Nov 28, 2023
a425bbe
Updated readme
Angelelz Nov 28, 2023
dfc7442
fix types
Angelelz Nov 28, 2023
26175d2
Merge branch 'beta' into fix-with-recursive-args
AndriiSherman Nov 28, 2023
333bedf
Merge branch 'beta' into feat-eslint-plugin
AndriiSherman Nov 28, 2023
2d1807a
Merge branch 'beta' into feat-eslint-plugin
AndriiSherman Nov 28, 2023
44e2467
Merge pull request #1536 from Angelelz/fix-with-recursive-args
AndriiSherman Nov 28, 2023
1edfc39
Merge branch 'beta' into feat-eslint-plugin
AndriiSherman Nov 28, 2023
89a2300
Merge pull request #1514 from Angelelz/feat-eslint-plugin
AndriiSherman Nov 28, 2023
758723b
Bump drizzle-orm and eslint-plugin versions
AndriiSherman Nov 29, 2023
e78b53e
Add JsDoc info
AndriiSherman Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- drizzle-zod
- drizzle-typebox
- drizzle-valibot
- eslint-plugin-drizzle
runs-on: ubuntu-20.04
permissions:
contents: read
Expand Down Expand Up @@ -91,8 +92,8 @@ jobs:
is_version_published="$(npm view ${{ matrix.package }} versions --json | jq -r '.[] | select(. == "'$version'") | . == "'$version'"')"

if [[ "$is_version_published" == "true" ]]; then
echo "\`${{ matrix.package }}@$version\` already published, adding tag \`$tag\`" >> $GITHUB_STEP_SUMMARY
npm dist-tag add ${{ matrix.package }}@$version $tag
echo "\`${{ matrix.package }}@ $version\` already published, adding tag \`$tag\`" >> $GITHUB_STEP_SUMMARY
npm dist-tag add ${{ matrix.package }}@ $version $tag
else
{
echo "version=$version"
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/release-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- drizzle-zod
- drizzle-typebox
- drizzle-valibot
- eslint-plugin-drizzle
runs-on: ubuntu-20.04
services:
postgres:
Expand Down Expand Up @@ -82,8 +83,8 @@ jobs:
is_version_published="$(npm view ${{ matrix.package }} versions --json | jq -r '.[] | select(. == "'$version'") | . == "'$version'"')"

if [[ "$is_version_published" == "true" ]]; then
echo "\`${{ matrix.package }}@$version\` already published, adding tag \`latest\`" >> $GITHUB_STEP_SUMMARY
npm dist-tag add ${{ matrix.package }}@$version latest
echo "\`${{ matrix.package }}@ $version\` already published, adding tag \`latest\`" >> $GITHUB_STEP_SUMMARY
npm dist-tag add ${{ matrix.package }}@ $version latest
elif [[ "$latest" != "$version" ]]; then
echo "Latest: $latest"
echo "Current: $version"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unpublish-release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
- drizzle-zod
- drizzle-typebox
- drizzle-valibot
- eslint-plugin-drizzle
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand Down
276 changes: 276 additions & 0 deletions changelogs/drizzle-orm/0.29.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
# Fixes

- Forward args correctly when using withReplica feature #1536. Thanks @Angelelz
- Fix selectDistinctOn not working with multiple columns #1466. Thanks @L-Mario564

# New Features/Helpers

## 🎉 Detailed JSDoc for all query builders in all dialects - thanks @realmikesolo

You can now access more information, hints, documentation links, etc. while developing and using JSDoc right in your IDE. Previously, we had them only for filter expressions, but now you can see them for all parts of the Drizzle query builder

## 🎉 New helpers for aggregate functions in SQL - thanks @L-Mario564

> Remember, aggregation functions are often used with the GROUP BY clause of the SELECT statement. So if you are selecting using aggregating functions and other columns in one query,
be sure to use the `.groupBy` clause

Here is a list of functions and equivalent using `sql` template

**count**
```ts
await db.select({ value: count() }).from(users);
await db.select({ value: count(users.id) }).from(users);

// It's equivalent to writing
await db.select({
value: sql`count('*'))`.mapWith(Number)
}).from(users);
await db.select({
value: sql`count(${users.id})`.mapWith(Number)
}).from(users);
```

**countDistinct**
```ts
await db.select({ value: countDistinct(users.id) }).from(users);

// It's equivalent to writing
await db.select({
value: sql`count(${users.id})`.mapWith(Number)
}).from(users);
```

**avg**
```ts
await db.select({ value: avg(users.id) }).from(users);

// It's equivalent to writing
await db.select({
value: sql`avg(${users.id})`.mapWith(String)
}).from(users);
```

**avgDistinct**
```ts
await db.select({ value: avgDistinct(users.id) }).from(users);

// It's equivalent to writing
await db.select({
value: sql`avg(distinct ${users.id})`.mapWith(String)
}).from(users);
```

**sum**
```ts
await db.select({ value: sum(users.id) }).from(users);

// It's equivalent to writing
await db.select({
value: sql`sum(${users.id})`.mapWith(String)
}).from(users);
```

**sumDistinct**
```ts
await db.select({ value: sumDistinct(users.id) }).from(users);

// It's equivalent to writing
await db.select({
value: sql`sum(distinct ${users.id})`.mapWith(String)
}).from(users);
```

**max**
```ts
await db.select({ value: max(users.id) }).from(users);

// It's equivalent to writing
await db.select({
value: sql`max(${expression})`.mapWith(users.id)
}).from(users);
```

**min**
```ts
await db.select({ value: min(users.id) }).from(users);

// It's equivalent to writing
await db.select({
value: sql`min(${users.id})`.mapWith(users.id)
}).from(users);
```

# New Packages
## 🎉 ESLint Drizzle Plugin

For cases where it's impossible to perform type checks for specific scenarios, or where it's possible but error messages would be challenging to understand, we've decided to create an ESLint package with recommended rules. This package aims to assist developers in handling crucial scenarios during development

> Big thanks to @Angelelz for initiating the development of this package and transferring it to the Drizzle Team's npm

## Install

```sh
[ npm | yarn | pnpm | bun ] install eslint eslint-plugin-drizzle
```
You can install those packages for typescript support in your IDE
```sh
[ npm | yarn | pnpm | bun ] install @typescript-eslint/eslint-plugin @typescript-eslint/parser
```

## Usage

Create a `.eslintrc.yml` file, add `drizzle` to the `plugins`, and specify the rules you want to use. You can find a list of all existing rules below

```yml
root: true
parser: '@typescript-eslint/parser'
parserOptions:
project: './tsconfig.json'
plugins:
- drizzle
rules:
'drizzle/enforce-delete-with-where': "error"
'drizzle/enforce-update-with-where': "error"
```

### All config

This plugin exports an [`all` config](src/configs/all.js) that makes use of all rules (except for deprecated ones).

```yml
root: true
extends:
- "plugin:drizzle/all"
parser: '@typescript-eslint/parser'
parserOptions:
project: './tsconfig.json'
plugins:
- drizzle
```

At the moment, `all` is equivalent to `recommended`

```yml
root: true
extends:
- "plugin:drizzle/recommended"
parser: '@typescript-eslint/parser'
parserOptions:
project: './tsconfig.json'
plugins:
- drizzle
```

## Rules

**enforce-delete-with-where**: Enforce using `delete` with the`.where()` clause in the `.delete()` statement. Most of the time, you don't need to delete all rows in the table and require some kind of `WHERE` statements.

**Error Message**:
```
Without `.where(...)` you will delete all the rows in a table. If you didn't want to do it, please use `db.delete(...).where(...)` instead. Otherwise you can ignore this rule here
```

Optionally, you can define a `drizzleObjectName` in the plugin options that accept a `string` or `string[]`. This is useful when you have objects or classes with a delete method that's not from Drizzle. Such a `delete` method will trigger the ESLint rule. To avoid that, you can define the name of the Drizzle object that you use in your codebase (like db) so that the rule would only trigger if the delete method comes from this object:

Example, config 1:
```json
"rules": {
"drizzle/enforce-delete-with-where": ["error"]
}
```

```ts
class MyClass {
public delete() {
return {}
}
}

const myClassObj = new MyClass();

// ---> Will be triggered by ESLint Rule
myClassObj.delete()

const db = drizzle(...)
// ---> Will be triggered by ESLint Rule
db.delete()
```

Example, config 2:
```json
"rules": {
"drizzle/enforce-delete-with-where": ["error", { "drizzleObjectName": ["db"] }],
}
```
```ts
class MyClass {
public delete() {
return {}
}
}

const myClassObj = new MyClass();

// ---> Will NOT be triggered by ESLint Rule
myClassObj.delete()

const db = drizzle(...)
// ---> Will be triggered by ESLint Rule
db.delete()
```

**enforce-update-with-where**: Enforce using `update` with the`.where()` clause in the `.update()` statement. Most of the time, you don't need to update all rows in the table and require some kind of `WHERE` statements.

**Error Message**:
```
Without `.where(...)` you will update all the rows in a table. If you didn't want to do it, please use `db.update(...).set(...).where(...)` instead. Otherwise you can ignore this rule here
```

Optionally, you can define a `drizzleObjectName` in the plugin options that accept a `string` or `string[]`. This is useful when you have objects or classes with a delete method that's not from Drizzle. Such as `update` method will trigger the ESLint rule. To avoid that, you can define the name of the Drizzle object that you use in your codebase (like db) so that the rule would only trigger if the delete method comes from this object:

Example, config 1:
```json
"rules": {
"drizzle/enforce-update-with-where": ["error"]
}
```

```ts
class MyClass {
public update() {
return {}
}
}

const myClassObj = new MyClass();

// ---> Will be triggered by ESLint Rule
myClassObj.update()

const db = drizzle(...)
// ---> Will be triggered by ESLint Rule
db.update()
```

Example, config 2:
```json
"rules": {
"drizzle/enforce-update-with-where": ["error", { "drizzleObjectName": ["db"] }],
}
```
```ts
class MyClass {
public update() {
return {}
}
}

const myClassObj = new MyClass();

// ---> Will NOT be triggered by ESLint Rule
myClassObj.update()

const db = drizzle(...)
// ---> Will be triggered by ESLint Rule
db.update()
```
4 changes: 4 additions & 0 deletions changelogs/eslint-plugin-drizzle/0.2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# eslint-plugin-drizzle 0.1.0

- Initial release
- 2 rules available
4 changes: 4 additions & 0 deletions changelogs/eslint-plugin-drizzle/0.2.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# eslint-plugin-drizzle 0.2.1

- Update README.md
- Change error text message
2 changes: 1 addition & 1 deletion drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.29.0",
"version": "0.29.1",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
Expand Down
Loading