-
-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3760 from drizzle-team/beta
Beta
- Loading branch information
Showing
17 changed files
with
1,397 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# New Features | ||
|
||
### `drizzle-kit export` | ||
|
||
To make drizzle-kit integration with other migration tools, like Atlas much easier, we've prepared a new command called `export`. It will translate your drizzle schema in SQL representation(DDL) statements and outputs to the console | ||
|
||
```ts | ||
// schema.ts | ||
import { pgTable, serial, text } from 'drizzle-orm/pg-core' | ||
|
||
export const users = pgTable('users', { | ||
id: serial('id').primaryKey(), | ||
email: text('email').notNull(), | ||
name: text('name') | ||
}); | ||
``` | ||
Running | ||
```bash | ||
npx drizzle-kit export | ||
``` | ||
|
||
will output this string to console | ||
```bash | ||
CREATE TABLE "users" ( | ||
"id" serial PRIMARY KEY NOT NULL, | ||
"email" text NOT NULL, | ||
"name" text | ||
); | ||
``` | ||
|
||
By default, the only option for now is `--sql`, so the output format will be SQL DDL statements. In the future, we will support additional output formats to accommodate more migration tools | ||
|
||
```bash | ||
npx drizzle-kit export --sql | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# New features | ||
|
||
## `USE INDEX`, `FORCE INDEX` and `IGNORE INDEX` for MySQL | ||
|
||
In MySQL, the statements USE INDEX, FORCE INDEX, and IGNORE INDEX are hints used in SQL queries to influence how the query optimizer selects indexes. These hints provide fine-grained control over index usage, helping optimize performance when the default behavior of the optimizer is not ideal. | ||
|
||
### Use Index | ||
|
||
The `USE INDEX` hint suggests to the optimizer which indexes to consider when processing the query. The optimizer is not forced to use these indexes but will prioritize them if they are suitable. | ||
|
||
```ts | ||
export const users = mysqlTable('users', { | ||
id: int('id').primaryKey(), | ||
name: varchar('name', { length: 100 }).notNull(), | ||
}, () => [usersTableNameIndex]); | ||
|
||
const usersTableNameIndex = index('users_name_index').on(users.name); | ||
|
||
await db.select() | ||
.from(users, { useIndex: usersTableNameIndex }) | ||
.where(eq(users.name, 'David')); | ||
``` | ||
|
||
### Ignore Index | ||
|
||
The `IGNORE INDEX` hint tells the optimizer to avoid using specific indexes for the query. MySQL will consider all other indexes (if any) or perform a full table scan if necessary. | ||
|
||
```ts | ||
export const users = mysqlTable('users', { | ||
id: int('id').primaryKey(), | ||
name: varchar('name', { length: 100 }).notNull(), | ||
}, () => [usersTableNameIndex]); | ||
|
||
const usersTableNameIndex = index('users_name_index').on(users.name); | ||
|
||
await db.select() | ||
.from(users, { ignoreIndex: usersTableNameIndex }) | ||
.where(eq(users.name, 'David')); | ||
``` | ||
|
||
### Force Index | ||
|
||
The `FORCE INDEX` hint forces the optimizer to use the specified index(es) for the query. If the specified index cannot be used, MySQL will not fall back to other indexes; it might resort to a full table scan instead. | ||
|
||
```ts copy | ||
export const users = mysqlTable('users', { | ||
id: int('id').primaryKey(), | ||
name: varchar('name', { length: 100 }).notNull(), | ||
}, () => [usersTableNameIndex]); | ||
|
||
const usersTableNameIndex = index('users_name_index').on(users.name); | ||
|
||
await db.select() | ||
.from(users, { forceIndex: usersTableNameIndex }) | ||
.where(eq(users.name, 'David')); | ||
``` | ||
|
||
You can also combine those hints and use multiple indexes in a query if you need |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.