https://github.com/reeceyang/convex-schema-mermaid
Generate a Mermaid flowchart from a Convex schema
https://github.com/reeceyang/convex-schema-mermaid
convex mermaid
Last synced: over 1 year ago
JSON representation
Generate a Mermaid flowchart from a Convex schema
- Host: GitHub
- URL: https://github.com/reeceyang/convex-schema-mermaid
- Owner: reeceyang
- Created: 2024-06-01T03:37:50.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-03T03:38:09.000Z (about 2 years ago)
- Last Synced: 2025-03-29T06:01:34.863Z (over 1 year ago)
- Topics: convex, mermaid
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/convex-schema-mermaid
- Size: 45.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# convex-schema-mermaid
Generate a Mermaid flowchart from a Convex schema
Install the package from NPM:
```sh
npm i convex-schema-mermaid
```
Import the `schemaToMermaid` function and pass in your schema:
```ts
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:
```sh
echo "import s from './convex/schema';import {schemaToMermaid} from 'convex-schema-mermaid';console.log(schemaToMermaid(s))" | npx esbuild --bundle | node
```