drizzle-seed 0.0.1 → 0.1.1-166fb8d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -0
- package/datasets/adjectives.d.cts +5 -0
- package/datasets/adjectives.d.mts +5 -0
- package/datasets/adjectives.d.ts +5 -0
- package/datasets/cityNames.d.cts +6 -0
- package/datasets/cityNames.d.mts +6 -0
- package/datasets/cityNames.d.ts +6 -0
- package/datasets/companyNameSuffixes.d.cts +2 -0
- package/datasets/companyNameSuffixes.d.mts +2 -0
- package/datasets/companyNameSuffixes.d.ts +2 -0
- package/datasets/countries.d.cts +6 -0
- package/datasets/countries.d.mts +6 -0
- package/datasets/countries.d.ts +6 -0
- package/datasets/emailDomains.d.cts +2 -0
- package/datasets/emailDomains.d.mts +2 -0
- package/datasets/emailDomains.d.ts +2 -0
- package/datasets/firstNames.d.cts +5 -0
- package/datasets/firstNames.d.mts +5 -0
- package/datasets/firstNames.d.ts +5 -0
- package/datasets/jobsTitles.d.cts +5 -0
- package/datasets/jobsTitles.d.mts +5 -0
- package/datasets/jobsTitles.d.ts +5 -0
- package/datasets/lastNames.d.cts +5 -0
- package/datasets/lastNames.d.mts +5 -0
- package/datasets/lastNames.d.ts +5 -0
- package/datasets/loremIpsumSentences.d.cts +5 -0
- package/datasets/loremIpsumSentences.d.mts +5 -0
- package/datasets/loremIpsumSentences.d.ts +5 -0
- package/datasets/phonesInfo.d.cts +7 -0
- package/datasets/phonesInfo.d.mts +7 -0
- package/datasets/phonesInfo.d.ts +7 -0
- package/datasets/states.d.cts +2 -0
- package/datasets/states.d.mts +2 -0
- package/datasets/states.d.ts +2 -0
- package/datasets/streetSuffix.d.cts +5 -0
- package/datasets/streetSuffix.d.mts +5 -0
- package/datasets/streetSuffix.d.ts +5 -0
- package/index.cjs +2 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +288 -0
- package/index.d.mts +288 -0
- package/index.d.ts +288 -0
- package/index.mjs +2 -0
- package/index.mjs.map +1 -0
- package/package.json +102 -9
- package/services/GeneratorsWrappers.d.cts +1293 -0
- package/services/GeneratorsWrappers.d.mts +1293 -0
- package/services/GeneratorsWrappers.d.ts +1293 -0
- package/services/SeedService.d.cts +112 -0
- package/services/SeedService.d.mts +112 -0
- package/services/SeedService.d.ts +112 -0
- package/services/utils.d.cts +20 -0
- package/services/utils.d.mts +20 -0
- package/services/utils.d.ts +20 -0
- package/tests/benchmarks/generatorsBenchmark.d.cts +1 -0
- package/tests/benchmarks/generatorsBenchmark.d.mts +1 -0
- package/tests/benchmarks/generatorsBenchmark.d.ts +1 -0
- package/tests/mysql/allDataTypesTest/drizzle.config.d.cts +2 -0
- package/tests/mysql/allDataTypesTest/drizzle.config.d.mts +2 -0
- package/tests/mysql/allDataTypesTest/drizzle.config.d.ts +2 -0
- package/tests/mysql/allDataTypesTest/mysqlSchema.d.cts +466 -0
- package/tests/mysql/allDataTypesTest/mysqlSchema.d.mts +466 -0
- package/tests/mysql/allDataTypesTest/mysqlSchema.d.ts +466 -0
- package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.cts +1 -0
- package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.mts +1 -0
- package/tests/mysql/allDataTypesTest/mysql_all_data_types.test.d.ts +1 -0
- package/tests/mysql/drizzle.config.d.cts +2 -0
- package/tests/mysql/drizzle.config.d.mts +2 -0
- package/tests/mysql/drizzle.config.d.ts +2 -0
- package/tests/mysql/generatorsTest/drizzle.config.d.cts +2 -0
- package/tests/mysql/generatorsTest/drizzle.config.d.mts +2 -0
- package/tests/mysql/generatorsTest/drizzle.config.d.ts +2 -0
- package/tests/mysql/generatorsTest/generators.test.d.cts +1 -0
- package/tests/mysql/generatorsTest/generators.test.d.mts +1 -0
- package/tests/mysql/generatorsTest/generators.test.d.ts +1 -0
- package/tests/mysql/generatorsTest/mysqlSchema.d.cts +48 -0
- package/tests/mysql/generatorsTest/mysqlSchema.d.mts +48 -0
- package/tests/mysql/generatorsTest/mysqlSchema.d.ts +48 -0
- package/tests/mysql/mysql.test.d.cts +1 -0
- package/tests/mysql/mysql.test.d.mts +1 -0
- package/tests/mysql/mysql.test.d.ts +1 -0
- package/tests/mysql/mysqlSchema.d.cts +1130 -0
- package/tests/mysql/mysqlSchema.d.mts +1130 -0
- package/tests/mysql/mysqlSchema.d.ts +1130 -0
- package/tests/northwind/mysqlSchema.d.cts +1130 -0
- package/tests/northwind/mysqlSchema.d.mts +1130 -0
- package/tests/northwind/mysqlSchema.d.ts +1130 -0
- package/tests/northwind/mysqlTest.d.cts +1 -0
- package/tests/northwind/mysqlTest.d.mts +1 -0
- package/tests/northwind/mysqlTest.d.ts +1 -0
- package/tests/northwind/pgSchema.d.cts +1131 -0
- package/tests/northwind/pgSchema.d.mts +1131 -0
- package/tests/northwind/pgSchema.d.ts +1131 -0
- package/tests/northwind/pgTest.d.cts +1 -0
- package/tests/northwind/pgTest.d.mts +1 -0
- package/tests/northwind/pgTest.d.ts +1 -0
- package/tests/northwind/sqliteSchema.d.cts +1130 -0
- package/tests/northwind/sqliteSchema.d.mts +1130 -0
- package/tests/northwind/sqliteSchema.d.ts +1130 -0
- package/tests/northwind/sqliteTest.d.cts +1 -0
- package/tests/northwind/sqliteTest.d.mts +1 -0
- package/tests/northwind/sqliteTest.d.ts +1 -0
- package/tests/pg/allDataTypesTest/drizzle.config.d.cts +2 -0
- package/tests/pg/allDataTypesTest/drizzle.config.d.mts +2 -0
- package/tests/pg/allDataTypesTest/drizzle.config.d.ts +2 -0
- package/tests/pg/allDataTypesTest/pgSchema.d.cts +509 -0
- package/tests/pg/allDataTypesTest/pgSchema.d.mts +509 -0
- package/tests/pg/allDataTypesTest/pgSchema.d.ts +509 -0
- package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.cts +1 -0
- package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.mts +1 -0
- package/tests/pg/allDataTypesTest/pg_all_data_types.test.d.ts +1 -0
- package/tests/pg/drizzle.config.d.cts +2 -0
- package/tests/pg/drizzle.config.d.mts +2 -0
- package/tests/pg/drizzle.config.d.ts +2 -0
- package/tests/pg/generatorsTest/drizzle.config.d.cts +2 -0
- package/tests/pg/generatorsTest/drizzle.config.d.mts +2 -0
- package/tests/pg/generatorsTest/drizzle.config.d.ts +2 -0
- package/tests/pg/generatorsTest/generators.test.d.cts +1 -0
- package/tests/pg/generatorsTest/generators.test.d.mts +1 -0
- package/tests/pg/generatorsTest/generators.test.d.ts +1 -0
- package/tests/pg/generatorsTest/pgSchema.d.cts +1136 -0
- package/tests/pg/generatorsTest/pgSchema.d.mts +1136 -0
- package/tests/pg/generatorsTest/pgSchema.d.ts +1136 -0
- package/tests/pg/pg.test.d.cts +1 -0
- package/tests/pg/pg.test.d.mts +1 -0
- package/tests/pg/pg.test.d.ts +1 -0
- package/tests/pg/pgSchema.d.cts +1189 -0
- package/tests/pg/pgSchema.d.mts +1189 -0
- package/tests/pg/pgSchema.d.ts +1189 -0
- package/tests/sqlite/allDataTypesTest/sqliteSchema.d.cts +194 -0
- package/tests/sqlite/allDataTypesTest/sqliteSchema.d.mts +194 -0
- package/tests/sqlite/allDataTypesTest/sqliteSchema.d.ts +194 -0
- package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.cts +1 -0
- package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.mts +1 -0
- package/tests/sqlite/allDataTypesTest/sqlite_all_data_types.test.d.ts +1 -0
- package/tests/sqlite/sqlite.test.d.cts +1 -0
- package/tests/sqlite/sqlite.test.d.mts +1 -0
- package/tests/sqlite/sqlite.test.d.ts +1 -0
- package/tests/sqlite/sqliteSchema.d.cts +1130 -0
- package/tests/sqlite/sqliteSchema.d.mts +1130 -0
- package/tests/sqlite/sqliteSchema.d.ts +1130 -0
- package/tests/vitest.config.d.cts +2 -0
- package/tests/vitest.config.d.mts +2 -0
- package/tests/vitest.config.d.ts +2 -0
- package/types/drizzleStudio.d.cts +60 -0
- package/types/drizzleStudio.d.mts +60 -0
- package/types/drizzleStudio.d.ts +60 -0
- package/types/seedService.d.cts +45 -0
- package/types/seedService.d.mts +45 -0
- package/types/seedService.d.ts +45 -0
- package/types/tables.d.cts +25 -0
- package/types/tables.d.mts +25 -0
- package/types/tables.d.ts +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Drizzle Seed
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> `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`
|
|
5
|
+
|
|
6
|
+
## Documentation
|
|
7
|
+
|
|
8
|
+
The full API reference and package overview can be found in our [official documentation](https://orm.drizzle.team/docs/seed-overview)
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
`drizzle-seed` is a TypeScript library that helps you generate deterministic, yet realistic,
|
|
13
|
+
fake data to populate your database. By leveraging a seedable pseudorandom number generator (pRNG),
|
|
14
|
+
it ensures that the data you generate is consistent and reproducible across different runs.
|
|
15
|
+
This is especially useful for testing, development, and debugging purposes.
|
|
16
|
+
|
|
17
|
+
#### What is Deterministic Data Generation?
|
|
18
|
+
|
|
19
|
+
Deterministic data generation means that the same input will always produce the same output.
|
|
20
|
+
In the context of `drizzle-seed`, when you initialize the library with the same seed number,
|
|
21
|
+
it will generate the same sequence of fake data every time. This allows for predictable and repeatable data sets.
|
|
22
|
+
|
|
23
|
+
#### Pseudorandom Number Generator (pRNG)
|
|
24
|
+
|
|
25
|
+
A pseudorandom number generator is an algorithm that produces a sequence of numbers
|
|
26
|
+
that approximates the properties of random numbers. However, because it's based on an initial value
|
|
27
|
+
called a seed, you can control its randomness. By using the same seed, the pRNG will produce the
|
|
28
|
+
same sequence of numbers, making your data generation process reproducible.
|
|
29
|
+
|
|
30
|
+
#### Benefits of Using a pRNG:
|
|
31
|
+
|
|
32
|
+
- Consistency: Ensures that your tests run on the same data every time.
|
|
33
|
+
- Debugging: Makes it easier to reproduce and fix bugs by providing a consistent data set.
|
|
34
|
+
- Collaboration: Team members can share seed numbers to work with the same data sets.
|
|
35
|
+
|
|
36
|
+
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.
|
|
37
|
+
|
|
38
|
+
## Getting started
|
|
39
|
+
|
|
40
|
+
`npm install drizzle-seed`
|
|
41
|
+
|
|
42
|
+
You have to install `drizzle-orm` in order to use `drizzle-seed`.
|
|
43
|
+
|
|
44
|
+
`npm install drizzle-orm`
|
|
45
|
+
|
|
46
|
+
## Basic Usage
|
|
47
|
+
|
|
48
|
+
In this example we will create 10 users with random names and ids
|
|
49
|
+
|
|
50
|
+
```ts {12}
|
|
51
|
+
import { pgTable, integer, text } from "drizzle-orm/pg-core";
|
|
52
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
53
|
+
import { seed } from "drizzle-seed";
|
|
54
|
+
|
|
55
|
+
const users = pgTable("users", {
|
|
56
|
+
id: integer().primaryKey(),
|
|
57
|
+
name: text().notNull(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
async function main() {
|
|
61
|
+
const db = drizzle(process.env.DATABASE_URL!);
|
|
62
|
+
await seed(db, { users });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Options
|
|
69
|
+
|
|
70
|
+
**`count`**
|
|
71
|
+
|
|
72
|
+
By default, the `seed` function will create 10 entities.
|
|
73
|
+
However, if you need more for your tests, you can specify this in the seed options object
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
await seed(db, schema, { count: 1000 });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**`seed`**
|
|
80
|
+
|
|
81
|
+
If you need a seed to generate a different set of values for all subsequent runs, you can define a different number
|
|
82
|
+
in the `seed` option. Any new number will generate a unique set of values
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
await seed(db, schema, { seed: 12345 });
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Reset databases
|
|
89
|
+
|
|
90
|
+
With `drizzle-seed`, you can easily reset your database and seed it with new values, for example, in your test suites
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
// path to a file with schema you want to reset
|
|
94
|
+
import * as schema from "./schema.ts";
|
|
95
|
+
import { reset } from "drizzle-seed";
|
|
96
|
+
|
|
97
|
+
async function main() {
|
|
98
|
+
const db = drizzle(process.env.DATABASE_URL!);
|
|
99
|
+
await reset(db, schema);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
More examples are available in our [official documentation](https://orm.drizzle.team/docs/seed-overview)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for cities names data was taken from https://www.kaggle.com/datasets/juanmah/world-cities
|
|
3
|
+
* We've excluded a few countries and their cities from this list because we don't think they should ever appear in any list
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: string[];
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for cities names data was taken from https://www.kaggle.com/datasets/juanmah/world-cities
|
|
3
|
+
* We've excluded a few countries and their cities from this list because we don't think they should ever appear in any list
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: string[];
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for cities names data was taken from https://www.kaggle.com/datasets/juanmah/world-cities
|
|
3
|
+
* We've excluded a few countries and their cities from this list because we don't think they should ever appear in any list
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: string[];
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for countries data was taken from https://www.kaggle.com/datasets/manusmitajha/countrydatacsv
|
|
3
|
+
* We've excluded a few countries and their cities from this list because we don't think they should ever appear in any list
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: string[];
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for countries data was taken from https://www.kaggle.com/datasets/manusmitajha/countrydatacsv
|
|
3
|
+
* We've excluded a few countries and their cities from this list because we don't think they should ever appear in any list
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: string[];
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for countries data was taken from https://www.kaggle.com/datasets/manusmitajha/countrydatacsv
|
|
3
|
+
* We've excluded a few countries and their cities from this list because we don't think they should ever appear in any list
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: string[];
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for the phones info data was taken from https://www.kaggle.com/datasets/leighplt/country-code?select=mobile_telephone_prefixes_by_country.csv
|
|
3
|
+
*
|
|
4
|
+
* Data format is: ["country prefix, operator prefix, number length including operator prefix and excluding country prefix"]
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: string[];
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for the phones info data was taken from https://www.kaggle.com/datasets/leighplt/country-code?select=mobile_telephone_prefixes_by_country.csv
|
|
3
|
+
*
|
|
4
|
+
* Data format is: ["country prefix, operator prefix, number length including operator prefix and excluding country prefix"]
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: string[];
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The original source for the phones info data was taken from https://www.kaggle.com/datasets/leighplt/country-code?select=mobile_telephone_prefixes_by_country.csv
|
|
3
|
+
*
|
|
4
|
+
* Data format is: ["country prefix, operator prefix, number length including operator prefix and excluding country prefix"]
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: string[];
|
|
7
|
+
export default _default;
|