0.3.1 • Published 11 months ago

drizzle-seed v0.3.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 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

11 months ago

0.3.1-e30ede4

11 months ago

0.3.2-f8a2f3c

11 months ago

0.3.1-cacd055

11 months ago

0.3.1-53e792e

11 months ago

0.3.1-fd5d1e8

11 months ago

0.3.1-af4c434

11 months ago

0.3.1-abfca61

11 months ago

0.3.1-90273a7

11 months ago

0.3.1-bbf78ae

11 months ago

0.3.2-905c951

11 months ago

0.3.2-8e220c4

11 months ago

0.3.2-61ab0d9

11 months ago

0.3.2-97009ae

11 months ago

0.3.1-d004082

11 months ago

0.3.1-af1f2fe

11 months ago

0.3.1-262a7b0

11 months ago

0.3.1-1b8a752

11 months ago

0.3.1-a5d12b4

11 months ago

0.3.1-dc3b366

11 months ago

0.3.1-2fb137b

11 months ago

0.3.1-c7c31ad

11 months ago

0.3.1-65ced5e

11 months ago

0.1.2-3efe329

11 months ago

0.3.1-c417a27

12 months ago

0.3.1-338c5e5

12 months ago

0.3.1-627b98f

12 months ago

0.3.1-8628c8a

12 months ago

0.1.2-8896749

12 months ago

0.3.1-0cc153d

12 months ago

0.3.1-6f787bc

12 months ago

0.3.1-aaa57ff

12 months ago

0.3.1-eba7324

12 months ago

0.3.1-a82c3ad

12 months ago

0.3.1-a0db3f7

12 months ago

0.3.1-563f370

12 months ago

0.3.1-1177ad8

12 months ago

0.3.1-98994dc

12 months ago

0.3.1-ffb171d

12 months ago

0.3.1-4647df7

12 months ago

0.3.1-610a691

12 months ago

0.3.1

12 months ago

0.3.0-f9c666c

1 year ago

0.3.0-b776df4

1 year ago

0.3.1-389471d

1 year ago

0.3.0-6b6aca7

12 months ago

0.3.0-a42bb03

12 months ago

0.3.0-efae52b

1 year ago

0.3.0-88fe396

1 year ago

0.3.0-84987cd

1 year ago

0.3.0-f36e3ea

1 year ago

0.3.1-19ccabb

1 year ago

0.3.1-991e8b4

12 months ago

0.3.0-2c67783

12 months ago

0.3.0-aa1668f

1 year ago

0.3.0-e36471e

1 year ago

0.2.1-f2d266c

1 year ago

0.3.0-9927cf1

1 year ago

0.3.0-15cd998

1 year ago

0.3.0-471d797

1 year ago

0.3.0-bd7c23e

1 year ago

0.2.1-5734f71

1 year ago

0.2.1-efed06b

1 year ago

0.3.1-b06bbcd

1 year ago

0.2.1-2c70592

1 year ago

0.3.0-0a0cdd2

1 year ago

0.3.0-055ab2c

1 year ago

0.3.0-0350a59

1 year ago

0.2.1-57eb6bd

1 year ago

0.2.1-348fb92

1 year ago

0.3.0-8e428d1

1 year ago

0.2.1-86fcd29

1 year ago

0.2.1-b4f992e

1 year ago

0.3.0-44616e9

1 year ago

0.3.0-de3c537

1 year ago

0.3.0-9d1aac1

1 year ago

0.2.1-38fedf0

1 year ago

0.3.0-2329e17

1 year ago

0.1.2-66f461a

1 year ago

0.2.0-5ee9619

1 year ago

0.2.0-5d7860c

1 year ago

0.2.1-e6823b4

1 year ago

0.2.1-7db411e

1 year ago

0.3.0

1 year ago

0.2.0-be0f833

1 year ago

0.2.1-c095ebc

1 year ago

0.2.1-791f459

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.3-0db3d13

1 year ago

0.1.3-2807200

1 year ago

0.1.2-3256029

1 year ago

0.1.2-5dc5b05

1 year ago

0.1.2-7c72529

1 year ago

0.1.3-e14a5a2

1 year ago

0.1.2-5d53945

1 year ago

0.1.3-ec5d35e

1 year ago

0.1.3-05d907b

1 year ago

0.1.2-a44af76

1 year ago

0.1.3-1c8cbad

1 year ago

0.1.3-019d9b0

1 year ago

0.1.2-dbf7383

1 year ago

0.1.3-7cd9d79

1 year ago

0.1.2-994b9b8

1 year ago

0.1.2-d21dbf5

1 year ago

0.1.3-1b05f63

1 year ago

0.1.3-06a9368

1 year ago

0.1.2-c56b864

1 year ago

0.1.2-5514d51

1 year ago

0.1.2-661b6f2

1 year ago

0.1.3

1 year ago

0.1.3-21dab20

1 year ago

0.1.2-7525e49

1 year ago

0.1.3-1abaaf8

1 year ago

0.1.2-7f37974

1 year ago

0.1.2-95a805f

1 year ago

0.1.2-3f3eb73

1 year ago

0.1.2-29eb63c

1 year ago

0.1.3-aafed23

1 year ago

0.1.2-3c69a1f

1 year ago

0.1.3-d379dcf

1 year ago

0.1.2-0c27176

1 year ago

0.1.2-0ab568f

1 year ago

0.1.3-f6eaa62

1 year ago

0.1.2-7665ad9

1 year ago

0.1.3-db33c87

1 year ago

0.1.3-455725c

1 year ago

0.1.2-74a51ae

1 year ago

0.1.1-3d262cd

1 year ago

0.1.1-440c1ee

1 year ago

0.1.2-14e59f4

1 year ago

0.1.2-08d2486

1 year ago

0.1.1-4b33aac

1 year ago

0.1.1-6f7d345

1 year ago

0.1.2-ddb97ec

1 year ago

0.1.1-6479912

1 year ago

0.1.2-717bfb5

1 year ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.1-375ed28

1 year ago

0.1.1-7fe6033

1 year ago

0.1.1-fcaa0a5

1 year ago

0.1.1-166fb8d

1 year ago

0.0.1

1 year ago