-
-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
115 changed files
with
146,793 additions
and
750 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
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 |
---|---|---|
|
@@ -12,3 +12,5 @@ dist-dts | |
rollup.config-*.mjs | ||
*.log | ||
.DS_Store | ||
drizzle-seed/src/test.ts | ||
drizzle-seed/src/schemaTest.ts |
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,84 @@ | ||
# New Package: `drizzle-seed` | ||
|
||
> [!NOTE] | ||
> `drizzle-seed` can only be used with `[email protected]` or higher. Versions lower than this may work at runtime but could have type issues and identity column issues, as this patch was introduced in `[email protected]` | ||
## Full Reference | ||
|
||
The full API reference and package overview can be found in our [official documentation](https://orm.drizzle.team/docs/seed-overview) | ||
|
||
## Basic Usage | ||
|
||
In this example we will create 10 users with random names and ids | ||
|
||
```ts {12} | ||
import { pgTable, integer, text } 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(), | ||
}); | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { users }); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
## Options | ||
|
||
**`count`** | ||
|
||
By default, the `seed` function will create 10 entities. | ||
However, if you need more for your tests, you can specify this in the seed options object | ||
|
||
```ts | ||
await seed(db, schema, { count: 1000 }); | ||
``` | ||
|
||
**`seed`** | ||
|
||
If you need a seed to generate a different set of values for all subsequent runs, you can define a different number | ||
in the `seed` option. Any new number will generate a unique set of values | ||
|
||
```ts | ||
await seed(db, schema, { seed: 12345 }); | ||
``` | ||
|
||
The full API reference and package overview can be found in our [official documentation](https://orm.drizzle.team/docs/seed-overview) | ||
|
||
# Features | ||
|
||
## Added `OVERRIDING SYSTEM VALUE` api to db.insert() | ||
|
||
If you want to force you own values for `GENERATED ALWAYS AS IDENTITY` columns, you can use `OVERRIDING SYSTEM VALUE` | ||
|
||
As PostgreSQL docs mentions | ||
> In an INSERT command, if ALWAYS is selected, a user-specified value is only accepted if the INSERT statement specifies OVERRIDING SYSTEM VALUE. If BY DEFAULT is selected, then the user-specified value takes precedence | ||
```ts | ||
await db.insert(identityColumnsTable).overridingSystemValue().values([ | ||
{ alwaysAsIdentity: 2 }, | ||
]); | ||
``` | ||
|
||
## Added `.$withAuth()` API for Neon HTTP driver | ||
|
||
Using this API, Drizzle will send you an auth token to authorize your query. It can be used with any query available in Drizzle by simply adding `.$withAuth()` before it. This token will be used for a specific query | ||
|
||
Examples | ||
|
||
```ts | ||
const token = 'HdncFj1Nm' | ||
|
||
await db.$withAuth(token).select().from(usersTable); | ||
await db.$withAuth(token).update(usersTable).set({ name: 'CHANGED' }).where(eq(usersTable.name, 'TARGET')) | ||
``` | ||
|
||
# Bug Fixes | ||
|
||
- [[BUG]: TypeScript error Please install '@neondatabase/serverless' to allow Drizzle ORM to connect to the database](https://github.com/drizzle-team/drizzle-orm/issues/3521) |
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,52 @@ | ||
# Initial Release | ||
|
||
> [!NOTE] | ||
> `drizzle-seed` can only be used with `[email protected]` or higher. Versions lower than this may work at runtime but could have type issues and identity column issues, as this patch was introduced in `[email protected]` | ||
## Full Reference | ||
|
||
The full API reference and package overview can be found in our [official documentation](https://orm.drizzle.team/docs/seed-overview) | ||
|
||
## Basic Usage | ||
|
||
In this example we will create 10 users with random names and ids | ||
|
||
```ts {12} | ||
import { pgTable, integer, text } 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(), | ||
}); | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { users }); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
## Options | ||
|
||
**`count`** | ||
|
||
By default, the `seed` function will create 10 entities. | ||
However, if you need more for your tests, you can specify this in the seed options object | ||
|
||
```ts | ||
await seed(db, schema, { count: 1000 }); | ||
``` | ||
|
||
**`seed`** | ||
|
||
If you need a seed to generate a different set of values for all subsequent runs, you can define a different number | ||
in the `seed` option. Any new number will generate a unique set of values | ||
|
||
```ts | ||
await seed(db, schema, { seed: 12345 }); | ||
``` | ||
|
||
The full API reference and package overview can be found in our [official documentation](https://orm.drizzle.team/docs/seed-overview) |
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
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.