0.3.1 • Published 8 months ago

drizzle-seed v0.3.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

Drizzle Seed

!NOTE drizzle-seed can only be used with drizzle-orm@0.36.4 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 drizzle-orm@0.36.4

Documentation

The full API reference and package overview can be found in our official documentation

Overview

drizzle-seed is a TypeScript library that helps you generate deterministic, yet realistic, fake data to populate your database. By leveraging a seedable pseudorandom number generator (pRNG), it ensures that the data you generate is consistent and reproducible across different runs. This is especially useful for testing, development, and debugging purposes.

What is Deterministic Data Generation?

Deterministic data generation means that the same input will always produce the same output. In the context of drizzle-seed, when you initialize the library with the same seed number, it will generate the same sequence of fake data every time. This allows for predictable and repeatable data sets.

Pseudorandom Number Generator (pRNG)

A pseudorandom number generator is an algorithm that produces a sequence of numbers that approximates the properties of random numbers. However, because it's based on an initial value called a seed, you can control its randomness. By using the same seed, the pRNG will produce the same sequence of numbers, making your data generation process reproducible.

Benefits of Using a pRNG:

  • Consistency: Ensures that your tests run on the same data every time.
  • Debugging: Makes it easier to reproduce and fix bugs by providing a consistent data set.
  • Collaboration: Team members can share seed numbers to work with the same data sets.

With drizzle-seed, you get the best of both worlds: the ability to generate realistic fake data and the control to reproduce it whenever needed.

Getting started

npm install drizzle-seed

You have to install drizzle-orm in order to use drizzle-seed.

npm install drizzle-orm

Basic Usage

In this example we will create 10 users with random names and ids

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

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

await seed(db, schema, { seed: 12345 });

Reset databases

With drizzle-seed, you can easily reset your database and seed it with new values, for example, in your test suites

// path to a file with schema you want to reset
import * as schema from "./schema.ts";
import { reset } from "drizzle-seed";

async function main() {
  const db = drizzle(process.env.DATABASE_URL!);
  await reset(db, schema);
}

main();

More examples are available in our official documentation

0.3.1-9fd1115

8 months ago

0.3.1-e30ede4

8 months ago

0.3.2-f8a2f3c

8 months ago

0.3.1-cacd055

8 months ago

0.3.1-53e792e

8 months ago

0.3.1-fd5d1e8

8 months ago

0.3.1-af4c434

8 months ago

0.3.1-abfca61

8 months ago

0.3.1-90273a7

8 months ago

0.3.1-bbf78ae

8 months ago

0.3.2-905c951

8 months ago

0.3.2-8e220c4

8 months ago

0.3.2-61ab0d9

8 months ago

0.3.2-97009ae

8 months ago

0.3.1-d004082

8 months ago

0.3.1-af1f2fe

9 months ago

0.3.1-262a7b0

9 months ago

0.3.1-1b8a752

9 months ago

0.3.1-a5d12b4

9 months ago

0.3.1-dc3b366

9 months ago

0.3.1-2fb137b

9 months ago

0.3.1-c7c31ad

9 months ago

0.3.1-65ced5e

9 months ago

0.1.2-3efe329

9 months ago

0.3.1-c417a27

9 months ago

0.3.1-338c5e5

9 months ago

0.3.1-627b98f

9 months ago

0.3.1-8628c8a

9 months ago

0.1.2-8896749

9 months ago

0.3.1-0cc153d

9 months ago

0.3.1-6f787bc

9 months ago

0.3.1-aaa57ff

9 months ago

0.3.1-eba7324

9 months ago

0.3.1-a82c3ad

9 months ago

0.3.1-a0db3f7

9 months ago

0.3.1-563f370

9 months ago

0.3.1-1177ad8

9 months ago

0.3.1-98994dc

9 months ago

0.3.1-ffb171d

9 months ago

0.3.1-4647df7

9 months ago

0.3.1-610a691

9 months ago

0.3.1

9 months ago

0.3.0-f9c666c

10 months ago

0.3.0-b776df4

10 months ago

0.3.1-389471d

10 months ago

0.3.0-6b6aca7

10 months ago

