new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle · MySQL · all subjects

drizzle-seed

85 notes in this subject, read out of this brain and free to use. This is page 1 of 2.

postcode generator

The postcode generator generates postal codes. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

state generator

The state generator generates US states. Parameters: arraySize (number, optional) - if specified, creates arrays of states.

companyName generator

The companyName generator generates random company names. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

loremIpsum generator

The loremIpsum generator generates lorem ipsum text sentences. Parameters: sentencesCount (number, default 1) - number of sentences to generate as one string, arraySize (number, optional).

point generator

The point generator generates 2D points within specified ranges for x and y coordinates. Parameters: isUnique (boolean, defaults to database column uniqueness), minXValue (number, defaults to -maxXValue), maxXValue (number, defaults to 10 * 1000 if not unique, 10 * count if unique), minYValue (number, defaults to -maxYValue), maxYValue (number, defaults to 10 * 1000 if not unique, 10 * count if unique), arraySize (number, optional).

line generator

The line generator generates 2D lines within specified ranges for a, b and c parameters of the line equation: a*x + b*y + c = 0. Parameters: isUnique (boolean, defaults to database column uniqueness), minAValue (number, defaults to -maxAValue), maxAValue (number, defaults to 10 * 1000 if not unique, 10 * count if unique), minBValue (number, defaults to -maxBValue), maxBValue (number, defaults to 10 * 1000 if not unique, 10 * count if unique), minCValue (number, defaults to -maxCValue), maxCValue (number, defaults to 10 * 1000 if not unique, 10 * count if unique), arraySize (number, optional).

bitString generator

The bitString generator generates bit strings based on specified parameters. Parameters: isUnique (boolean, defaults to database column uniqueness), dimensions (number, defaults to database column bit-length) - desired length of each bit string, arraySize (number, optional).

inet generator

The inet generator generates IP addresses. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional), ipAddress (string, default 'ipv4') - either 'ipv4' or 'ipv6', includeCidr (boolean, default true) - whether to include CIDR suffix.

geometry generator limitations with arraySize

Currently, if arraySize is set to a value greater than 1 or if trying to insert more than one geometry point element into a geometry(point, 0)[] column in MySQL via drizzle-orm, an error will be encountered. This is a known bug in the backlog. Use arraySize: 1 for geometry arrays.

geometry generator limitations with SRID

Currently, if the SRID of a geometry(point) column is set to anything other than 0 (for example, 4326) in the drizzle-orm table declaration, an error will be encountered during the seeding process. This is a known bug in the backlog. Set SRID to 0 in table declaration and pass the desired SRID to the generator.

geometry generator

The geometry generator generates geometry objects. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional, limited to 1 for MySQL), type (string, default 'point') - currently only 'point' is supported, srid (number, default 4326) - either 4326 or 3857, decimalPlaces (number, default 6) - 1-7 decimal places for points.

vector generator

