Framework

Seed SvelteKit + Drizzle with Realistic Test Data

Script

// scripts/seed.ts
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import { users, posts } from "../src/lib/server/schema";

const db = drizzle(postgres(process.env.DATABASE_URL!));

const data = await fetch("https://api.mockhero.dev/api/v1/generate", {
  method: "POST",
  headers: { "x-api-key": process.env.MOCKHERO_API_KEY!, "Content-Type": "application/json" },
  body: JSON.stringify({
    tables: [
      { name: "users", count: 25, fields: [
        { name: "id", type: "uuid" },
        { name: "email", type: "email" }
      ]},
      { name: "posts", count: 120, fields: [
        { name: "id", type: "uuid" },
        { name: "author_id", type: "ref", ref: "users.id" },
        { name: "title", type: "sentence" }
      ]}
    ]
  })
}).then(r => r.json());

await db.insert(users).values(data.users);
await db.insert(posts).values(data.posts);

Run with tsx scripts/seed.ts.

Get Started

Get your free key.

M

MockHero Team

Guides and tutorials for generating realistic test data with the MockHero API.

Start generating test data for free

1,000 rows/month on the free tier. No credit card required.

Get Your API Key

Related Articles