
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
json-sql-enhanced
Advanced tools
Node.js library for mapping MongoDB-style query objects to SQL queries with enhanced operators and multi-dialect support
A powerful, modern fork of json-sql with comprehensive MongoDB operators and multi-dialect support
This is a comprehensive modernization and enhancement of the original json-sql library, featuring:
$regex
with $options
support for case-insensitive pattern matching$size
for array length queries$exists
for field existence checks$elemMatch
for complex array element matching$not
for negation$and
/$or
with nested logical operations~
, ~*
operators, ILIKE, JSONB functions{}
convert to NULL
toHexString()
methodnpm install json-sql-enhanced
const jsonSql = require('json-sql-enhanced')();
// Basic query
const result = jsonSql.build({
type: 'select',
table: 'users',
condition: {
name: { $regex: 'John', $options: 'i' },
age: { $gt: 18 },
emails: { $size: { $gt: 0 } },
},
});
console.log(result.query);
// Output: select * from "users" where "name" ILIKE $p1 and "age" > $p2 and JSON_LENGTH("emails") > $p3
console.log(result.values);
// Output: { p1: '%John%', p2: 18, p3: 0 }
// Case-insensitive pattern matching
{ fullName: { $regex: 'John', $options: 'i' } }
// โ PostgreSQL: "fullName" ILIKE '%John%'
// โ MySQL: LOWER("fullName") LIKE LOWER('%John%')
// โ SQLite: "fullName" LIKE '%John%' COLLATE NOCASE
// Pattern optimization
{ name: { $regex: '^John' } } // โ "name" LIKE 'John%'
{ name: { $regex: 'Smith$' } } // โ "name" LIKE '%Smith'
{ name: { $regex: '^John$' } } // โ "name" = 'John'
// Complex array element matching
{
emails: {
$elemMatch: {
value: { $regex: '@company\\.com$', $options: 'i' },
type: 'work'
}
}
}
// โ PostgreSQL: EXISTS(SELECT 1 FROM jsonb_array_elements("emails") elem WHERE ...)
// โ MySQL: JSON_SEARCH("emails", 'one', '%@company.com%') IS NOT NULL
// โ SQLite: EXISTS(SELECT 1 FROM json_each("emails") WHERE ...)
{
tags: {
$size: 3;
}
} // โ JSON_LENGTH("tags") = 3
{
emails: {
$size: {
$gt: 0;
}
}
} // โ JSON_LENGTH("emails") > 0
{
email: {
$exists: true;
}
} // โ "email" IS NOT NULL
{
phone: {
$exists: false;
}
} // โ "phone" IS NULL
{
$and: [
{ age: { $gte: 18 } },
{
$or: [{ status: 'active' }, { emails: { $size: { $gt: 0 } } }],
},
];
}
// PostgreSQL optimizations
const pgSql = require('json-sql-enhanced')({ dialect: 'postgresql' });
// MySQL optimizations
const mysqlSql = require('json-sql-enhanced')({ dialect: 'mysql' });
// SQLite optimizations
const sqliteSql = require('json-sql-enhanced')({ dialect: 'sqlite' });
// SQL Server support
const mssqlSql = require('json-sql-enhanced')({ dialect: 'mssql' });
This fork is 100% backward compatible. Simply replace your import:
// Before
const jsonSql = require('json-sql')();
// After
const jsonSql = require('json-sql-enhanced')();
// All existing code works unchanged!
All these complex MongoDB-style queries are supported:
// Case-insensitive regex with options
{ fullName: { $regex: 'John', $options: 'i' } }
// Array element matching with nested conditions
{
emails: {
$elemMatch: {
value: { $regex: 'john@example\\.com', $options: 'i' }
}
}
}
// Complex logical operations
{
$or: [
{ emails: { $exists: false } },
{ emails: { $size: 0 } }
]
}
// Negation with nested operators
{
$not: {
emails: {
$elemMatch: { type: { $regex: '^WORK$', $options: 'i' } }
}
}
}
// Multiple conditions with $and
{
$and: [
{
emails: {
$elemMatch: { value: { $regex: '@example\\.com', $options: 'i' } }
}
},
{
emails: { $elemMatch: { value: { $regex: '^john', $options: 'i' } } }
}
]
}
# Install dependencies
npm install
# Run tests
npm test
# Format code
npm run format
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
git checkout -b feature/amazing-feature
)git commit -m 'feat: add amazing feature'
)git push origin feature/amazing-feature
)MIT License - see the LICENSE file for details.
For detailed documentation, examples, and API reference, see the docs directory:
Made with โค๏ธ for the JavaScript community
FAQs
Node.js library for mapping MongoDB-style query objects to SQL queries with enhanced operators and multi-dialect support
We found that json-sql-enhanced demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.