{"id":21843646,"url":"https://github.com/tasmidur/nodejs-schema-rules","last_synced_at":"2026-04-16T19:05:08.390Z","repository":{"id":220277109,"uuid":"751199321","full_name":"tasmidur/nodejs-schema-rules","owner":"tasmidur","description":"Dynamic NodeJS Schema Validation Rules Generator","archived":false,"fork":false,"pushed_at":"2024-02-03T16:40:26.000Z","size":663,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-13T02:59:42.156Z","etag":null,"topics":["mysql","postgres","schema","validation-library","validation-tool"],"latest_commit_sha":null,"homepage":"https://tasmidur.medium.com/dynamic-nodejs-schema-validation-rules-generator-ca2afb8b59c5","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tasmidur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-01T05:57:51.000Z","updated_at":"2024-02-03T13:23:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"986b2189-2221-424f-82af-8b8da81563db","html_url":"https://github.com/tasmidur/nodejs-schema-rules","commit_stats":{"total_commits":32,"total_committers":2,"mean_commits":16.0,"dds":0.4375,"last_synced_commit":"92a816c607878b4a60f80858266d4e0fa9e6f515"},"previous_names":["tasmidur/nodejs-validation-schema-rules"],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/tasmidur/nodejs-schema-rules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tasmidur%2Fnodejs-schema-rules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tasmidur%2Fnodejs-schema-rules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tasmidur%2Fnodejs-schema-rules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tasmidur%2Fnodejs-schema-rules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tasmidur","download_url":"https://codeload.github.com/tasmidur/nodejs-schema-rules/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tasmidur%2Fnodejs-schema-rules/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28846767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mysql","postgres","schema","validation-library","validation-tool"],"created_at":"2024-11-27T22:16:00.416Z","updated_at":"2026-01-28T16:03:52.657Z","avatar_url":"https://github.com/tasmidur.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NodeJS Schema Rules\n\n[![NPM Downloads](https://img.shields.io/npm/dw/nodejs-schema-rules)](https://www.npmjs.com/package/nodejs-schema-rules)\n[![npm](https://img.shields.io/npm/v/nodejs-schema-rules)](https://www.npmjs.com/package/nodejs-schema-rules)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThe CLI tool automatically generates basic validation rules for popular libraries such as [JOI](https://www.npmjs.com/package/joi),    [ValidatorJS](https://www.npmjs.com/package/validatorjs) and [@vinejs/vine](https://www.npmjs.com/package/@vinejs/vine) rules based on your database table schema. These rules serve as a convenient starting point, allowing you to refine and enhance them to suit your specific needs.\n\n\n## Installation\nInstalling nodejs-schema-rules globally to access `ndVr` CLI \n```bash\nnpm install nodejs-schema-rules -g\nyarn add global nodejs-schema-rules\n```\nThen run `ndVr init` for initialization of  `schema.config.js` file then modify as your requirement.\n\n```bash\nndVr init\n```\n\nModify the `schema.config.js`\n\n```javascript\nrequire(\"dotenv\").config();\nconst schemaConfig = {\n  defaultDatabase: 'sqlite',\n  databases: {\n    postgres: {\n      host: 'localhost',\n      port: 5432,\n      user: 'postgres',\n      password: '123456',\n      database: 'testing'\n    },\n    mysql: {\n      host: 'localhost',\n      port: 3306,\n      user: 'root',\n      password: '123456',\n      database: 'schema_builder'\n    },\n    sqlite: { database: './schema_builder.db' }\n  },\n  skipColumns: [ 'created_at', 'updated_at', 'deleted_at' ],\n  validationSchemaType: 'joi'\n};\nmodule.exports = schemaConfig;\n```\n\n## Usage\n\n  The `ndVr joi -t my_table -db mysql -c column1,column2` command generates validation rules for a specified database table and its columns. It creates a validation rules based on the chosen validation libraries like `joi`, \"validatorjs\", \"vine\". The generated rules can be used to enforce data integrity and validate incoming requests in your application.\n\n  Options:\n  - -db, --database: Specify the type of database (e.g., `mysql`, `postgres`, `sqlite`).\n  - -t, --table: Specify the name of the database table for which rules should be generated.\n  - -c, --columns: Specify the column names of the table to generate rules for.\n  - -h, --help: Display help for the command.\n\n  Examples:\n  - Generate rules for a MySQL table named `users` with columns `id` and `name`:\n\n    ```bash\n    ndVr joi -t users -db mysql -c id,name\n    ```\n\n  - Generate rules for a PostgreSQL table named `users` with a validation library `validatorJs`:\n\n      ```bash\n    ndVr validatorJs -t users -db mysql -c id,name\n      ```\n  \n  as same as for sqlite.\n\nLet's say you've the table structure:\n\n```sql\nCREATE TABLE data_types (\n    id INTEGER PRIMARY KEY,\n    name TEXT,\n    age INTEGER,\n    height REAL,\n    is_student BOOLEAN,\n    birthdate DATE,\n    registration_timestamp TIMESTAMP,\n    description BLOB\n    created_at TIMESTAMP,\n    updated_at TIMESTAMP\n);\n```\n\n### Generate rules for a whole table\n\nNow if you run:\n\n```bash\nndVr joi -db sqlite -t data_types\n```\n\nYou'll get:\n```\n🚀 Schema Base Validation rules for \"joi\" generated! 🚀\nCopy and paste these rules into your validation location, such as controller, form request, or any applicable place 😊\n______________________________________________________________________________________________________________________\n\n\n{ \n  name: Joi.string().required(),\n  age: Joi.integer().min(-9223372036854775808).max(9223372036854775807).required(),\n  height: Joi.number().required(),\n  is_student: Joi.required(),\n  birthdate: Joi.date().required(),\n  registration_timestamp: Joi.required(),\n  description: Joi.required(), \n}\n\n```\n\n### Generate rules for specific columns\n\nYou can also explicitly specify the columns:\n\n```bash\nndVr joi -db sqlite -t data_types -c name,age\n```\n\nWhich gives you:\n```\n\n🚀 Schema Base Validation rules for \"joi\" generated! 🚀\nCopy and paste these rules into your validation location, such as controller, form request, or any applicable place 😊\n______________________________________________________________________________________________________________________\n\n{ \n  name: Joi.string().required(),\n  age: Joi.integer().min(-9223372036854775808).max(9223372036854775807).required(), \n}\n\n```\n\n### Always skip columns\n\nTo always skip columns add it in the `schema-config.js` file, under `skipColumns` attribute.\n\n```javascript\nskipColumns: (process.env.SKIP_COLUMNS || 'created_at,updated_at,deleted_at').split(',')\n```\n\n\n## Supported Drivers\n\nSupported database drivers are MySQL, PostgreSQL, and SQLite.\n\nValidation rules may vary based on the selected driver due to differences in supported data types and range specifications.\n\n## Testing\n\n```bash\nyarn test\n```\n## Author\n👤 **Md Tasmidur Rahman \u003ctasmidurrahman@gmail.com\u003e (https://tasmidur.netlify.app)**\n\n* Linkedin: [@tasmidur](https://www.linkedin.com/in/tasmidur/)\n* Github: [@tasmidur](https://github.com/tasmidur)\n* Medium: [@tasmidur](https://medium.com/@tasmidur)\n\n## 🤝 Contributing\n\nContributions, issues and feature requests are welcome!\u003cbr /\u003eFeel free to check [issues page](https://github.com/tasmidur/nodejs-dynamic-validation-rules/issues)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftasmidur%2Fnodejs-schema-rules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftasmidur%2Fnodejs-schema-rules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftasmidur%2Fnodejs-schema-rules/lists"}