0.0.18 • Published 1 year ago

nest-resource v0.0.18

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

Nest Resource Schematics

Installation

$ npm install nest-resource

Usage

Create folder and files

- Create "schemas" folder root of the project

- All schema files should be in "schemas" folder

Schema File

sample schema file: schemas/cargo.json

{
  "modelName": "Cargo",
  "api": "cargos",
  "fields": [
    {
      "name": "quantity",
      "type": "number",
      "dbType": {
        "allowNull": false,
        "autoIncrement": true,
        "primaryKey": true,
        "type": "INTEGER"
      },
      "dto": [
        "IsNotEmpty", "IsString"
      ]
    },
    {
      "name": "description",
      "type": "string",
      "dbType": {
        "allowNull": false,
        "type": "STRING"
      },
      "dto": [
        "IsNotEmpty"
      ]
    },
    {
      "name": "remarks",
      "type": "string"
    }
  ],
  "indexes": [
    "description"
  ]
}

Generate Resource

if schema args not provided, file name and model name should be same

nest g -c nest-resource rs <model-name> OR

nest g -c nest-resource rs <model-name> --schema=[file name without .json]

Available Commands

aliascommanddescription
rs / resourcenest g -c nest-resource rs Generate full resource with module file
dt / dtonest g -c nest-resource dt Generate DTO file only with given name
mg / migrationnest g -c nest-resource mg Generate migration file only with given name
et / entitynest g -c nest-resource et Generate entity file only with given name

Database Type Mapping

lowercase also supported

[
  'ABSTRACT',
  'STRING',
  'CHAR',
  'TEXT',
  'NUMBER',
  'TINYINT',
  'SMALLINT',
  'MEDIUMINT',
  'INTEGER',
  'BIGINT',
  'FLOAT',
  'TIME',
  'DATE',
  'DATEONLY',
  'BOOLEAN',
  'NOW',
  'BLOB',
  'DECIMAL',
  'NUMERIC',
  'UUID',
  'UUIDV1',
  'UUIDV4',
  'HSTORE',
  'JSON',
  'JSONB',
  'VIRTUAL',
  'ARRAY',
  'NONE',
  'ENUM',
  'RANGE',
  'REAL',
  'DOUBLE',
  'DOUBLE PRECISION',
  'GEOMETRY',
];

Types

export interface SchemaModel {
  modelName: string;
  api: string;
  fields: Field[];
  indexes?: string[];
}

export interface Field {
  name: string;
  type: string;
  dbType?: { [key: string]: any };
  dto?: string[];
}
0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago