Become a Gold Sponsor

Generators

---

default

Generates the same given value each time the generator is called.

paramdefaulttype
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

paramdefaulttype
valuesβ€”any[] | { weight: number; values: any[] }[]
isUniquedatabase column uniquenessboolean
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.

paramdefaulttype
β€”β€”β€”
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

paramdefaulttype
isUniquedatabase column uniquenessboolean
precision100number
maxValue `precision * 1000` if isUnique equals false `precision * count` if isUnique equals truenumber
minValue-maxValuenumber
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

paramdefaulttype
isUniquedatabase column uniquenessboolean
maxValue `1000` if isUnique equals false `count * 10` if isUnique equals truenumber | bigint
minValue-maxValuenumber | 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

paramdefaulttype
β€”β€”β€”
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)

paramdefaulttype
β€”β€”β€”
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

paramdefaulttype
minDatenew Date('2020-05-08')string | Date
maxDatenew 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

paramdefaulttype
β€”β€”β€”
import { seed } from "drizzle-seed";

await seed(db, schema, { count: 1000 }).refine((funcs) => ({
  users: {
    columns: {
      birthTime: funcs.time(),
    },
  },
}));

timestamp

Generates timestamps

paramdefaulttype
β€”β€”β€”
import { seed } from "drizzle-seed";

await seed(db, schema, { count: 1000 }).refine((funcs) => ({
  orders: {
    columns: {
      shippedDate: funcs.timestamp(),
    },
  },
}));

datetime

Generates datetime objects

paramdefaulttype
β€”β€”β€”
import { seed } from "drizzle-seed";

await seed(db, schema, { count: 1000 }).refine((funcs) => ({
  orders: {
    columns: {
      shippedDate: funcs.datetime(),
    },
  },
}));

year

Generates years in YYYY format

paramdefaulttype
β€”β€”β€”
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

paramdefaulttype
β€”β€”β€”
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

paramdefaulttype
isUniquecolumn uniquenessboolean
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

paramdefaulttype
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

paramdefaulttype
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

paramdefaulttype
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

paramdefaulttype
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

paramdefaulttype
β€”β€”β€”
import { seed } from "drizzle-seed";

await seed(db, schema, { count: 1000 }).refine((funcs) => ({
  users: {
    columns: {
      email: funcs.email(),
    },
  },
}));

phoneNumber

Generates unique phone numbers

paramdefaulttype
templateβ€”string
prefixesUsed dataset for prefixesstring[]
generatedDigitsNumbers7 - if prefixes was definednumber | 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

paramdefaulttype
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

paramdefaulttype
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

paramdefaulttype
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

paramdefaulttype
β€”β€”β€”
import { seed } from "drizzle-seed";

await seed(db, schema, { count: 1000 }).refine((funcs) => ({
  users: {
    columns: {
      jobTitle: funcs.jobTitle(),
    },
  },
}));

postcode

Generates postal codes

paramdefaulttype
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

paramdefaulttype
β€”β€”β€”
import { seed } from "drizzle-seed";

await seed(db, schema, { count: 1000 }).refine((funcs) => ({
  users: {
    columns: {
      state: funcs.state(),
    },
  },
}));

companyName

Generates random company’s names

paramdefaulttype
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.

paramdefaulttype
sentencesCount1number
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.

paramdefaulttype
isUniquedatabase column uniquenessboolean
maxXValue `10 * 1000` if isUnique equals false `10 * count` if isUnique equals truenumber
minXValue-maxXValuenumber
maxYValue `10 * 1000` if isUnique equals false `10 * count` if isUnique equals truenumber
minYValue-maxYValuenumber
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
paramdefaulttype
isUniquedatabase column uniquenessboolean
maxAValue `10 * 1000` if isUnique equals false `10 * count` if isUnique equals truenumber
minAValue-maxAValuenumber
maxBValue `10 * 1000` if isUnique equals false `10 * count` if isUnique equals truenumber
minBValue-maxBValuenumber
maxCValue `10 * 1000` if isUnique equals false `10 * count` if isUnique equals truenumber
minCValue-maxCValuenumber
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,
      }),
    },
  },
}));