{"id":42916,"library":"json-schema-entity","title":"json-schema-entity","description":"Manage a group of SQL tables with parent-child relations as a document/entity (NoSQL-style). Current stable version 7.2.0. Release cadence is irregular. Key differentiator: define entity schemas using JSON Schema and automatically create relational tables with CRUD operations. Requires a CR layer driver like pg-cr-layer or mssql-cr-layer. Not to be confused with JSON Schema validation libraries.","status":"active","version":"7.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/andrglo/json-schema-entity","tags":["javascript","SQL","document","entity","belongs","To","has","Many"],"install":[{"cmd":"npm install json-schema-entity","lang":"bash","label":"npm"},{"cmd":"yarn add json-schema-entity","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-schema-entity","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for PostgreSQL database operations","package":"pg-cr-layer","optional":false},{"reason":"Alternative driver for MSSQL, one of these cr-layer packages is required","package":"mssql-cr-layer","optional":true}],"imports":[{"note":"Default export is a function. In CommonJS use require('json-schema-entity')","wrong":"const { jse } = require('json-schema-entity')","symbol":"default","correct":"import jse from 'json-schema-entity'"},{"note":"CommonJS default import, no named exports","wrong":"import jse from 'json-schema-entity'","symbol":"jse","correct":"const jse = require('json-schema-entity')"},{"note":"jse is a factory function, not a constructor","wrong":"const invoiceClass = new jse('invoice', schema)","symbol":"default","correct":"import jse from 'json-schema-entity'; const invoiceClass = jse('invoice', schema)"}],"quickstart":{"code":"const jse = require('json-schema-entity');\nconst PgCrLayer = require('pg-cr-layer');\n\nconst db = new PgCrLayer({\n  user: 'test',\n  password: 'test',\n  host: 'localhost',\n  port: 5432,\n  database: 'test',\n  pool: { max: 10, idleTimeout: 30000 }\n});\n\nconst customerSchema = {\n  properties: {\n    id: { type: 'integer', autoIncrement: true, primaryKey: true },\n    name: { type: 'string' }\n  }\n};\n\nconst Customer = jse('customer', customerSchema);\n\nCustomer.hasMany('orders', {\n  properties: {\n    id: { type: 'integer', autoIncrement: true, primaryKey: true },\n    total: { type: 'number' },\n    customerId: { type: 'integer', $ref: 'customer' }\n  }\n});\n\nconst customer = Customer.new(db);\ncustomer.createTables()\n  .then(() => customer.syncTables())\n  .then(() => {\n    const instance = customer.createInstance({ name: 'Acme', orders: [{ total: 100 }] });\n    return instance.save();\n  })\n  .then(() => console.log('Entity saved'));","lang":"javascript","description":"Creates an entity class for 'customer' with hasMany relation to 'orders', then creates tables, inserts data, and saves."},"warnings":[{"fix":"Ensure createTables() resolves before syncTables() and update schema definitions to conform to JSON Schema draft-04.","message":"v7 changed the API: 'syncTables' must be called after 'createTables', and schema validation is more strict.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Install either pg-cr-layer or mssql-cr-layer as a peer dependency.","message":"Missing required dependency: pg-cr-layer or mssql-cr-layer","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use const jse = require('json-schema-entity') or import jse from 'json-schema-entity'.","message":"The global jse function is the only API; named exports removed in v6.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Ensure autoIncrement properties are integers and have primaryKey: true.","message":"autoIncrement property only works with integer primary keys.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'7.2.0':25 'automat':39 'belong':74 'cadenc':27 'child':14 'confus':64 'cr':48,54,59 'creat':40 'crud':44 'current':22 'defin':32 'differenti':31 'document':72 'document/entity':18 'driver':50 'entiti':4,33,73 'group':7 'irregular':29 'javascript':70 'json':2,36,66 'json-schema-ent':1 'key':30 'layer':49,55,60 'librari':69 'like':51 'manag':5 'mani':77 'mssql':58 'mssql-cr-layer':57 'nosql':20 'nosql-styl':19 'oper':45 'parent':13 'parent-child':12 'pg':53 'pg-cr-layer':52 'relat':15,41 'releas':26 'requir':46 'schema':3,34,37,67 'sql':9,71 'stabl':23 'style':21 'tabl':10,42 'use':35 'valid':68 'version':24","created_at":"2026-06-05T16:57:16.705140+00:00","updated_at":"2026-06-05T16:57:16.705140+00:00","problems":[{"fix":"npm install pg-cr-layer","cause":"pg-cr-layer not installed","error":"Cannot find module 'pg-cr-layer'"},{"fix":"const MyClass = jse('name', schema); // no new","cause":"Using new jse instead of calling jse as a function","error":"jse is not a constructor"},{"fix":"Ensure schema has valid properties and types.","cause":"jse returned undefined due to missing schema properties","error":"Cannot read property 'new' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/andrglo/json-schema-entity#readme","github":"https://github.com/andrglo/json-schema-entity","docs":null,"changelog":null,"pypi":null,"npm":"json-schema-entity","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}