Framework

Seed Astro + Turso (LibSQL) with MockHero

Script

// scripts/seed.mjs
import { createClient } from "@libsql/client";

const turso = createClient({
  url: process.env.TURSO_DATABASE_URL,
  authToken: process.env.TURSO_AUTH_TOKEN,
});

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({
    format: "sql",
    dialect: "sqlite",
    tables: [
      { name: "authors", count: 15, fields: [
        { name: "id", type: "uuid" },
        { name: "name", type: "full_name" }
      ]},
      { name: "articles", count: 150, fields: [
        { name: "id", type: "uuid" },
        { name: "author_id", type: "ref", ref: "authors.id" },
        { name: "title", type: "sentence" }
      ]}
    ]
  })
}).then(r => r.text());

for (const stmt of data.split(";").filter(Boolean)) {
  await turso.execute(stmt);
}

Get Started

Create a free account.

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