forked from drizzle-team/drizzle-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'beta' into singlestore-blob-new-column-type
- Loading branch information
Showing
128 changed files
with
10,227 additions
and
2,132 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
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 @@ | ||
- Closed [[FEATURE]: Add more flexible typing for usage with exactOptionalPropertyTypes](https://github.com/drizzle-team/drizzle-orm/issues/2742) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Fix incorrect deprecation detection for table declarations |
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,131 @@ | ||
## Bug fixes | ||
|
||
- https://github.com/drizzle-team/drizzle-orm/issues/3644 | ||
- seeding a table with columns that have .default(sql``) will result in an error | ||
|
||
## Features | ||
|
||
- added support for postgres uuid columns | ||
|
||
Example | ||
|
||
```ts | ||
import { pgTable, uuid } from "drizzle-orm/pg-core"; | ||
import { drizzle } from "drizzle-orm/node-postgres"; | ||
import { seed } from "drizzle-seed"; | ||
|
||
const users = pgTable("users", { | ||
uuid: uuid("uuid"), | ||
}); | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
// You can let it seed automatically | ||
// await seed(db, { users }); | ||
|
||
// Alternatively, you can manually specify the generator in refine. | ||
await seed(db, { users }, { count: 1000 }).refine((funcs) => ({ | ||
users: { | ||
columns: { | ||
uuid: funcs.uuid(), | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
## | ||
|
||
- added support for postgres array columns | ||
|
||
Example | ||
|
||
```ts | ||
import { pgTable, integer, text, varchar } from "drizzle-orm/pg-core"; | ||
import { drizzle } from "drizzle-orm/node-postgres"; | ||
import { seed } from "drizzle-seed"; | ||
|
||
const users = pgTable("users", { | ||
id: integer().primaryKey(), | ||
name: text().notNull(), | ||
phone_numbers: varchar({ length: 256 }).array(), | ||
}); | ||
``` | ||
|
||
You can specify the `arraySize` parameter in generator options, like `funcs.phoneNumber({ arraySize: 3 })`, to generate 1D arrays. | ||
|
||
```ts | ||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { users }, { count: 1000 }).refine((funcs) => ({ | ||
users: { | ||
columns: { | ||
phone_numbers: funcs.phoneNumber({ arraySize: 3 }), | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
Alternatively, you can let it seed automatically, and it will handle arrays of any dimension. | ||
|
||
```ts | ||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { users }); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
## | ||
|
||
- added support for cyclic tables | ||
|
||
You can now seed tables with cyclic relations. | ||
|
||
```ts | ||
import type { AnyPgColumn } from "drizzle-orm/pg-core"; | ||
import { | ||
foreignKey, | ||
integer, | ||
pgTable, | ||
serial, | ||
varchar, | ||
} from "drizzle-orm/pg-core"; | ||
|
||
export const modelTable = pgTable( | ||
"model", | ||
{ | ||
id: serial().primaryKey(), | ||
name: varchar().notNull(), | ||
defaultImageId: integer(), | ||
}, | ||
(t) => [ | ||
foreignKey({ | ||
columns: [t.defaultImageId], | ||
foreignColumns: [modelImageTable.id], | ||
}), | ||
] | ||
); | ||
|
||
export const modelImageTable = pgTable("model_image", { | ||
id: serial().primaryKey(), | ||
url: varchar().notNull(), | ||
caption: varchar(), | ||
modelId: integer() | ||
.notNull() | ||
.references((): AnyPgColumn => modelTable.id), | ||
}); | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { modelTable, modelImageTable }); | ||
} | ||
|
||
main(); | ||
``` |
Oops, something went wrong.