Skip to content

Commit

Permalink
Merge pull request #149 from drizzle-team/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
AndriiSherman authored Jan 26, 2023
2 parents 391e792 + 31c94dd commit 3753d10
Show file tree
Hide file tree
Showing 230 changed files with 1,181 additions and 1,314 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ jobs:
matrix:
package:
- drizzle-orm
- drizzle-orm-mysql
- drizzle-orm-pg
- drizzle-orm-sqlite
- drizzle-zod
runs-on: ubuntu-20.04
steps:
Expand Down
82 changes: 68 additions & 14 deletions .github/workflows/release-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ on: workflow_dispatch

jobs:
release:
permissions: write-all
strategy:
fail-fast: false
matrix:
package:
- drizzle-orm
- drizzle-orm-mysql
- drizzle-orm-pg
- drizzle-orm-sqlite
- drizzle-zod
runs-on: ubuntu-20.04
steps:
Expand All @@ -26,7 +25,10 @@ jobs:
version: latest
run_install: true

- name: Publish
- name: Check preconditions
id: checks
shell: bash
working-directory: ${{ matrix.package }}
run: |
latest="$(npm view --json ${{ matrix.package }} dist-tags.latest | jq -r)"
version="$(jq -r .version package.json)"
Expand All @@ -35,22 +37,74 @@ jobs:
echo "Latest: $latest"
echo "Current: $version"
is_version_published="$(npm view ${{ matrix.package }} versions --json | jq -r '.[] | select(. == "'$version'") | . == "'$version'"')"
if [[ "$is_version_published" == "true" ]]; then
echo "Version $version already published, adding tag $tag"
npm dist-tag add ${{ matrix.package }}@$version latest
else
echo echo "Publishing ${{ matrix.package }}@$version"
(cd .. && npm run pack -- --filter ${{ matrix.package }})
npm run publish
changelogPath=$(node -e "console.log(require('path').resolve('..', 'changelogs', '${{ matrix.package }}', '$version.md'))")
if [[ ! -f "$changelogPath" ]]; then
echo "::error::Changelog for version $version not found: $changelogPath"
exit 1
fi
# Post release message to Discord
curl -X POST -H "Content-Type: application/json" -d "{\"embeds\": [{\"title\": \"New \`${{ matrix.package }}\` release! 🎉\", \"url\": \"https://www.npmjs.com/package/${{ matrix.package }}\", \"color\": \"12907856\", \"fields\": [{\"name\": \"Tag\", \"value\": \"\`$tag\`\"}]}]}" ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
{
echo "version=$version"
echo "has_new_release=true"
echo "changelog_path=$changelogPath"
} >> $GITHUB_OUTPUT
else
echo "Already up to date: $version"
echo "\`$version\` is already latest on NPM" >> $GITHUB_STEP_SUMMARY
fi
- name: Publish
if: steps.checks.outputs.has_new_release == 'true'
working-directory: ${{ matrix.package }}
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
run: |
version="${{ steps.checks.outputs.version }}"
is_version_published="$(npm view ${{ matrix.package }} versions --json | jq -r '.[] | select(. == "'$version'") | . == "'$version'"')"
if [[ "$is_version_published" == "true" ]]; then
echo "Version $version already published, adding tag $tag"
npm dist-tag add ${{ matrix.package }}@$version latest
else
echo echo "Publishing ${{ matrix.package }}@$version"
(cd .. && npm run pack -- --filter ${{ matrix.package }})
npm run publish
fi
echo "npm: \`+ ${{ matrix.package }}@$version\`" >> $GITHUB_STEP_SUMMARY
# Post release message to Discord
curl -X POST -H "Content-Type: application/json" -d "{\"embeds\": [{\"title\": \"New \`${{ matrix.package }}\` release! 🎉\", \"url\": \"https://www.npmjs.com/package/${{ matrix.package }}\", \"color\": \"12907856\", \"fields\": [{\"name\": \"Tag\", \"value\": \"\`$tag\`\"}]}]}" ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
- name: Create GitHub release for ORM package
uses: actions/github-script@v6
if: matrix.package == 'drizzle-orm' && steps.checks.outputs.has_new_release == 'true'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
const fs = require("fs");
const path = require("path");
const version = "${{ steps.checks.outputs.version }}";
const changelog = fs.readFileSync("${{ steps.checks.outputs.changelog_path }}", "utf8");
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `${version}`,
name: `${version}`,
body: changelog,
});
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: `${{ matrix.package }}-${version}-dist.tgz`,
data: fs.readFileSync(path.resolve("${{ matrix.package }}", "package.tgz")),
});
} catch (e) {
core.setFailed(e.message);
}
3 changes: 0 additions & 3 deletions .github/workflows/unpublish-release-feature-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ jobs:
matrix:
package:
- drizzle-orm
- drizzle-orm-mysql
- drizzle-orm-pg
- drizzle-orm-sqlite
- drizzle-zod
runs-on: ubuntu-20.04
steps:
Expand Down
1 change: 1 addition & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ first-line-h1: false
line-length: false
MD010:
spaces_per_tab: 2
code_blocks: false
39 changes: 22 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,23 @@ There are several ways how you can provide a feedback

