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

crudify-dtu

v1.2.13

Published

<div id="top"></div>

Downloads

13

Readme

About The Project

CRUDify is a command-line tool to kickstart a backend project by just providing an ER Diagram. The user needs to create a database schema in JSON format and then install the package. Next step is to invoke the package from the command line and pass the name of the schema file along with it. This creates a backend project with the corresponding database schema file for Prisma ORM. Further, it also contains all the endpoints for CRUD operations for all database tables.

Installation

Install the NPM package

yarn add crudify-dtu
npm i crudify-dtu

Installation - Local Development

Install the dependencies

yarn install

Build the project in watch mode

yarn build -w

In a separate terminal, run the project

yarn dev

How To Use

Consider the following ER Diagram

Shown below will be the corresponding schema for CRUDify

{
  "Models": [
    {
      "name": "user",
      "attributes": {
        "StaticFields": [
          {
            "name": "email",
            "type": "String",
            "isUnique": true,
            "faker": {
              "module": "internet",
              "method": "email"
            }
          },
          {
            "name": "password",
            "type": "String",
            "toBeHashed": true,
            "faker": {
              "module": "internet",
              "method": "password"
            }
          },
          {
            "name": "name",
            "type": "String"
          }
        ],
        "RelationalFields": []
      }
    },
    {
      "name": "blog",
      "attributes": {
        "StaticFields": [
          {
            "name": "title",
            "type": "String"
          },
          {
            "name": "content",
            "type": "String"
          }
        ],
        "RelationalFields": [
          {
            "connection": "user",
            "foriegnKeyName": "id",
            "type": "ONETOMANY"
          }
        ]
      }
    },
    {
      "name": "review",
      "attributes": {
        "StaticFields": [
          {
            "name": "title",
            "type": "String"
          },
          {
            "name": "content",
            "type": "String"
          }
        ],
        "RelationalFields": [
          {
            "connection": "user",
            "foriegnKeyName": "id",
            "type": "ONETOMANY"
          },
          {
            "connection": "blog",
            "foriegnKeyName": "id",
            "type": "ONETOMANY"
          }
        ]
      }
    }
  ],
  "Authentication": {
    "model": "user",
    "userFieldName": "email",
    "passwordFieldName": "password"
  }
}

Create a .env file at the root of the app and copy the content of .example.env file into it. Then, add your PostgreSQL username and password and replace the database name starter with a name of your choice. After creating the .env file, run the following commands:

yarn install
yarn prisma migrate dev
yarn build
yarn dev

Syntax For Creating JSON Schema File

{
  "Models": [
    {
      "name": "MODEL_NAME",
      "softDelete": false/true, // It is an optional field with default value as true
      "attributes": {
        "StaticFields": [
          {
            "name": "FIELD_NAME",
            "type": "FIELD_TYPE",
            "isUnique": true,
            "toBeHashed": true,
            "faker": {
              "module": "MODULE_NAME",
              "method": "FUNCTION_NAME"
            }
          }
        ],
        "RelationalFields": [
          {
            "connection": "RELATED_TABLE_NAME",
            "foriegnKeyName": "id",
            "type": "CONNECTION_TYPE"
          }
        ]
      }
    }
  ],
  "Enums": [
    {
      "name": "ENUM_NAME",
      "fields": ["SAMPLE_FIELD1", "SAMPLE_FIELD2"]
    }
  ],
  "Authentication": {
    "model": "YOUR_USER_MODEL_NAME",
    "userFieldName": "YOUR_USERNAME_FIELD_NAME",
    "passwordFieldName": "YOUR_PASSWORD_FIELD_NAME"
  }
}

MODEL_NAME: Name of the table (must be lowercase) softDelete: False if you don't want soft deletes enabled on a particular model. See more about soft deletes here. StaticFields: Array of JSON objects with each object representing a non-relational field FIELD_NAME: Name of the field (must be lowercase) FIELD_TYPE: Type of the field (can be either String , Boolean , Int , BigInt , Float , Decimal , DateTime , Json) isUnique: Boolean that signifies whether the unique constraint should be applied to the field. Defaults to false, so can be omitted. toBeHashed: Boolean that signifies whether the field's value should be hashed before saving to the database. Defaults to false, so can be omitted. faker: Object representing the type of seed (fake) data that should be generated for the field. It is optional module: Name of the module (e.g. lorem) from https://fakerjs.dev/api/ method: Name of the function to be called for the provided module [e.g. word (for lorem module)] from https://fakerjs.dev/api/ RelationalFields: Array of JSON objects with each object representing a relational field RELATED_TABLE_NAME: Name of the table to which you want to create a relation to foriegnKeyName: Name of the field in the RELATED_TABLE_NAME table which should be made the foreign key. It should be set as id to set the default auto-generated primary key of the RELATED_TABLE_NAME table as the foreign key CONNECTION_TYPE: Can be either ONETOMANY or ONETOONE. In the case of ONETOMANY connection, one record in RELATED_TABLE_NAME will be related to many MODEL_NAME records Enums: Specify to use enums in your database. See more about enums and their usage here USER AUTHENTICATION DETAILS Authentication: An object containing information regarding user authentication. It is optional and should be added only if user authentication API endpoints are required (login and getCurrentUser currently) model: Name of the user model defined previously (case-sensitive) userFieldName: Name of the field in the user model corresponding to username (Must be a unique field) passwordFieldName: Name of the field in the user model corresponding to password

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Naman Gogia - Linkedin - [email protected] Abhinandan Sharma - Linkedin - [email protected]