PDConSec / vsc-print

Completely local print support for VS Code with syntax-colouring and line numbering
Other
70 stars 28 forks source link

Database diagram support #340

Closed PeterWone closed 6 days ago

PeterWone commented 2 months ago
  1. Extend the handling of fenced block languages to include "database"
  2. Parse the content of the fenced block as YAML
  3. Use the parsed values to extract schema information from a live database and generate source for a Mermaid entity relationship diagram.
  4. Render the generated Mermaid diagram as SVG
  5. Based on the method used for Kroki diagrams add caching

For step 2, parse YAML like so. token.text gives you everything between the fences.


          case "PUSH":
            resolvedConfig = yaml.parse(token.text);
            stack.push(resolvedConfig);
            break;

The YAML parser is already in scope unless you break out the logic into a new file in which case you can import like so:

import * as yaml from "yaml";

Sample

```database
DatabaseType: postgresql
ConnectionString: Host=localhost;Port=5432;Database=mydatabase;Username=user;Password=secret
Schema: public
Tables: 
  - Offers
  - Orders
  - Passes
Detail: column names


## DatabaseType

- postgresql
- mssql

## ConnectionString

A dotnet database connection string. Depending on your setup you may need to embed the password. In that case create a user with permissions limited to reading the schema details.

## Schema

The schema containing the tables to be diagrammed. When this item is omitted, the Postgres default is `public` and the MSSQL default is `dbo`.

## Tables

A list of the tables you want in the diagram. When this item is omitted, the default is all the tables.

## Detail
Supported values in decreasing level of detail are

- column types
- column names
- key column names
- table name

When this item is omitted, the default is column names.
abdiukov commented 2 months ago

That looks like a great first issue. (as discussed offline) I will pick it up and let's see how it goes!

abdiukov commented 2 months ago

I created a fork to work on this; here it is https://github.com/abdiukov/vsc-print-340.

Do you have any preferences for which db driver/library is better to use?