Generators
---
default
Generates the same given value each time the generator is called.
param default type defaultValue
β any
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
posts : {
columns : {
content : funcs .default ({
// value you want to generate
defaultValue : "post content"
}) ,
} ,
} ,
}));
valuesFromArray
Generates values from given array
param default type values
β any[]
| { weight: number; values: any[] }[]
isUnique
database column uniqueness boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
posts : {
columns : {
title : funcs .valuesFromArray ({
// Array of values you want to generate (can be an array of weighted values)
values : [ "Title1" , "Title2" , "Title3" , "Title4" , "Title5" ] ,
// Property that controls whether the generated values will be unique or not
isUnique : true ,
}) ,
} ,
} ,
}));
intPrimaryKey
Generates sequential integers starting from 1.
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
posts : {
columns : {
id : funcs .intPrimaryKey () ,
} ,
} ,
}));
number
Generates numbers with a floating point within the given range
param default type isUnique
database column uniqueness boolean
precision
100
number
maxValue
`precision * 1000` if isUnique equals false
`precision * count` if isUnique equals true
number
minValue
-maxValue
number
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
products : {
columns : {
unitPrice : funcs .number ({
// lower border of range.
minValue : 10 ,
// upper border of range.
maxValue : 120 ,
// precision of generated number:
// precision equals 10 means that values will be accurate to one tenth (1.2, 34.6);
// precision equals 100 means that values will be accurate to one hundredth (1.23, 34.67).
precision : 100 ,
// property that controls if generated values gonna be unique or not.
isUnique : false ,
}) ,
} ,
} ,
}));
int
Generates integers within the given range
param default type isUnique
database column uniqueness boolean
maxValue
`1000` if isUnique equals false
`count * 10` if isUnique equals true
number | bigint
minValue
-maxValue
number | bigint
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
products : {
columns : {
unitsInStock : funcs .int ({
// lower border of range.
minValue : 0 ,
// lower border of range.
maxValue : 100 ,
// property that controls if generated values gonna be unique or not.
isUnique : false ,
}) ,
} ,
} ,
}));
uuid
Generates v4 UUID strings
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
products : {
columns : {
id : funcs .uuid () ,
} ,
} ,
}));
boolean
Generates boolean values (true or false)
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
isAvailable : funcs .boolean () ,
} ,
} ,
}));
date
Generates a date within the given range
param default type minDate
new Date('2020-05-08')
string | Date
maxDate
new Date('2028-05-08')
string | Date
IMPORTANT
If only one of the parameters (minDate
or maxDate
) is provided, the unspecified parameter will be calculated by adding or subtracting 8 years to/from the specified one
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
birthDate : funcs .date ({
// lower border of range.
minDate : "1990-01-01" ,
// upper border of range.
maxDate : "2010-12-31"
}) ,
} ,
} ,
}));
time
Generates time in 24-hour format
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
birthTime : funcs .time () ,
} ,
} ,
}));
timestamp
Generates timestamps
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
orders : {
columns : {
shippedDate : funcs .timestamp () ,
} ,
} ,
}));
datetime
Generates datetime objects
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
orders : {
columns : {
shippedDate : funcs .datetime () ,
} ,
} ,
}));
year
Generates years in YYYY
format
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
birthYear : funcs .year () ,
} ,
} ,
}));
json
Generates JSON objects with a fixed structure
{ email , name , isGraduated , hasJob , salary , startedWorking , visitedCountries}
// or
{ email , name , isGraduated , hasJob , visitedCountries }
The JSON structure will be picked randomly
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
metadata : funcs .json () ,
} ,
} ,
}));
interval
Generates time intervals.
Example of a generated value: 1 year 12 days 5 minutes
param default type isUnique
column uniqueness boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
timeSpentOnWebsite : funcs .interval ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : true
}) ,
} ,
} ,
}));
string
Generates random strings
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
hashedPassword : funcs .string ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : false
}) ,
} ,
} ,
}));
firstName
Generates a personβs first name
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
firstName : funcs .firstName ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : true
}) ,
} ,
} ,
}));
lastName
Generates a personβs last name
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
lastName : funcs .lastName ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : false
}) ,
} ,
} ,
}));
fullName
Generates a personβs full name
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
fullName : funcs .fullName ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : true
}) ,
} ,
} ,
}));
email
Generates unique email addresses
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
email : funcs .email () ,
} ,
} ,
}));
phoneNumber
Generates unique phone numbers
param default type template
β string
prefixes
Used dataset for prefixes string[]
generatedDigitsNumbers
7
- if prefixes was defined
number | number[]
import { seed } from "drizzle-seed" ;
//generate phone number using template property
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
phoneNumber : funcs .phoneNumber ({
// `template` - phone number template, where all '#' symbols will be substituted with generated digits.
template : "+(380) ###-####"
}) ,
} ,
} ,
}));
import { seed } from "drizzle-seed" ;
//generate phone number using prefixes and generatedDigitsNumbers properties
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
phoneNumber : funcs .phoneNumber ({
// `prefixes` - array of any string you want to be your phone number prefixes.(not compatible with `template` property)
prefixes : [ "+380 99" , "+380 67" ] ,
// `generatedDigitsNumbers` - number of digits that will be added at the end of prefixes.(not compatible with `template` property)
generatedDigitsNumbers : 7 ,
}) ,
} ,
} ,
}));
import { seed } from "drizzle-seed" ;
// generate phone number using prefixes and generatedDigitsNumbers properties but with different generatedDigitsNumbers for prefixes
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
phoneNumber : funcs .phoneNumber ({
// `prefixes` - array of any string you want to be your phone number prefixes.(not compatible with `template` property)
prefixes : [ "+380 99" , "+380 67" , "+1" ] ,
// `generatedDigitsNumbers` - number of digits that will be added at the end of prefixes.(not compatible with `template` property)
generatedDigitsNumbers : [ 7 , 7 , 10 ] ,
}) ,
} ,
} ,
}));
country
Generates countryβs names
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
country : funcs .country ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : false
}) ,
} ,
} ,
}));
city
Generates cityβs names
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
city : funcs .city ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : false
}) ,
} ,
} ,
}));
streetAddress
Generates street address
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
streetAddress : funcs .streetAddress ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : false
}) ,
} ,
} ,
}));
jobTitle
Generates job titles
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
jobTitle : funcs .jobTitle () ,
} ,
} ,
}));
postcode
Generates postal codes
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
postcode : funcs .postcode ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : true
}) ,
} ,
} ,
}));
state
Generates US states
param default type β β β
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
state : funcs .state () ,
} ,
} ,
}));
companyName
Generates random companyβs names
param default type isUnique
- boolean
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
users : {
columns : {
company : funcs .companyName ({
// `isUnique` - property that controls whether the generated values will be unique or not
isUnique : true
}) ,
} ,
} ,
}));
loremIpsum
Generates lorem ipsum
text sentences.
param default type sentencesCount
1 number
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
posts : {
columns : {
content : funcs .loremIpsum ({
// `sentencesCount` - number of sentences you want to generate as one generated value(string).
sentencesCount : 2
}) ,
} ,
} ,
}));
point
Generates 2D points within specified ranges for x and y coordinates.
param default type isUnique
database column uniqueness boolean
maxXValue
`10 * 1000` if isUnique equals false
`10 * count` if isUnique equals true
number
minXValue
-maxXValue
number
maxYValue
`10 * 1000` if isUnique equals false
`10 * count` if isUnique equals true
number
minYValue
-maxYValue
number
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
triangles : {
columns : {
pointCoords : funcs .point ({
// `isUnique` - property that controls if generated values gonna be unique or not.
isUnique : true ,
// `minXValue` - lower bound of range for x coordinate.
minXValue : - 5 ,
// `maxXValue` - upper bound of range for x coordinate.
maxXValue : 20 ,
// `minYValue` - lower bound of range for y coordinate.
minYValue : 0 ,
// `maxYValue` - upper bound of range for y coordinate.
maxYValue : 30 ,
}) ,
} ,
} ,
}));
line
Generates 2D lines within specified ranges for a, b and c parameters of line.
line equation: a*x + b*y + c = 0
param default type isUnique
database column uniqueness boolean
maxAValue
`10 * 1000` if isUnique equals false
`10 * count` if isUnique equals true
number
minAValue
-maxAValue
number
maxBValue
`10 * 1000` if isUnique equals false
`10 * count` if isUnique equals true
number
minBValue
-maxBValue
number
maxCValue
`10 * 1000` if isUnique equals false
`10 * count` if isUnique equals true
number
minCValue
-maxCValue
number
import { seed } from "drizzle-seed" ;
await seed (db , schema , { count : 1000 }) .refine ((funcs) => ({
lines : {
columns : {
lineParams : funcs .point ({
// `isUnique` - property that controls if generated values gonna be unique or not.
isUnique : true ,
// `minAValue` - lower bound of range for a parameter.
minAValue : - 5 ,
// `maxAValue` - upper bound of range for x parameter.
maxAValue : 20 ,
// `minBValue` - lower bound of range for y parameter.
minBValue : 0 ,
// `maxBValue` - upper bound of range for y parameter.
maxBValue : 30 ,
// `minCValue` - lower bound of range for y parameter.
minCValue : 0 ,
// `maxCValue` - upper bound of range for y parameter.
maxCValue : 10 ,
}) ,
} ,
} ,
}));