Skip to content

reeceyang/convex-schema-mermaid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Generate a Mermaid flowchart from a Convex schema

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published