diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3b7f8cbba..38b9f4642 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,169 +2,137 @@ Welcome! We're glad you're interested in Drizzle ORM and want to help us make it better. -Drizzle ORM is owned by [Drizzle Team](https://drizzle.team) and maintained by community members, mainly by our core contributors [@AndriiSherman](https://github.com/AndriiSherman) [@AlexBlokh](https://github.com/AlexBlokh) [@dankochetov](https://github.com/dankochetov). Everything that is going to be merged should be approved by all core contributors members +Drizzle ORM is owned by [Drizzle Team](https://drizzle.team) and maintained by community members, mainly by our core contributors ([@AndriiSherman](https://github.com/AndriiSherman), [@AlexBlokh](https://github.com/AlexBlokh), [@dankochetov](https://github.com/dankochetov)). Everything that is going to be merged should be approved by all core contributors members. --- -There are many ways you can contribute to the Drizzle ORM project +There are many ways you can contribute to the Drizzle ORM project: -- [Submitting bug reports](#bugreport) -- [Submitting feature request](#featurerequest) +- [Submitting bug reports](#bug-report) +- [Submitting feature request](#feature-request) - [Providing feedback](#feedback) -- [Contribution guidelines](#contributing) +- [Contribution guidelines](#contribution-guidelines) -## Submitting bug report +## Submitting bug report ---- - -To submit a bug or issue, please use our [issue form](https://github.com/drizzle-team/drizzle-orm/issues/new/choose) and choose Bug Report +To report a bug or issue, please use our [issue form](https://github.com/drizzle-team/drizzle-orm/issues/new/choose) and choose Bug Report. -## Submitting feature request +## Submitting feature request ---- - -To submit a bug or issue, please use our [issue form](https://github.com/drizzle-team/drizzle-orm/issues/new/choose) and choose Feature Request +To request a feature, please use our [issue form](https://github.com/drizzle-team/drizzle-orm/issues/new/choose) and choose Feature Request. ## Providing feedback ---- +There are several ways you can provide feedback: -There are several ways how you can provide a feedback +- You can join our [Discord server](https://discord.gg/yfjTbVXMW4) and provide feedback there. +- You can add new ticket in [Discussions](https://github.com/drizzle-team/drizzle-orm/discussions). +- Mention our [Twitter account](https://twitter.com/DrizzleOrm). -- You can join our [Discord](https://discord.gg/yfjTbVXMW4) channel and provide feedback there -- You can add new ticket in [Discussions](https://github.com/drizzle-team/drizzle-orm/discussions) -- Mention our [Twitter account](https://twitter.com/DrizzleOrm) +## Contribution guidelines -## Contribution guidelines - ---- - -- [Pre-Contribution setup](#pre-contribution) - - [Installing node](#-installing-node) - - [Install pnpm](#-install-pnpm) - - [Install docker](#-install-docker) - - [Clone project](#-clone-project) - - [Repository Structure](#repo-structure) - - [Build project](#-build-project) +- [Pre-contribution setup](#pre-contribution) + - [Installing Node](#installing-node) + - [Installing pnpm](#installing-pnpm) + - [Installing Docker](#installing-docker) + - [Cloning the repository](#cloning-the-repository) + - [Repository structure](#repository-structure) + - [Building the project](#building-the-project) +- [Commit message guidelines](#commit-message-guidelines) - [Contributing to `drizzle-orm`](#contributing-orm) - [Project structure](#project-structure-orm) - - [Run tests](#run-tests-orm) - - [Commits and PRs](#commits-and-prs-orm) - - [Commit guideline](#commit-guideline-orm) - - [PR guideline](#pr-guideline-orm) + - [Running tests](#running-tests-orm) + - [PR guidelines](#pr-guidelines-orm) - [Contributing to `drizzle-kit`](#contributing-kit) - [Project structure](#project-structure-kit) - - [Run tests](#run-tests-kit) - - [Commits and PRs](#commits-and-prs-kit) - - [Commit guideline](#commit-guideline-kit) - - [PR guideline](#-pr-guideline) - -## Pre-Contribution setup + - [Running tests](#running-tests-kit) + - [PR guidelines](#pr-guidelines-kit) -### Installing node +## Pre-contribution setup ---- +### Installing Node ```bash # https://github.com/nvm-sh/nvm#install--update-script -curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash nvm install 18.13.0 nvm use 18.13.0 ``` -### Install pnpm - ---- +### Installing pnpm ```bash # https://pnpm.io/installation npm install -g pnpm ``` -### Install docker - ---- +### Installing Docker ```bash # https://docs.docker.com/get-docker/ -Use docker guide to install docker on your OS +# Use Docker's guide to install Docker for your OS. ``` -## Local project setup - -### Clone project - ---- +### Cloning the repository ```bash git clone https://github.com/drizzle-team/drizzle-orm.git cd drizzle-orm ``` -### Repository Structure - -``` -📂 drizzle-orm/ - orm core package with all main logic for each dialect - -📂 drizzle-kit/ - kit core package with all main logic and tests for each dialect +### Repository structure -📂 drizzle-typebox/ - all the code related to drizzle+typebox extension +- 📂 `drizzle-orm/` -📂 drizzle-valibot/ - all the code related to drizzle+valibot extension + orm core package with all main logic for each dialect -📂 drizzle-zod/ - all the code related to drizzle+zod extension +- 📂 `drizzle-kit/` -📂 eslint-plugin-drizzle/ - all the code related to drizzle eslint plugin + kit core package with all main logic and tests for each dialect -📂 changelogs/ - all changelogs for drizzle-orm, drizzle-kit, drizzle-typebox, drizzle-zod, drizzle-valibot modules +- 📂 `drizzle-typebox/` -📂 examples/ - package with Drizzle ORM usage examples + all the code related to drizzle+typebox extension -📂 integration-tests/ - package with all type of tests for each supported database -``` +- 📂 `drizzle-valibot/` -### Build project + all the code related to drizzle+valibot extension ---- +- 📂 `drizzle-zod/` -- `"pnpm i && pnpm build"` -> if you run this script from root folder - it will build whole monorepo. Running this script from specific package folder will only build current package + all the code related to drizzle+zod extension -## Contributing to `drizzle-orm` - -### Project structure - -``` -Project structure +- 📂 `eslint-plugin-drizzle/` -📂 pg-core, mysql-core, sqlite-core - core packages for each dialect with all the main logic for relation and query builder + all the code related to drizzle eslint plugin -📂 sql/ - package containing all expressions and SQL template implementation +- 📂 `changelogs/` -All other folders are for specific drivers that Drizzle ORM supports. -``` + all changelogs for drizzle-orm, drizzle-kit, drizzle-typebox, drizzle-zod, drizzle-valibot modules -### Run tests +- 📂 `examples/` ---- -All tests for Drizzle ORM are integration tests, that are simulating real database and different queries and responses from database. Each file in `integration-tests` has a list of different scenarios for different dialect+driver. Each file is creating a docker instance with needed database and running test cases there. Right after all tests were run - docker container with database will be deleted + package with Drizzle ORM usage examples -If you have added additional logic to core package - make sure that all tests were executed without any errors +- 📂 `integration-tests/` -> If you have added data types or feature for query building, you need to create additional test cases with this data type/syntax changes, syntax addition + package with all type of tests for each supported database -- `"cd integration-tests && pnpm test"` -> will run all tests in integration test folder +### Building the project -## Commits and PRs +Run the following script from the root folder to build the whole monorepo. Running it from a specific package folder will only build that package. -### Commit guideline +```bash +pnpm install && pnpm build +``` ---- +## Commit message guidelines We have specific rules on how commit messages should be structured. -It's important to make sure your commit messages are clear, concise, and informative to make it easier for others to understand the changes you are making +It's important to make sure your commit messages are clear, concise, and informative to make it easier for others to understand the changes you are making. -Commit message pattern +All commit messages should follow the pattern below: ``` @@ -172,7 +140,7 @@ Commit message pattern ``` -Example +Example: ``` Add groupBy error message @@ -181,117 +149,131 @@ In specific case, groupBy was responding with unreadable error ... ``` -> **Warning**: -> All commits should be signed, before submitting PR. Please check detailed info on [how to sign commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) +> [!WARNING] +> All commits should be signed before submitting a PR. Please check the documentation on [how to sign commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification). -### PR guideline +## Contributing to `drizzle-orm` ---- +### Project structure -1. PR should be created with specific name pattern +- 📂 `pg-core/`, `mysql-core/`, `sqlite-core/` + + core packages for each dialect with all the main logic for relation and query builder -``` -[Dialect name]: -``` +- 📂 `sql/` -Example + package containing all expressions and SQL template implementation -``` -[Pg] Add PostGIS extension support +- All other folders are for each specific driver that Drizzle ORM supports. + +### Running tests + +All tests for Drizzle ORM are integration tests that simulate real databases with different queries and responses from each database. Each file in `integration-tests` has a list of different scenarios for different dialects and drivers. Each file creates a Docker container with the needed database and runs the test cases there. After every test is run, the Docker container will be deleted. + +If you have added additional logic to a core package, make sure that all tests completed without any failures. + +> [!NOTE] +> If you have added data types or a feature for query building, you need to create additional test cases using the new API to ensure it works properly. + +If you are in the root of the repository, run all integration tests with the following script: + +```bash +cd integration-tests && pnpm test ``` -2. PR should contain detailed description with everything, that was changed +### PR guidelines -3. Each PR should contain - - Tests on feature, that was created; - - Tests on bugs, that was fixed; +1. PR titles should follow the pattern below: -To understand how test should be created and run - please check [Run tests](#-run-tests) section + ``` + []: + ``` + Example: + + ``` + [Pg] Add PostGIS extension support + ``` + +2. PRs should contain a detailed description of everything that was changed. + +3. Commit messages should follow the [message style guidelines](#commit-message-guidelines). + +4. PRs should implement: + - Tests for features that were added. + - Tests for bugs that were fixed. + +> [!NOTE] +> To understand how tests should be created and run, please check the [Running tests](#running-tests-orm) section. ## Contributing to `drizzle-kit` ### Project structure -``` -📂 cli/ - | - | -> 📄 schema.ts - all the commands defined using brocli - | - | -> 📂 commands - all the business logic for drizzle-kit commands - -📂 extensions/ - all the extension helpers for databases +- 📂 `cli/` + - 📄 `schema.ts` -📂 serializer/ - all the necessary logic to read from the Drizzle ORM schema and convert it to a common JSON format, as well as the logic to introspect all tables, types, and other database elements and convert them to a common JSON format + all the commands defined using brocli -📄 introspect-pg.ts, introspect-mysql.ts, introspect-sqlite.ts - these files are responsible for mapping JSON snapshots to TypeScript files during introspect commands + - 📂 `commands/` -📄 snapshotsDiffer.ts - this file handles the mapping from JSON snapshot format to JSON statement objects. + all the business logic for drizzle-kit commands -📄 jsonStatements.ts - this file defines JSON statement types, interfaces, and helper functions. +- 📂 `extensions/` -📄 sqlgenerator.ts - this file converts JSON statements to SQL strings. -``` + all the extension helpers for databases -### Run tests +- 📂 `serializer/` ---- -All tests for Drizzle Kit are integration tests, that are simulating real database and different queries and responses from database. Each file in `drizzle-kit/tests` has a list of different scenarios for different commands. Each MySQL file is creating a docker instance with needed database and running test cases there. Right after all tests were run - docker container with database will be deleted. For PostgreSQL we are using PgLite and for SQLite we are using SQLite files. + all the necessary logic to read from the Drizzle ORM schema and convert it to a common JSON format, as well as the logic to introspect all tables, types, and other database elements and convert them to a common JSON format -If you are in the root of repo: +- 📄 `introspect-pg.ts`, `introspect-mysql.ts`, `introspect-sqlite.ts` -- `"cd drizzle-kit && pnpm test"` -> will run all tests + these files are responsible for mapping JSON snapshots to TypeScript files during introspect commands -## Commits and PRs +- 📄 `snapshotsDiffer.ts` -### Commit guideline + this file handles the mapping from JSON snapshot format to JSON statement objects. ---- +- 📄 `jsonStatements.ts` -We have specific rules on how commit messages should be structured. + this file defines JSON statement types, interfaces, and helper functions. -It's important to make sure your commit messages are clear, concise, and informative to make it easier for others to understand the changes you are making +- 📄 `sqlgenerator.ts` -Commit message pattern + this file converts JSON statements to SQL strings. -``` - - - -``` +### Running tests -Example +All tests for Drizzle Kit are integration tests that simulate real databases with different queries and responses from each database. Each file in `drizzle-kit/tests` has a list of different scenarios for different commands. Each file creates a Docker container with the needed database and runs the test cases there. After every test is run, the Docker container will be deleted. We test MySQL, PostgreSQL (using PGlite), and SQLite. -``` -Add groupBy error message +If you are in the root of the repository, run all Drizzle Kit tests with the following script: -In specific case, groupBy was responding with unreadable error -... +```bash +cd drizzle-kit && pnpm test ``` -> **Warning**: -> All commits should be signed, before submitting PR. Please check detailed info on [how to sign commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) +### PR guidelines -### PR guideline +1. PR titles should follow the pattern below: ---- + ``` + [-kit]: + ``` -1. PR should be created with specific name pattern + Example: -``` -[-kit]: -``` - -Example + ``` + [Pg-kit] Add PostGIS extension support + ``` -``` -[Pg-kit] Add PostGIS extension support -``` +2. PRs should contain a detailed description of everything that was changed. -2. PR should contain detailed description with everything, that was changed +3. Commit messages should follow the [message style guidelines](#commit-message-guidelines). -3. Each PR should contain - - Tests on feature, that was created; - - Tests on bugs, that was fixed; +4. PRs should implement: + - Tests for features that were added. + - Tests for bugs that were fixed. -To understand how test should be created and run - please check [Run tests](#run-tests) section +> [!NOTE] +> To understand how tests should be created and run, please check the [Running tests](#running-tests-kit) section. diff --git a/README.md b/README.md index ac509ab0d..4342d8afe 100644 --- a/README.md +++ b/README.md @@ -17,24 +17,24 @@ ### What's Drizzle? Drizzle is a modern TypeScript ORM developers [wanna use in their next project](https://stateofdb.com/tools/drizzle). -It is [lightweight](https://bundlephobia.com/package/drizzle-orm) at only ~7.4kb minified+gzipped, it's tree shakeable with exactly 0 dependencies. +It is [lightweight](https://bundlephobia.com/package/drizzle-orm) at only ~7.4kb minified+gzipped, and it's tree shakeable with exactly 0 dependencies. -**Drizzle supports every PostgreSQL, MySQL and SQLite databases**, including serverless ones like [Turso](https://orm.drizzle.team/docs/get-started-sqlite#turso), [Neon](https://orm.drizzle.team/docs/get-started-postgresql#neon), [Xata](xata.io), [PlanetScale](https://orm.drizzle.team/docs/get-started-mysql#planetscale), [Cloudflare D1](https://orm.drizzle.team/docs/get-started-sqlite#cloudflare-d1), [FlyIO LiteFS](https://fly.io/docs/litefs/), [Vercel Postgres](https://orm.drizzle.team/docs/get-started-postgresql#vercel-postgres), [Supabase](https://orm.drizzle.team/docs/get-started-postgresql#supabase) and [AWS Data API](https://orm.drizzle.team/docs/get-started-postgresql#aws-data-api). No bells and whistles, no rust binaries, no serverless adapters, everything just works out of the box. +**Drizzle supports every PostgreSQL, MySQL and SQLite database**, including serverless ones like [Turso](https://orm.drizzle.team/docs/get-started-sqlite#turso), [Neon](https://orm.drizzle.team/docs/get-started-postgresql#neon), [Xata](xata.io), [PlanetScale](https://orm.drizzle.team/docs/get-started-mysql#planetscale), [Cloudflare D1](https://orm.drizzle.team/docs/get-started-sqlite#cloudflare-d1), [FlyIO LiteFS](https://fly.io/docs/litefs/), [Vercel Postgres](https://orm.drizzle.team/docs/get-started-postgresql#vercel-postgres), [Supabase](https://orm.drizzle.team/docs/get-started-postgresql#supabase) and [AWS Data API](https://orm.drizzle.team/docs/get-started-postgresql#aws-data-api). No bells and whistles, no Rust binaries, no serverless adapters, everything just works out of the box. -**Drizzle is serverless-ready by design**, it works in every major JavaScript runtime like NodeJS, Bun, Deno, Cloudflare Workers, Supabase functions, any Edge runtime and even in Browsers. -With Drizzle you can be [**fast out of the box**](https://orm.drizzle.team/benchmarks), save time and costs while never introducing any data proxies into your infrastructure. +**Drizzle is serverless-ready by design**. It works in every major JavaScript runtime like NodeJS, Bun, Deno, Cloudflare Workers, Supabase functions, any Edge runtime, and even in browsers. +With Drizzle you can be [**fast out of the box**](https://orm.drizzle.team/benchmarks) and save time and costs while never introducing any data proxies into your infrastructure. -While you can use Drizzle as a JavaScript library, it shines in the TypeScript. It lets you [**declare SQL schema**](https://orm.drizzle.team/docs/sql-schema-declaration) and build both [**relational**](https://orm.drizzle.team/docs/rqb) and [**SQL-like queries**](https://orm.drizzle.team/docs/select), while keeping the balance between type-safety and extensibility for toolmakers to build on top. +While you can use Drizzle as a JavaScript library, it shines with TypeScript. It lets you [**declare SQL schemas**](https://orm.drizzle.team/docs/sql-schema-declaration) and build both [**relational**](https://orm.drizzle.team/docs/rqb) and [**SQL-like queries**](https://orm.drizzle.team/docs/select), while keeping the balance between type-safety and extensibility for toolmakers to build on top. ### Ecosystem While Drizzle ORM remains a thin typed layer on top of SQL, we made a set of tools for people to have best possible developer experience. -Drizzle comes with a powerful [**Drizzle Kit**](https://orm.drizzle.team/kit-docs/overview) CLI companion for you to have hasstle-free migrations. It can generate SQL migration files for you or apply schema changes directly to the database. +Drizzle comes with a powerful [**Drizzle Kit**](https://orm.drizzle.team/kit-docs/overview) CLI companion for you to have hassle-free migrations. It can generate SQL migration files for you or apply schema changes directly to the database. -And we have a [**Drizzle Studio**](https://orm.drizzle.team/drizzle-studio/overview) for you to effortlessly browse and manipulate data in your database of choice. +We also have [**Drizzle Studio**](https://orm.drizzle.team/drizzle-studio/overview) for you to effortlessly browse and manipulate data in your database of choice. ### Documentation -Check out the full documentation on [the website](https://orm.drizzle.team/docs/overview) +Check out the full documentation on [the website](https://orm.drizzle.team/docs/overview). ### Our sponsors ❤️

diff --git a/docs/custom-types.lite.md b/docs/custom-types.lite.md index 627aba1a4..af1371461 100644 --- a/docs/custom-types.lite.md +++ b/docs/custom-types.lite.md @@ -1,6 +1,7 @@ # Common way of defining custom types -> **Info**: For more advanced documentation about defining custom data types in PostgreSQL and MySQL please check [custom-types.md](https://github.com/drizzle-team/drizzle-orm/blob/main/docs/custom-types.md) +> [!NOTE] +> For more advanced documentation about defining custom data types in PostgreSQL and MySQL, please check [`custom-types.md`](custom-types.md). ## Examples diff --git a/docs/custom-types.md b/docs/custom-types.md index 1dffe6ce0..2a9f1a1da 100644 --- a/docs/custom-types.md +++ b/docs/custom-types.md @@ -1,7 +1,6 @@ # How to define custom types Drizzle ORM has a big set of predefined column types for different SQL databases. But still there are additional types that are not supported by Drizzle ORM (yet). That could be native pg types or extension types -
Here are some instructions on how to create and use your own types with Drizzle ORM @@ -13,14 +12,11 @@ Each type creation should use 2 classes: - `ColumnBuilder` - class, that is responsible for generating whole set of needed fields for column creation - `Column` - class, that is representing Columns itself, that is used in query generation, migration mapping, etc. -
-
+ Each module has it's own class, representing `ColumnBuilder` or `Column`: - For `pg` -> `PgColumnBuilder` and `PgColumn` - For `mysql` -> `MySqlColumnBuilder` and `MySqlColumn` - For `sqlite` -> `SQLiteColumnBuilder` and `SQLiteColumn` -
-
### Builder class explanation - (postgresql text data type example) @@ -44,7 +40,7 @@ export class PgTextBuilder } ``` -> **Warning** +> [!WARNING] > `$pgColumnBuilderBrand` should be changed and be equal to class name for new data type builder ### Column class explanation - (postgresql text data type example) @@ -104,11 +100,8 @@ export class PgText } ``` -> **Warning** +> [!WARNING] > `$pgColumnBrand` should be changed and be equal to class name for new data type ---- - -
### Full text data type for PostgreSQL example @@ -162,19 +155,13 @@ export function text( ## Custom data type example ---- - -> **Note** +> [!NOTE] > We will check example on pg module, but current pattern applies to all dialects, that are currently supported by Drizzle ORM -
- ### 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 -
+> [!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 ### CITEXT data type example @@ -224,4 +211,4 @@ You could add your created custom data types to Drizzle ORM, so everyone can use Each data type should be placed in separate file in `columns` folder and PR open with tag `new-data-type:pg` | `new-data-type:sqlite` | `new-data-type:mysql` -For more Contribution information - please check [CONTRIBUTING.md](https://github.com/drizzle-team/drizzle-orm/blob/main/CONTRIBUTING.md) +For more Contribution information - please check [CONTRIBUTING.md](../CONTRIBUTING.md) diff --git a/docs/joins.md b/docs/joins.md index e0579e3e2..2b5829aa9 100644 --- a/docs/joins.md +++ b/docs/joins.md @@ -1,7 +1,7 @@ # Drizzle ORM - Joins As with other parts of Drizzle ORM, the joins syntax is a balance between the SQL-likeness and type safety. -Here's an example of how a common `1-to-many` relationship can be modelled. +Here's an example of how a common "one-to-many" relationship can be modelled. ```typescript const users = pgTable('users', { @@ -96,7 +96,7 @@ In that case, the ORM will use dark TypeScript magic (as if it wasn't already) a This is much more convenient! Now, you can just do a single check for `row.user !== null`, and all the user fields will become available. -


+--- Note that you can group any fields in a nested object however you like, but the single check optimization will only be applied to a certain nested object if all its fields belong to the same table. So, for example, you can group the city fields, too: @@ -131,7 +131,7 @@ And the result type will look like this: } ``` -
+--- If you just need all the fields from all the tables you're selecting and joining, you can simply omit the argument of the `.select()` method altogether: @@ -139,7 +139,8 @@ If you just need all the fields from all the tables you're selecting and joining const rows = await db.select().from(cities).leftJoin(users, eq(users.cityId, cities.id)); ``` -> **Note**: in this case, the Drizzle table/column names will be used as the keys in the result object. +> [!NOTE] +> In this case, the Drizzle table/column names will be used as the keys in the result object. ```typescript { @@ -156,7 +157,7 @@ const rows = await db.select().from(cities).leftJoin(users, eq(users.cityId, cit }[] ``` -
+--- There are cases where you'd want to select all the fields from one table, but pick fields from others. In that case, instead of listing all the table fields, you can just pass a table: @@ -181,7 +182,7 @@ There are cases where you'd want to select all the fields from one table, but pi } ``` -
+--- But what happens if you group columns from multiple tables in the same nested object? Nothing, really - they will still be all individually nullable, just grouped under the same object (as you might expect!): diff --git a/drizzle-kit/README.md b/drizzle-kit/README.md index d2a4191b7..bd69a4d3d 100644 --- a/drizzle-kit/README.md +++ b/drizzle-kit/README.md @@ -1,21 +1,21 @@ ## Drizzle Kit -DrizzleKit - is a CLI migrator tool for DrizzleORM. It is probably one and only tool that lets you completely automatically generate SQL migrations and covers ~95% of the common cases like deletions and renames by prompting user input. +Drizzle Kit is a CLI migrator tool for Drizzle ORM. It is probably the one and only tool that lets you completely automatically generate SQL migrations and covers ~95% of the common cases like deletions and renames by prompting user input. - is a mirror repository for issues. ## Documentation -Check the full documenation on [the website](https://orm.drizzle.team/kit-docs/overview) +Check the full documentation on [the website](https://orm.drizzle.team/kit-docs/overview). ### How it works -`drizzle-kit` will traverse `schema folder` or `schema file`, generate schema snapshot and compare it to the previous version, if there's one. - Based on the difference it will generate all needed SQL migrations and if there are any `automatically unresolvable` cases like `renames` it will prompt user for input. +Drizzle Kit traverses a schema module and generates a snapshot to compare with the previous version, if there is one. +Based on the difference, it will generate all needed SQL migrations. If there are any cases that can't be resolved automatically, such as renames, it will prompt the user for input. -For schema file: +For example, for this schema module: ```typescript -// ./src/db/schema.ts +// src/db/schema.ts import { integer, pgTable, serial, text, varchar } from "drizzle-orm/pg-core"; @@ -63,7 +63,7 @@ CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name); npm install -D drizzle-kit ``` -Running with CLI options +Running with CLI options: ```jsonc // package.json diff --git a/drizzle-orm/src/sqlite-core/README.md b/drizzle-orm/src/sqlite-core/README.md index 6d4ebd8b6..ae5fbe660 100644 --- a/drizzle-orm/src/sqlite-core/README.md +++ b/drizzle-orm/src/sqlite-core/README.md @@ -8,7 +8,7 @@
-DrizzleORM is a [tiny](https://twitter.com/_alexblokh/status/1594735880417472512), [blazingly fast](#️-performance-and-prepared-statements) TypeScript ORM library with a [drizzle-kit](#-migrations) CLI companion for automatic SQL migrations generation. +Drizzle ORM is a [tiny](https://twitter.com/_alexblokh/status/1594735880417472512), [blazingly fast](#️-performance-and-prepared-statements) TypeScript ORM library with a [drizzle-kit](#-migrations) CLI companion for automatic SQL migrations generation. Here you can find extensive docs for SQLite module. | Driver | Support | | @@ -365,7 +365,8 @@ const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42))); const result = db.with(sq).select().from(sq).all(); ``` -> **Note**: Keep in mind that if you need to select raw `sql` in a WITH subquery and reference that field in other queries, you must add an alias to it: +> [!NOTE] +> Keep in mind that if you need to select raw `sql` in a WITH subquery and reference that field in other queries, you must add an alias to it: ```typescript const sq = db.$with('sq').as(db.select({ name: sql`upper(${users.name})`.as('name') }).from(users)); @@ -582,7 +583,8 @@ db ### Joins -> **Note**: for in-depth partial select joins documentation, refer to [this page](/docs/joins.md). +> [!NOTE] +> For in-depth partial select joins documentation, refer to [this page](/docs/joins.md). ### Many-to-one @@ -721,7 +723,8 @@ const { sql, params } = query.toSQL(); ## Views (WIP) -> **Warning**: views are currently only implemented on the ORM side. That means you can query the views that already exist in the database, but they won't be added to drizzle-kit migrations or `db push` yet. +> [!WARNING] +> views are currently only implemented on the ORM side. That means you can query the views that already exist in the database, but they won't be added to drizzle-kit migrations or `db push` yet. ### Creating a view @@ -731,7 +734,8 @@ import { sqliteView } from 'drizzle-orm/sqlite-core'; const newYorkers = sqliteView('new_yorkers').as((qb) => qb.select().from(users).where(eq(users.cityId, 1))); ``` -> **Warning**: All the parameters inside the query will be inlined, instead of replaced by `$1`, `$2`, etc. +> [!WARNING] +> All the parameters inside the query will be inlined, instead of replaced by `$1`, `$2`, etc. You can also use the [`queryBuilder` instance](#query-builder) directly instead of passing a callback, if you already have it imported. @@ -794,8 +798,8 @@ q.all({ name: '%an%' }) // SELECT * FROM customers WHERE name ilike '%an%' ### Automatic SQL migrations generation with drizzle-kit -[Drizzle Kit](https://www.npmjs.com/package/drizzle-kit) is a CLI migrator tool for Drizzle ORM. It is probably one and only tool that lets you completely automatically generate SQL migrations and covers ~95% of the common cases like deletions and renames by prompting user input. -Check out the [docs for Drizzle Kit](https://github.com/drizzle-team/drizzle-kit-mirror) +[Drizzle Kit](https://www.npmjs.com/package/drizzle-kit) is a CLI migrator tool for Drizzle ORM. It is probably the one and only tool that lets you completely automatically generate SQL migrations and covers ~95% of the common cases like deletions and renames by prompting user input. +Check out the [docs for Drizzle Kit](https://github.com/drizzle-team/drizzle-kit-mirror). For schema file: diff --git a/examples/mysql-proxy/README.md b/examples/mysql-proxy/README.md index 8bbdf3f7b..fadc843d3 100644 --- a/examples/mysql-proxy/README.md +++ b/examples/mysql-proxy/README.md @@ -30,7 +30,7 @@ This project has simple example of defining http proxy server, that will proxy a
-> **Warning**: +> [!WARNING] > You will be responsible for proper error handling in this part. Drizzle always waits for `{rows: string[][] | object[]}` so if any error was on http call(or any other call) - be sure, that you return at least empty array back > > For `all` method you should return `{rows: string[][]}` @@ -72,7 +72,7 @@ In current MySQL Proxy version - drizzle don't handle transactions for migration
-> **Warning**: +> [!WARNING] > You will be responsible for proper error handling in this part. Drizzle just finds migrations, that need to be executed on this iteration and if finds some -> provide `queries` array to callback
@@ -97,7 +97,7 @@ await migrate(db, async (queries) => { --- -> **Note**: +> [!WARNING] > It's just a suggestion on how proxy server could be set up and a simple example of params handling on `query` and `migration` calls ```typescript diff --git a/examples/neon-cloudflare/readme.md b/examples/neon-cloudflare/readme.md index 0585ccecc..f69581b21 100644 --- a/examples/neon-cloudflare/readme.md +++ b/examples/neon-cloudflare/readme.md @@ -1,4 +1,4 @@ -### Example project for [DrizzleORM](https://driz.li/orm) + [Cloudflare Worker](https://workers.cloudflare.com) + [Neon Serverless](https://github.com/neondatabase/serverless) +### Example project for [Drizzle ORM](https://driz.li/orm) + [Cloudflare Worker](https://workers.cloudflare.com) + [Neon Serverless](https://github.com/neondatabase/serverless) --- diff --git a/examples/pg-proxy/README.md b/examples/pg-proxy/README.md index d9ff24fb1..b47fcd5e3 100644 --- a/examples/pg-proxy/README.md +++ b/examples/pg-proxy/README.md @@ -30,7 +30,7 @@ This project has simple example of defining http proxy server, that will proxy a
-> **Warning**: +> [!WARNING] > You will be responsible for proper error handling in this part. Drizzle always waits for `{rows: string[][] | object[]}` so if any error was on http call(or any other call) - be sure, that you return at least empty array back > > For `all` method you should return `{rows: string[][]}` @@ -72,7 +72,7 @@ In current Postgres Proxy version - drizzle don't handle transactions for migrat
-> **Warning**: +> [!WARNING] > You will be responsible for proper error handling in this part. Drizzle just finds migrations, that need to be executed on this iteration and if finds some -> provide `queries` array to callback
@@ -97,7 +97,7 @@ await migrate(db, async (queries) => { --- -> **Note**: +> [!NOTE] > It's just a suggestion on how proxy server could be set up and a simple example of params handling on `query` and `migration` calls ```typescript diff --git a/examples/sqlite-proxy/README.md b/examples/sqlite-proxy/README.md index b187e35fb..d25cd7d8b 100644 --- a/examples/sqlite-proxy/README.md +++ b/examples/sqlite-proxy/README.md @@ -30,7 +30,7 @@ This project has simple example of defining http proxy server, that will proxy a
-> **Warning**: +> [!WARNING] > You will be responsible for proper error handling in this part. Drizzle always waits for `{rows: string[][]}` so if any error was on http call(or any other call) - be sure, that you return at least empty array back > > For `get` method you should return `{rows: string[]}` @@ -71,7 +71,7 @@ In current SQLite Proxy version - drizzle don't handle transactions for migratio
-> **Warning**: +> [!WARNING] > You will be responsible for proper error handling in this part. Drizzle just finds migrations, that need to be executed on this iteration and if finds some -> provide `queries` array to callback
@@ -96,7 +96,7 @@ await migrate(db, async (queries) => { --- -> **Note**: +> [!NOTE] > It's just a suggestion on how proxy server could be set up and a simple example of params handling on `query` and `migration` calls ```typescript