## <a name="contributing"></a> Contribution guidelines
---
1. [General setup](#general-setup)
- [Install node](#installing-node)
- [Install pnpm](#installing-pnpm)
- [Install docker](#installing-docker)
2. [Local project setup](#local-project-setup)
- [Clone project](#clone-project)
3. [Building project](#building-project)
- [Build project](#build-project)
- [Run tests](#run-tests)
4. [Commits and PRs](#commits-pr)
- [Commit guideline](#commit-guideline)
- [PR guideline](#pr-guideline)
- [Contributing](#contributing)
- [ Submitting bug report](#-submitting-bug-report)
- [ Submitting feature request](#-submitting-feature-request)
- [ Providing feedback](#-providing-feedback)
- [ Contribution guidelines](#-contribution-guidelines)
- [ General setup](#-general-setup)
- [ Installing node](#-installing-node)
- [ Install pnpm](#-install-pnpm)
- [ Install docker](#-install-docker)
- [ Local project setup](#-local-project-setup)
- [ Clone project](#-clone-project)
- [ Building project](#-building-project)
- [ Build project](#-build-project)
- [ Run tests](#-run-tests)
- [ Commits and PRs](#-commits-and-prs)
- [ Commit guideline](#-commit-guideline)
- [ PR guideline](#-pr-guideline)

## <a name="general-setup"></a> General setup
### <a name="installing-node"></a> Installing node
Expand Down Expand Up @@ -84,11 +89,11 @@ Project sctructure
📂 changelogs/ - all changelogs by modules
📂 drizzle-orm-pg/ - package with all resources for PostgreSQL database support
📂 drizzle-orm/src/pg-core/ - package with all resources for PostgreSQL database support
📂 drizzle-orm-sqlite/ - package with all resources for SQLite database support
📂 drizzle-orm/src/sqlite-core/ - package with all resources for SQLite database support
📂 drizzle-orm-mysql/ - package with all resources for MySQL database support
📂 drizzle-orm/src/mysql-core/ - package with all resources for MySQL database support
📂 examples/ - package with Drizzle ORM usage examples
Expand Down Expand Up @@ -118,7 +123,7 @@ Commit message patten
```
Example
```
drizzle-orm-pg: Add groupBy error message
drizzle-orm: [Pg] Add groupBy error message
In specific case, groupBy was responding with unreadable error
...
Expand All @@ -145,4 +150,4 @@ List of possible types for branch name
---
Each PR should contain:
- Tests on feature, that was created
- Tests on bugs, that was fixed
- Tests on bugs, that was fixed
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The ORM main philosophy is "If you know SQL, you know Drizzle ORM". We follow th

Drizzle ORM is being battle-tested on production projects by multiple teams 🚀 Give it a try and let us know if you have any questions or feedback on [Discord](https://discord.gg/yfjTbVXMW4).

### Feature list
## Feature list

- Full type safety
- [Smart automated migrations generation](https://github.com/drizzle-team/drizzle-kit-mirror)
Expand All @@ -25,27 +25,22 @@ Drizzle ORM is being battle-tested on production projects by multiple teams 🚀
- Auto-inferring of TS types for DB models for selections and insertions separately
- Zero dependencies

## Database support status

| Database | Support | |
|:------------|:-------:|:---|
| PostgreSQL | |[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-pg)|
| MySQL ||[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-mysql)|
| SQLite ||[Docs](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-sqlite)|
| PostgreSQL || [Docs](./drizzle-orm/src/pg-core/README.md)|
| MySQL ||[Docs](./drizzle-orm/src/mysql-core/README.md)|
| SQLite ||[Docs](./drizzle-orm/src/sqlite-core/README.md)|
| DynamoDB || |
| MS SQL || |
| CockroachDB || |

### Installation
## Installation

```bash
# postgresql
npm install drizzle-orm drizzle-orm-pg
npm install -D drizzle-kit

# mysql
npm install drizzle-orm drizzle-orm-mysql
npm install -D drizzle-kit

# sqlite
npm install drizzle-orm drizzle-orm-sqlite
npm install drizzle-orm
npm install -D drizzle-kit
```

See [dialect-specific docs](#database-support-status) for more details.
27 changes: 27 additions & 0 deletions changelogs/drizzle-orm/0.17.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# drizzle-orm 0.17.0

## ❗ All ORM packages are now merged into `drizzle-orm`

Starting from release `0.17.0` and onwards, all dialect-specific packages are merged into `drizzle-orm`. Legacy ORM packages will be archived.

### Import paths changes

#### PostgreSQL

- `import { ... } from 'drizzle-orm-pg'` -> `import { ... } from 'drizzle-orm/pg-core'`
- `import { ... } from 'drizzle-orm-pg/node'` -> `import { ... } from 'drizzle-orm/node-postgres'`
- `import { ... } from 'drizzle-orm-pg/neondb'` -> `import { ... } from 'drizzle-orm/neon'`
- `import { ... } from 'drizzle-orm-pg/postgres.js'` -> `import { ... } from 'drizzle-orm/postgres.js'`

#### MySQL

- `import { ... } from 'drizzle-orm-mysql'` -> `import { ... } from 'drizzle-orm/mysql-core'`
- `import { ... } from 'drizzle-orm-mysql/mysql2'` -> `import { ... } from 'drizzle-orm/mysql2'`

#### SQLite

- `import { ... } from 'drizzle-orm-sqlite'` -> `import { ... } from 'drizzle-orm/sqlite-core'`
- `import { ... } from 'drizzle-orm-sqlite/better-sqlite3'` -> `import { ... } from 'drizzle-orm/better-sqlite3'`
- `import { ... } from 'drizzle-orm-sqlite/d1'` -> `import { ... } from 'drizzle-orm/d1'`
- `import { ... } from 'drizzle-orm-sqlite/bun'` -> `import { ... } from 'drizzle-orm/bun-sqlite'`
- `import { ... } from 'drizzle-orm-sqlite/sql.js'` -> `import { ... } from 'drizzle-orm/sql.js'`
24 changes: 16 additions & 8 deletions docs/custom-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Each type creation should use 2 classes:
- Builder class is responsible for storing TS return type for specific database datatype and override build function to return ready to use column in table

- `TData` - extends return type for column. Current example will infer string type for current datatype used in schema definition

```typescript
export class PgTextBuilder<TData extends string = string>
extends PgColumnBuilder<
Expand All @@ -47,16 +48,18 @@ export class PgTextBuilder<TData extends string = string>
> `$pgColumnBuilderBrand` should be changed and be equal to class name for new data type builder
### Column class explanation - (postgresql text data type example)

---
Column class has set of types/functions, that could be overridden to get needed behavior for custom type

- `TData` - extends return type for column. Current example will infer string type for current datatype used in schema definition

- `getSQLType()` - function, that shows datatype name in database and will be used in migration generation
- `getSQLType()` - function, that shows datatype name in database and will be used in migration generation

- `mapFromDriverValue` - interceptor between database and select query execution. If you want to modify/map/change value for specific data type, it could be done here
- `mapFromDriverValue()` - interceptor between database and select query execution. If you want to modify/map/change value for specific data type, it could be done here

#### Usage example for jsonb type

#### Usage example for jsonb type:
```typescript
override mapToDriverValue(value: TData): string {
return JSON.stringify(value);
Expand All @@ -65,7 +68,8 @@ override mapToDriverValue(value: TData): string {

- `mapToDriverValue` - interceptor between user input for insert/update queries and database query. If you want to modify/map/change value for specific data type, it could be done here

#### Usage example for int type:
#### Usage example for int type

```typescript
override mapFromDriverValue(value: number | string): number {
if (typeof value === 'string') {
Expand All @@ -76,6 +80,7 @@ override mapFromDriverValue(value: number | string): number {
```

#### Column class example

```typescript
export class PgText<TTableName extends string, TData extends string>
extends PgColumn<ColumnConfig<{ tableName: TTableName; data: TData; driverParam: string }>> {
Expand Down Expand Up @@ -105,9 +110,9 @@ export class PgText<TTableName extends string, TData extends string>

</br>

### Full text data type for postgresql looks like:
### Full text data type for PostgreSQL example

For more postgres data type examples you could check [here](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-pg/src/columns)
For more postgres data type examples you could check [here](/drizzle-orm/src/pg-core/columns)

```typescript
import { ColumnConfig } from 'drizzle-orm';
Expand Down Expand Up @@ -166,12 +171,14 @@ export function text<T extends string = string>(
</br>

### Setting up CITEXT datatype

---
> **Note**
This type is available only with extensions and used for example, just to show how you could setup any data type you want. Extension support will come soon
This type is available only with extensions and used for example, just to show how you could setup any data type you want. Extension support will come soon
</br>

### CITEXT data type example

```typescript
export class PgCITextBuilder<TData extends string = string> extends PgColumnBuilder<
ColumnBuilderConfig<{ data: TData; driverParam: string }>
Expand Down Expand Up @@ -203,14 +210,15 @@ export function citext<T extends string = string>(name: string): PgCITextBuilder
```

#### Usage example

```typescript
const table = pgTable('table', {
id: integer('id').primaryKey(),
ciname: citext('ciname')
})
```

# Contributing by adding new custom types in Drizzle ORM
## Contributing by adding new custom types in Drizzle ORM

You could add your created custom data types to Drizzle ORM, so everyone can use it.

Expand Down
Loading

0 comments on commit 3753d10

Please sign in to comment.