0.3.0-a42bb03

9 months ago

0.3.0-efae52b

10 months ago

0.3.0-88fe396

10 months ago

0.3.0-84987cd

10 months ago

0.3.0-f36e3ea

10 months ago

0.3.1-19ccabb

10 months ago

0.3.1-991e8b4

9 months ago

0.3.0-2c67783

10 months ago

0.3.0-aa1668f

10 months ago

0.3.0-e36471e

10 months ago

0.2.1-f2d266c

10 months ago

0.3.0-9927cf1

10 months ago

0.3.0-15cd998

10 months ago

0.3.0-471d797

10 months ago

0.3.0-bd7c23e

10 months ago

0.2.1-5734f71

10 months ago

0.2.1-efed06b

10 months ago

0.3.1-b06bbcd

10 months ago

0.2.1-2c70592

10 months ago

0.3.0-0a0cdd2

10 months ago

0.3.0-055ab2c

10 months ago

0.3.0-0350a59

10 months ago

0.2.1-57eb6bd

10 months ago

0.2.1-348fb92

10 months ago

0.3.0-8e428d1

10 months ago

0.2.1-86fcd29

10 months ago

0.2.1-b4f992e

10 months ago

0.3.0-44616e9

10 months ago

0.3.0-de3c537

10 months ago

0.3.0-9d1aac1

10 months ago

0.2.1-38fedf0

10 months ago

0.3.0-2329e17

10 months ago

0.1.2-66f461a

11 months ago

0.2.0-5ee9619

11 months ago

0.2.0-5d7860c

11 months ago

0.2.1-e6823b4

10 months ago

0.2.1-7db411e

10 months ago

0.3.0

10 months ago

0.2.0-be0f833

11 months ago

0.2.1-c095ebc

10 months ago

0.2.1-791f459

10 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.3-0db3d13

11 months ago

0.1.3-2807200

11 months ago

0.1.2-3256029

11 months ago

0.1.2-5dc5b05

11 months ago

0.1.2-7c72529

11 months ago

0.1.3-e14a5a2

11 months ago

0.1.2-5d53945

11 months ago

0.1.3-ec5d35e

11 months ago

0.1.3-05d907b

11 months ago

0.1.2-a44af76

11 months ago

0.1.3-1c8cbad

11 months ago

0.1.3-019d9b0

11 months ago

0.1.2-dbf7383

11 months ago

0.1.3-7cd9d79

11 months ago

0.1.2-994b9b8

11 months ago

0.1.2-d21dbf5

11 months ago

0.1.3-1b05f63

11 months ago

0.1.3-06a9368

11 months ago

0.1.2-c56b864

11 months ago

0.1.2-5514d51

11 months ago

0.1.2-661b6f2

11 months ago

0.1.3

11 months ago

0.1.3-21dab20

11 months ago

0.1.2-7525e49

11 months ago

0.1.3-1abaaf8

11 months ago

0.1.2-7f37974

11 months ago

0.1.2-95a805f

11 months ago

0.1.2-3f3eb73

11 months ago

0.1.2-29eb63c

11 months ago

0.1.3-aafed23

11 months ago

0.1.2-3c69a1f

11 months ago

0.1.3-d379dcf

11 months ago

0.1.2-0c27176

11 months ago

0.1.2-0ab568f

11 months ago

0.1.3-f6eaa62

11 months ago

0.1.2-7665ad9

11 months ago

0.1.3-db33c87

11 months ago

0.1.3-455725c

11 months ago

0.1.2-74a51ae

11 months ago

0.1.1-3d262cd

11 months ago

0.1.1-440c1ee

12 months ago

0.1.2-14e59f4

11 months ago

0.1.2-08d2486

12 months ago

0.1.1-4b33aac

12 months ago

0.1.1-6f7d345

12 months ago

0.1.2-ddb97ec

12 months ago

0.1.1-6479912

12 months ago

0.1.2-717bfb5

12 months ago

0.1.0

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.1.1-375ed28

12 months ago

0.1.1-7fe6033

12 months ago

0.1.1-fcaa0a5

12 months ago

0.1.1-166fb8d

12 months ago

0.0.1

1 year ago