nest-resource

0.0.18 • Public • Published

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

[//]: # (table)

alias command description
rs / resource nest g -c nest-resource rs Generate full resource with module file
dt / dto nest g -c nest-resource dt Generate DTO file only with given name
mg / migration nest g -c nest-resource mg Generate migration file only with given name
et / entity nest 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[];
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.180latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.180
0.0.170
0.0.160
0.0.150
0.0.140
0.0.130
0.0.120
0.0.110
0.0.100
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i nest-resource

Weekly Downloads

0

Version

0.0.18

License

MIT

Unpacked Size

71.8 kB

Total Files

73

Last publish

Collaborators

  • mandhu