convex-schema-mermaid
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

convex-schema-mermaid

Generate a Mermaid flowchart from a Convex schema

Install the package from NPM:

npm i convex-schema-mermaid

Import the schemaToMermaid function and pass in your schema:

import { schemaToMermaid } from "convex-schema-mermaid";

const schema = defineSchema({
  messages: defineTable({
    authorId: v.id("users"),
  }),
  users: defineTable({
    name: v.string(),
    age: v.number(),
    teamId: v.id("teams"),
  }),
  teams: defineTable({
    name: v.string(),
  }),
});
console.log(schemaToMermaid(schema));

// flowchart LR
//   subgraph messages
//     messages.authorId[authorId: id 'users']
//   end
//   subgraph users
//     users.name[name: string]
//     users.age[age: number]
//     users.teamId[teamId: id 'teams']
//   end
//   subgraph teams
//     teams.name[name: string]
//   end
//   messages.authorId-->users
//   users.teamId-->teams

To use with your Convex project, you can place the console.log(schemaToMermaid(schema)) inside a Convex function and then run that function from the Convex dashboard.

You can also run this one-liner from the root directory of your project, which will bundle and run your schema with a script to print the mermaid output:

echo "import s from './convex/schema';import {schemaToMermaid} from 'convex-schema-mermaid';console.log(schemaToMermaid(s))" | npx esbuild --bundle | node

Readme

Keywords

Package Sidebar

Install

npm i convex-schema-mermaid

Weekly Downloads

0

Version

0.3.1

License

ISC

Unpacked Size

10 kB

Total Files

4

Last publish

Collaborators

  • reeceyang