Registry / database / knex-doc-filter

knex-doc-filter

JSON →
library0.1.0jsnpmunverified

A library that converts MongoDB-style query documents into knex.js query builder filters. Current version is 0.1.0, appears to be an early release with no recent updates. It supports common operators ($and, $or, $nor, $eq, $ne, $regex, $gt, $gte, $lt, $lte, $in, $nin, $not) and works by applying filter conditions to a knex query builder. Unlike direct MongoDB, it translates $regex to SQL LIKE, potentially with different semantics. It is a niche package for developers who prefer MongoDB query syntax while using SQL databases via knex. The package has low adoption and no recent maintenance, so users should assess stability.

npm install knex-doc-filter
INSTALL
IMPORT
SIG · KNEX-DOC-FILTER
K
knex-doc-filter
databasejavascriptv0.1.0
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 docFilter from 'knex-doc-filter'
const docFilter = require('knex-doc-filter')
Package exports a default function; ESM import recommended.
default (CommonJS)
const docFilter = require('knex-doc-filter').default
const docFilter = require('knex-doc-filter')
If using CommonJS, you must access .default because the package is ESM-compatible.
none (type import)
import docFilter from 'knex-doc-filter'
import { docFilter } from 'knex-doc-filter'
No named exports; only a default export.

Demonstrates installing knex and knex-doc-filter, creating a knex connection, and applying a MongoDB-style filter to select active users aged 18+.

import Knex from 'knex'; import docFilter from 'knex-doc-filter'; const knex = Knex({ client: 'mysql', connection: { host: process.env.DB_HOST ?? '127.0.0.1', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test' } }); const selection = knex('users'); const query = { $and: [ { status: { $eq: 'active' } }, { age: { $gte: 18 } } ] }; docFilter(selection, query) .then(rows => console.log(rows)) .catch(err => console.error(err));
Debug
Known issues
deprecatedPackage is unmaintained (last commit in 2017) and may not work with modern knex versions.
fix
Consider using knex's native where methods or other query builder wrappers.
affects: >=0.1.0
breaking$regex operator translates to SQL LIKE, which does not support full regex syntax; patterns may behave differently than MongoDB.
fix
Review and adapt regex patterns to SQL LIKE wildcards (% and _).
affects: >=0.0.0
gotchaImport fails in CommonJS without .default access because package uses ES module export.
fix
Use import or const docFilter = require('knex-doc-filter').default.
affects: >=0.1.0
deprecatedNo TypeScript typings provided; may cause type errors.
fix
Consider writing a declaration file or using an alternative.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: docFilter is not a function
CommonJS require returns an object with default export; calling it directly fails.
fix
Use const docFilter = require('knex-doc-filter').default;
Error: Cannot find module 'knex'
knex is a peer dependency and must be installed separately.
fix
Run npm install knex knex-doc-filter.
knex-doc-filter: $regex not supported on this client
Some SQL clients (e.g., SQLite) may not support LIKE operators in the same way.
fix
Check the client compatibility or avoid using $regex with limited clients.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
knexrequiredpeer dependency; the library builds on knex query builder
Agent activity
4 hits · last 30 days
node
4
Resources
knex-doc-filter — npm install knex-doc-filter · libregistry