The vector generator generates vectors based on provided parameters. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional), decimalPlaces (number, default 2) - decimal places for each vector element, dimensions (number, defaults to database column's dimensions) - number of elements in each vector, minValue (number, default -1000) - minimum value for each element, maxValue (number, default 1000) - maximum value for each element.

arraySize parameter with isUnique warning

When both arraySize and isUnique are specified in generators that support both, unique values are generated (not unique arrays), which are then packed into arrays. This means each element in the array will be unique, but the arrays themselves may not be globally unique.

drizzle-seed generators overview

drizzle-seed provides generator functions for seeding databases with various data types. These generators are used within the seed() function's refine() callback to specify how to generate values for each column. Each generator supports an arraySize parameter (if specified, arrays will be generated) and other parameters specific to the data type being generated.

default generator

The default generator generates the same given value each time it is called. Parameters: defaultValue (any, required) - the value to generate repeatedly, arraySize (number, optional) - if specified, creates arrays of the default value.

valuesFromArray generator

The valuesFromArray generator generates values from a given array. Parameters: values (any[] | { weight: number; values: any[] }[], required) - array of values to pick from (can be weighted), isUnique (boolean, defaults to database column uniqueness) - whether values are unique, arraySize (number, optional) - creates arrays if specified.

intPrimaryKey generator

The intPrimaryKey generator generates sequential integers starting from 1. It takes no parameters.

number generator

The number generator generates floating point numbers within a specified range. Parameters: isUnique (boolean, defaults to database column uniqueness), precision (number, default 100) - decimal precision where 10 means 0.1, 100 means 0.01, minValue (number, defaults to -maxValue), maxValue (number, defaults to precision * 1000 if not unique, precision * count if unique), arraySize (number, optional).

int generator

The int generator generates integers within a specified range. Parameters: isUnique (boolean, defaults to database column uniqueness), minValue (number | bigint, defaults to -maxValue), maxValue (number | bigint, defaults to 1000 if not unique, count * 10 if unique), arraySize (number, optional).

boolean generator

The boolean generator generates boolean values (true or false). Parameters: arraySize (number, optional) - if specified, creates arrays of booleans.

date generator

The date generator generates dates within a specified range. Parameters: minDate (string | Date, defaults to '2024-05-08' - 4 years if maxDate not set, or maxDate - 8 years if maxDate set), maxDate (string | Date, defaults to '2024-05-08' + 4 years if minDate not set, or minDate + 8 years if minDate set), arraySize (number, optional). If only one date parameter is provided, the other is calculated by adding or subtracting 8 years.

time generator

The time generator generates time in 24-hour format. Parameters: min (string | Date, default '00:00:00.000Z'), max (string | Date, default '23:59:59.999Z'), arraySize (number, optional).

timestamp generator

The timestamp generator generates timestamps. Parameters: min (string | Date, defaults to '2024-05-08' - 2 years if max not set, or max - 4 years if max set), max (string | Date, defaults to '2024-05-08' + 2 years if min not set, or min + 4 years if min set), arraySize (number, optional).

datetime generator

The datetime generator generates datetime objects. Parameters: min (string | Date, defaults to '2024-05-08' - 2 years if max not set, or max - 4 years if max set), max (string | Date, defaults to '2024-05-08' + 2 years if min not set, or min + 4 years if min set), arraySize (number, optional).

year generator

The year generator generates years in YYYY format. Parameters: arraySize (number, optional) - if specified, creates arrays of years.

json generator

The json generator generates JSON objects with a fixed structure. The JSON structure is randomly picked from predefined structures like { email, name, isGraduated, hasJob, salary, startedWorking, visitedCountries } or { email, name, isGraduated, hasJob, visitedCountries }. Parameters: arraySize (number, optional).

interval generator

The interval generator generates time intervals like '1 year 12 days 5 minutes'. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

string generator

The string generator generates random strings. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

uuid generator

The uuid generator generates v4 UUID strings. Parameters: arraySize (number, optional) - if specified, creates arrays of UUIDs.

firstName generator

The firstName generator generates a person's first name. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

lastName generator

The lastName generator generates a person's last name. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

fullName generator

The fullName generator generates a person's full name. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

email generator

The email generator generates unique email addresses. Parameters: arraySize (number, optional) - if specified, creates arrays of emails.

phoneNumber generator with template

The phoneNumber generator generates unique phone numbers using a template where '#' symbols are replaced with generated digits. Parameters: template (string, required) - phone number template with '#' for digit substitution, arraySize (number, optional).

phoneNumber generator with prefixes

The phoneNumber generator can generate phone numbers using prefixes and generated digits. Parameters: prefixes (string[], required, not compatible with template) - array of phone number prefixes, generatedDigitsNumbers (number | number[], optional, default 7 if prefixes defined) - number of digits to append to each prefix (can be different per prefix), arraySize (number, optional).

country generator

The country generator generates country names. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

city generator

The city generator generates city names. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

streetAddress generator

The streetAddress generator generates street addresses. Parameters: isUnique (boolean, defaults to database column uniqueness), arraySize (number, optional).

jobTitle generator

The jobTitle generator generates job titles. Parameters: arraySize (number, optional) - if specified, creates arrays of job titles.

weightedRandom() for columns uses weight and value properties

The weightedRandom generator accepts an array of objects with weight (probability as decimal 0-1) and value (generator function result) properties. Example: f.weightedRandom([{ weight: 0.3, value: f.int({minValue: 10, maxValue: 100}) }, { weight: 0.7, value: f.number({minValue: 100, maxValue: 300, precision: 100}) }]).

Install drizzle-seed package

Install the drizzle-seed package using npm, pnpm, or yarn to use deterministic data generation for your database.

seed() function basic usage for MySQL

The seed function accepts a database instance and schema object to generate fake data. Default behavior creates 10 entities. Example: await seed(db, { users }).refine(...) for a MySQL setup using drizzle-orm/mysql2.

seed() count option specifies number of entities to create

The count option in seed function options controls how many entities to generate. Default is 10. Example: await seed(db, schema, { count: 1000 }).

seed() seed option generates different data sets with different values

The seed option in seed function options accepts a number that controls the pseudorandom number generator. Each different seed number generates a unique set of values. Example: await seed(db, schema, { seed: 12345 }).

reset() function empties all tables in database for MySQL

The reset function from drizzle-seed empties all tables in the database schema. For MySQL, it disables FOREIGN_KEY_CHECKS, generates TRUNCATE statements for all tables, then re-enables FOREIGN_KEY_CHECKS. Example: await reset(db, schema).

MySQL reset strategy uses FOREIGN_KEY_CHECKS and TRUNCATE

For MySQL, drizzle-seed's reset function first executes SET FOREIGN_KEY_CHECKS = 0, then generates TRUNCATE statements for each table, then executes SET FOREIGN_KEY_CHECKS = 1. This prevents foreign key constraint failures when clearing tables.

refine() customizes seed generator behavior per table and column

The refine method accepts a callback that receives generator functions. It returns an object with table keys, where each table can specify: columns (customize or exclude column generation), count (override global count for this table), and with (define related entities to create). Excluding a column uses false to allow database defaults.

refine() with option creates related entities for one-to-many relationships

The with property in refine defines how many referenced entities to create for each parent table. Works only for one-to-many relationships. Example: with: { posts: 10 } creates 10 posts for each user.

drizzle-seed generator functions available in refine callback

The refine callback receives generator functions including: fullName(), firstName(), lastName(), companyName(), jobTitle(), streetAddress(), city(), state(), country(), postcode(), phoneNumber(template), date(minDate, maxDate), loremIpsum(), int(minValue, maxValue, isUnique), number(minValue, maxValue, precision), valuesFromArray(values), weightedRandom(array), and default(defaultValue).

drizzle-seed generates deterministic fake data using seedable pRNG

drizzle-seed is a TypeScript library that generates deterministic, yet realistic, fake data for database population. It uses a seedable pseudorandom number generator (pRNG) to ensure consistent and reproducible data generation. The same seed input will always produce the same output, enabling predictable and repeatable data sets across different runs.

weightedRandom() for with option uses weight and count range

The weightedRandom for the with property uses objects with weight (probability) and count (array of possible counts as range). Example: details: [{ weight: 0.6, count: [1, 2, 3] }, { weight: 0.3, count: [5, 6, 7] }, { weight: 0.1, count: [8, 9, 10] }].

with option only works for one-to-many relationships

The with option in refine works only for one-to-many relationships. For example, you can use users with posts (one user has many posts), but cannot use posts with users (many posts cannot have one user). This is a TypeScript limitation preventing circular dependency inference.

int() generator with isUnique option creates unique values

The int() generator function accepts minValue, maxValue, and isUnique properties. Setting isUnique to true ensures generated integers remain unique across rows. Example: f.int({ minValue: 10000, maxValue: 20000, isUnique: true }).

valuesFromArray() generator picks from predefined values

The valuesFromArray generator accepts a values array and randomly selects from it. Example: f.valuesFromArray({ values: ['value1', 'value2', 'value3'] }).

default() generator uses database default value for column

The default() generator allows the database to use its default value for a column instead of generating data. Example: f.default({ defaultValue: 0 }).

phoneNumber() generator accepts template with # placeholders

The phoneNumber() generator accepts a template string where # represents digit positions. Example: f.phoneNumber({ template: '(###) ###-####' }) generates phone numbers like (123) 456-7890.

date() generator accepts minDate and maxDate in YYYY-MM-DD format

The date() generator accepts minDate and maxDate strings in YYYY-MM-DD format to generate dates within a range. Example: f.date({ minDate: '2010-12-31', maxDate: '2024-08-26' }).

number() generator accepts precision parameter

The number() generator for decimal/floating-point values accepts minValue, maxValue, and precision properties. The precision determines decimal places. Example: f.number({ minValue: 0, maxValue: 1000, precision: 100 }).

drizzle-seed refine columns property excludes columns with false

In refine, setting a column to false excludes it from seeding, allowing the database to use its default value. Example: columns: { name: false } skips generating values for the name column.

drizzle-seed generator versioning under the hood

Individual generators have their own versions. When a generator is updated, a new version becomes available (e.g., LastNameGenV1, LastNameGenV2). When you specify a version number for the seed function, it uses the latest available version of each generator up to that version number. For example, with version '2', if FirstNameGen has version 3 available and LastNameGen only has version 2 available, it uses FirstNameGenV1 and LastNameGenV2.

Give your agent this brain