{"_id":"@eduardomagaldi/crudy","_rev":"3-5e0a649fa3f1e8cd90ef793abfa99ab1","name":"@eduardomagaldi/crudy","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@eduardomagaldi/crudy","version":"1.0.0","keywords":["crud","express","postgresql","api","rest"],"author":"","license":"ISC","_id":"@eduardomagaldi/crudy@1.0.0","maintainers":[{"name":"eduardomagaldi","email":"magaldi1989@gmail.com"}],"homepage":"https://github.com/eduardomagaldi/crudy#readme","bugs":{"url":"https://github.com/eduardomagaldi/crudy/issues"},"dist":{"shasum":"a56a2b6fa23fac0c1ca483dcde23926f75efd1cb","tarball":"https://registry.npmjs.org/@eduardomagaldi/crudy/-/crudy-1.0.0.tgz","fileCount":4,"integrity":"sha512-y6mVSpMbLeWecyGiUrJOxonQQgZwCVtl2kDJr1QmWaZfYg5sjONs/ANEPh6tELwDjCFhC+R2RkCvHWwrourQ/w==","signatures":[{"sig":"MEYCIQD6JyCWmFaRLlgoMdb9YCqssbXAELLtoXBJWs/qCa/NbQIhAJPKNW59vEtwTtvOrJ6kbCPPSUzJxGAH0hM0PBsGsAcy","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39146},"main":"dist/index.js","engines":{"node":">=14.0.0"},"gitHead":"f0099f96ff5f65e6d16b04bf491e64c2e94b3878","scripts":{"test":"node scripts/test.js"},"_npmUser":{"name":"eduardomagaldi","email":"magaldi1989@gmail.com"},"repository":{"url":"git+https://github.com/eduardomagaldi/crudy.git","type":"git"},"_npmVersion":"11.6.2","description":"A CRUD generator for Express.js with PostgreSQL - automatically detects schemas and handles relations","directories":{},"_nodeVersion":"25.2.0","dependencies":{"express":"^4.18.2"},"_hasShrinkwrap":false,"peerDependencies":{"pg":"^8.16.3"},"_npmOperationalInternal":{"tmp":"tmp/crudy_1.0.0_1766300680732_0.621122042060013","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@eduardomagaldi/crudy","version":"1.0.1","keywords":["crud","express","postgresql","api","rest"],"author":"","license":"ISC","_id":"@eduardomagaldi/crudy@1.0.1","maintainers":[{"name":"eduardomagaldi","email":"magaldi1989@gmail.com"}],"homepage":"https://github.com/eduardomagaldi/crudy#readme","bugs":{"url":"https://github.com/eduardomagaldi/crudy/issues"},"dist":{"shasum":"86c368380a832c616ac158f9d95c9dd21412996f","tarball":"https://registry.npmjs.org/@eduardomagaldi/crudy/-/crudy-1.0.1.tgz","fileCount":4,"integrity":"sha512-hN7zccE9Cl4mFZLerQaO5c/Av40Ee0RfdADPOIvUn9Q7pIBNTjmQe0xGDP1CIb6DoS+v63obttslRof8brvo1A==","signatures":[{"sig":"MEUCIQDYbpG9S0+TH2/BszhHmyJr2XcraGvoDvPL7LA3//oG5wIgQpclMjcHFSSmDO9apAtA9igpXDNCK5PWITZNaUNTU8w=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35771},"main":"dist/index.js","engines":{"node":">=14.0.0"},"gitHead":"d5424d6965ea540d2c750c6f6cbde982423d6112","scripts":{"test":"node scripts/test.js"},"_npmUser":{"name":"eduardomagaldi","email":"magaldi1989@gmail.com"},"repository":{"url":"git+https://github.com/eduardomagaldi/crudy.git","type":"git"},"_npmVersion":"11.6.2","description":"A CRUD generator for Express.js with PostgreSQL - automatically detects schemas and handles relations","directories":{},"_nodeVersion":"25.2.0","dependencies":{"express":"^4.18.2"},"_hasShrinkwrap":false,"peerDependencies":{"pg":"^8.16.3"},"_npmOperationalInternal":{"tmp":"tmp/crudy_1.0.1_1766416047714_0.029079004757736282","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@eduardomagaldi/crudy","version":"1.0.2","description":"A CRUD generator for Express.js with PostgreSQL - automatically detects schemas and handles relations","main":"dist/index.js","scripts":{"test":"node scripts/test.js"},"keywords":["crud","express","postgresql","api","rest"],"author":"","license":"ISC","repository":{"type":"git","url":"git+https://github.com/eduardomagaldi/crudy.git"},"dependencies":{"express":"^4.18.2"},"peerDependencies":{"pg":"^8.16.3"},"engines":{"node":">=14.0.0"},"gitHead":"2a1de0ca86df490136ccbf1f6a16e0544d23b9ee","_id":"@eduardomagaldi/crudy@1.0.2","bugs":{"url":"https://github.com/eduardomagaldi/crudy/issues"},"homepage":"https://github.com/eduardomagaldi/crudy#readme","_nodeVersion":"25.2.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-FSW9x60tJKOk+aJbm8KGj3a5iQxIPx8+fszSsDQcZeHY4yx/7TqYis2+kqyL9N9xLbr31us5yD1ZppmGJTmhew==","shasum":"c3b1e4f52f1b00b96f23cffe006c1c259978a6a8","tarball":"https://registry.npmjs.org/@eduardomagaldi/crudy/-/crudy-1.0.2.tgz","fileCount":4,"unpackedSize":34499,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDS979W1rnv+x2gyhEKgp4lJ8FpwnR8PrGVx0keUeAmoQIgewLcHNCCPU8bR7oFe+CE74IcSzRb12vd/ixnzswCtAo="}]},"_npmUser":{"name":"eduardomagaldi","email":"magaldi1989@gmail.com"},"directories":{},"maintainers":[{"name":"eduardomagaldi","email":"magaldi1989@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/crudy_1.0.2_1766871939940_0.44163423461982254"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-21T07:04:40.644Z","modified":"2025-12-27T21:45:40.319Z","1.0.0":"2025-12-21T07:04:40.877Z","1.0.1":"2025-12-22T15:07:27.887Z","1.0.2":"2025-12-27T21:45:40.097Z"},"bugs":{"url":"https://github.com/eduardomagaldi/crudy/issues"},"license":"ISC","homepage":"https://github.com/eduardomagaldi/crudy#readme","keywords":["crud","express","postgresql","api","rest"],"repository":{"type":"git","url":"git+https://github.com/eduardomagaldi/crudy.git"},"description":"A CRUD generator for Express.js with PostgreSQL - automatically detects schemas and handles relations","maintainers":[{"name":"eduardomagaldi","email":"magaldi1989@gmail.com"}],"readme":"# Crudy\n\nA CRUD generator for Express.js with PostgreSQL that automatically detects table schemas and handles relations.\n\n## Features\n\n- 🚀 **Auto-detect schemas** from PostgreSQL database (lazy loading - no database calls on creation)\n- 🔗 **Automatic relation detection** from foreign keys\n- 📦 **Multi-table support** - generate CRUD for multiple tables at once\n- 🔍 **Related data inclusion** - GET requests automatically include related records\n- 🛡️ **Smart delete protection** - shows which records are blocking deletions\n- ⚡ **Zero configuration** - just pass table names\n\n## Installation\n\n```bash\nnpm install github:eduardomagaldi/crudy\nnpm install pg express\n```\n\n## Quick Start\n\n```javascript\nconst express = require('express')\nconst { Pool } = require('pg')\nconst createCrudyMulti = require('crudy')\n\nconst pool = new Pool({\n  user: 'your_user',\n  host: 'localhost',\n  database: 'your_database',\n  password: 'your_password',\n  port: 5432,\n})\n\nconst app = express()\napp.use(express.json())\n\n// ⚡ No await needed! createCrudyMulti is synchronous\n// Schemas are loaded lazily on first request\nconst handlers = createCrudyMulti(['users', 'addresses', 'purchases'], pool)\n\n// Response middleware\nconst sendResponse = (req, res) => {\n  const status = res.locals.crudyStatus || 200\n  const result = res.locals.crudyResult\n  if (status === 204) return res.status(204).send()\n  res.status(status).json(result)\n}\n\n// Set up routes\napp.get('/users', handlers.users.handleGetAll, sendResponse)\napp.get('/users/:id', handlers.users.handleGet, sendResponse)\napp.post('/users', handlers.users.handleCreate, sendResponse)\napp.put('/users/:id', handlers.users.handleUpdate, sendResponse)\napp.delete('/users/:id', handlers.users.handleDelete, sendResponse)\n\n// Repeat for other tables: handlers.addresses.*, handlers.purchases.*\n\napp.listen(3000, () => {\n  console.log('Server running on http://localhost:3000')\n})\n```\n\n## How It Works\n\n### Lazy Schema Loading\n\n**No database calls on creation!** Schemas are automatically loaded and cached in memory on the first request. This means:\n\n- ✅ Instant handler creation (synchronous, no await)\n- ✅ Schemas cached as singleton (one query per table)\n- ✅ Fast subsequent requests\n\n### Schema Auto-Detection\n\nCrudy automatically detects:\n\n- Column types, primary keys, foreign keys, auto-increment, required/optional fields\n\n### Relation Detection\n\nRelations are automatically detected from:\n\n1. Foreign key constraints\n2. Column patterns (e.g., `user_id` → `users` table)\n\n**Relation Types:**\n\n- **belongsTo** - Included as singular property: `address.user`\n- **hasMany** - Included as plural property: `user.addresses`\n\n## API\n\n### `createCrudyMulti(tableNames, db)`\n\nCreates CRUD handlers for multiple tables. **Synchronous - no await needed!**\n\n**Parameters:**\n\n- `tableNames` (string[]) - Array of table names\n- `db` (pg.Pool) - PostgreSQL connection pool\n\n**Returns:** Object with table names as keys, each containing:\n\n- `handleGetAll(req, res, next)` - Get all records\n- `handleGet(req, res, next)` - Get single record by ID\n- `handleCreate(req, res, next)` - Create new record\n- `handleUpdate(req, res, next)` - Update record by ID\n- `handleDelete(req, res, next)` - Delete record by ID\n- `tableName` - Table name\n- `schema` - Schema object (available after first request)\n\n## Response Format\n\n### GET with Relations\n\n```json\n{\n  \"id\": 1,\n  \"email\": \"john@example.com\",\n  \"addresses\": [{ \"id\": 1, \"street\": \"123 Main St\", \"user_id\": 1 }],\n  \"user\": { \"id\": 1, \"email\": \"john@example.com\" }\n}\n```\n\n### DELETE with Relations\n\nIf deleting a record referenced by others:\n\n```json\n{\n  \"error\": \"Cannot delete: this record is referenced by other records\",\n  \"details\": \"2 record(s) in 'addresses' table (IDs: 1, 2)\"\n}\n```\n\nStatus: `409 Conflict`\n\n## Query Parameters\n\nFilter results using query parameters:\n\n```\nGET /users?email=john@example.com&is_active=true\n```\n\n## Error Handling\n\nHandlers set response data in `res.locals`:\n\n- `res.locals.crudyStatus` - HTTP status code\n- `res.locals.crudyResult` - Response data or error object\n\nStatus codes: `200` (Success), `201` (Created), `204` (No Content), `404` (Not Found), `409` (Conflict), `500` (Server Error)\n\n## Requirements\n\n- Node.js 14+\n- PostgreSQL database\n- `pg` package (peer dependency)\n- `express` package\n\n## License\n\nISC\n","readmeFilename":"README.md"}