1.2.13 • Published 1 year ago

crudify-dtu v1.2.13

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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 - namangogia2001@gmail.com Abhinandan Sharma - Linkedin - abhi.moudgil15@gmail.com

1.2.13

1 year ago

1.2.12

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.0.9

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.2.1

2 years ago

1.1.2

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago