npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lucid-dreams

v1.0.12

Published

A CLI to convert a Lucidchart ERD to a Prisma schema file

Downloads

85

Readme

Overview

Lucidchart allows you to create an Entity Relationship Diagram (ERD), which is a great way to visualize and mange your database schema. It also allows you to export your ERD as a "CSV of Shape Data" .csv file.

Prisma is an ORM for Node.js and TypeScript, and it's been an awesome developer experience for me personally.

This command line interface (CLI) will take a Lucidchart "CSV of Shape Data" file as input, and output a Prisma Schema file 😎. Before the schema.prisma file is generated, prisma format is run against the file which will:

Format the Prisma schema file, which includes validating, formatting, and persisting the schema. | Source

Much love to the Prisma team 💙

Installation

npm install lucid-dreams

Usage

npx lucid-dreams --prisma ~/path/to/lucidchart/data.csv
npx lucid-dreams -p ~/path/to/data.csv

The --prisma (or -p) flag means we will convert the Entity Relationship Diagram to a schema.prisma file.

Supported fields

Note: If you have a Lucidchart field called id the "@id @default(autoincrement())" attribute will automatically be included 😎 | More info on autoincrement()

Required or mandatory fields

By default, your field will be a mandatory field in the generated schema.prisma file. Lucidchart fields are converted to the following Prisma model field scalar types:

| Lucidchart field | Prisma model field scalar types | Resources | | ---------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------- | | uuid / id | String @id @default(uuid()) | uuid() | | int | Int | autoIncrement() | | varchar(100) | String @db.VarChar(100) | varChar(x) | | char(245) | String @db.Char(245) | char(x) | | datetime | DateTime | | | date | DateTime | | | time | DateTime | | | timestamp | DateTime | | | bool | Boolean | | | boolean | Boolean | |

Optional fields

Optional Lucidchart fields can be represented with the ? or (null) modifiers. If either of those modifiers exist in the Lucidchart field, the field will be modified with the ? Prisma Type modifier making it optional:

| Lucidchart field | Prisma model field scalar types | | ---------------------------------- | ------------------------------- | | int? / int(null) | Int? | | varchar(100)? / varchar(100)(null) | String? @db.VarChar(100) | | char(245)? / char(245)(null) | String? @db.Char(245) | | datetime? / datetime(null) | DateTime? | | date? / date(null) | DateTime? | | time? / time(null) | DateTime? | | timestamp? / timestamp(null) | DateTime? | | bool? / bool(null) | Boolean? | | boolean? / boolean(null) | Boolean? |

Supported Lucidchart Shapes

Entity Relationship (2 columns)

Create a 2 column Shape in your Lucidchart ERD.

Shape Structure

The label in the header section of the Lucidchart Shape will be the table name, or the name of the resulting Prisma model. The first column should be the database column name (prisma field), and the second column should be it's field.

Example

Here is an example Lucidchart Entity Relationship Diagram with a two column structure. The first column is the database column name (prisma field), and the second column is the field. The field column is case insensitive, and can contain the modifiers ? or (null) to make it optional. The image below includes various examples of fields using both ? and (null) modifiers:

Lucid chart entity relationship diagram with various examples of fields using both ? and null modifiers

  1. This chart would then be exported from Lucidchart like this: File > Export > CSV of Shape Data. Let's say we saved it as /Downloads/data.csv for example.

  2. We can now run the lucid-dreams CLI with the -p flag and specify the path to the file we just exported:

    npx lucid-dreams -p /Downloads/data.csv
  3. The lucid-dreams CLI will take the models from Lucidchart and convert them to Prisma models. The generated schema.prisma file will contain the following:

    datasource db {
      url      = env("DATABASE_URL")
      provider = "postgresql"
    }
    
    generator client {
      provider = "prisma-client-js"
    }
    
    model Challenge {
      id          String   @id @default(uuid())
      time        DateTime
      location    String   @db.VarChar(50)
      accepted    Boolean?
      notes       String
      description String
      startTime   DateTime
      endDate     DateTime
      createdDate DateTime
    }
    
    model Rank {
      id            String       @id @default(uuid())
      position      Int
      description   String?      @db.VarChar(100)
      notes         String?      @db.Char(100)
      Leaderboard   Leaderboard? @relation(fields: [leaderboardId], references: [id])
      leaderboardId Int?
    }
    
    model Member {
      id        Int     @id @default(autoincrement())
      firstName String  @db.VarChar(100)
      lastName  String? @db.Char(245)
      nickname  String? @db.VarChar(50)
      age       Int?
      code      Int?
    }
    
    model Group {
      id           Int       @id @default(autoincrement())
      name         String
      description  String
      birthday     DateTime?
      halfBirthday DateTime?
      accepted     Boolean?
    }
    
    model Leaderboard {
      id    Int    @id @default(autoincrement())
      ranks Rank[]
    }