Registry / database / j2s
library2.0.13jsnpmunverified

JSON to SQL: build RESTful API servers on the fly by accepting JSON describing SQL query statements. Version 2.0.13 supports CRUD operations, joins, aggregations, where conditions with operators (gt, lt, in, between, etc.), relation manipulation, and configurable access control. It relies on Bookshelf.js (and Knex.js) for ORM and query building, and is tested with Koa.js. Unlike traditional REST frameworks, j2s shifts query complexity to the client, reducing backend code for data fetching.

npm install j2s
INSTALL
IMPORT
SIG · J2S
J
j2s
databasejavascriptv2.0.13
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

J2s
import J2s from 'j2s'
const J2s = require('j2s')
Default export (ESM-only in v2)
J2s
const J2s = require('j2s').default
const J2s = require('j2s')
CommonJS require must use .default since v2.0.0
j2s
const j2s = require('j2s')
Old CJS style, still works but deprecated

Minimal setup: create Koa app, configure knex/bookshelf, define a model, instantiate J2s, attach controller router.

import J2s from 'j2s'; import Koa from 'koa'; import Router from '@koa/router'; import knex from 'knex'; import bookshelf from 'bookshelf'; const app = new Koa(); const db = knex({ client: 'postgresql', connection: { host: process.env.DB_HOST || '127.0.0.1', database: process.env.DB_NAME, user: process.env.DB_USER, password: process.env.DB_PASS ?? '' } }); const bs = bookshelf(db); const User = bs.Model.extend({ tableName: 'user', hasTimestamps: true }); const j2s = new J2s({ models: { user: User }, knex: db, bookshelf: bs }); const router = new Router(); router.use('/api', j2s.controller()); app.use(router.routes()); app.listen(3000);
Debug
Known issues
breaking'new J2s()' no longer returns the router instance directly; use 'j2s.controller()' to get the router
fix
Change 'app.use(new J2s({...}))' to 'app.use(new J2s({...}).controller())'
affects: >=2.0.0
deprecatedCommonJS require('j2s') returns the module; you must use .default
fix
Use 'const J2s = require('j2s').default'
affects: >=2.0.0
gotchaBookshelf and knex peer dependencies are required but not installed automatically
fix
Install 'npm install bookshelf knex'
affects: >=2.0.0
gotchaOnly tested with Koa.js; may not work with Express or other frameworks
fix
Use Koa.js or wrap j2s controller for other frameworks
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: J2s is not a constructor
Using CommonJS require without .default
fix
const J2s = require('j2s').default
TypeError: router.use is not a function
Passing j2s() result directly to app.use instead of using .controller()
fix
app.use(new J2s(options).controller())
Error: Cannot find module 'bookshelf'
Missing peer dependency bookshelf
fix
npm install bookshelf
Error: knex is not a function
Missing peer dependency knex
fix
npm install knex
Upgrade
Version history
2.0.13latest on npm
Audit
Dependencies
bookshelfrequiredRequired for data modeling and ORM layer
knexrequiredRequired for query building and database access
Agent activity
4 hits · last 30 days
node
4
Resources
packagej2s
j2s — npm install j2s · libregistry