Registry / database / alcumus-mongo-sql

alcumus-mongo-sql

JSON →
library6.3.7jsnpmunverified

MoSQL is a JavaScript library for generating SQL statements from JSON objects, version 6.3.7. It supports a MongoDB-like query language, translating JSON queries into parameterized SQL for MySQL-style databases. The library covers SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and more, with support for joins, subqueries, and aggregation. Unlike chaining-based builders, MoSQL uses plain objects, enabling introspection and manipulation of queries. Moderate release cadence; last major updates added TypeScript declarations and improved subquery support.

npm install alcumus-mongo-sql
INSTALL
IMPORT
SIG · ALCUMUS-MONGO-SQL
A
alcumus-mongo-sql
databasejavascriptv6.3.7
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.

default
import mosql from 'mongo-sql'
const { sql } = require('mongo-sql')
Default export is a function that accepts query objects. CommonJS require returns the function, not an object with 'sql' property.
select
import { select } from 'mongo-sql'
const select = require('mongo-sql').select
Named export for select builder; also available as default().select() but this is direct.
sql
import { sql } from 'mongo-sql'
const sql = require('mongo-sql').sql
This is the main builder function; same as default export.

Creates a JSON query object and calls the default export to get SQL string and parameterized values.

import mongoSql from 'mongo-sql'; const query = { type: 'select', table: 'users', where: { $or: { id: 5, name: 'Bob' } } }; const result = mongoSql(query); console.log(result.toString()); // Output: select "users".* from "users" where "users"."id" = $1 or "users"."name" = $2 console.log(result.values); // Output: [5, 'Bob']
Debug
Known issues
breakingVersion 5.0.0 renamed the package from 'mongo-sql' to 'alcumus-mongo-sql' and changed module export structure.
fix
Update imports to use 'alcumus-mongo-sql' instead of 'mongo-sql'.
affects: >=5.0.0
gotchaThe library does not escape identifiers by default; table and column names are quoted with double quotes but not escaped for special characters.
fix
Avoid dynamic table/column names or sanitize them before building the query object.
affects: >=1.0.0
gotchaUsing 'type: 'update'' requires specifying $set or $unset in the query; otherwise the update clause will be empty.
fix
Include $set or $unset operators in the update query object.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'mongo-sql'
Package was renamed to 'alcumus-mongo-sql' in v5.0.0.
fix
Install and import from 'alcumus-mongo-sql' instead.
TypeError: mongoSql is not a function
Default import was used incorrectly; the module expects CommonJS require or correct default import.
fix
Use: import mongoSql from 'alcumus-mongo-sql' or const mongoSql = require('alcumus-mongo-sql').
Unrecognized query type: 'delete'
Delete queries use 'remove' as the type, not 'delete'.
fix
Use type: 'remove' for delete operations.
Upgrade
Version history
6.3.7latest on npm
Audit
Dependencies
lodashrequiredUsed internally for object manipulation and array operations
Agent activity
35 hits · last 30 days
node
28
Amazon
1
OpenAI (training)
1
Resources
alcumus-mongo-sql — npm install alcumus-mongo-sql · libregistry