Registry / database / pivotql-compiler-mongodb

pivotql-compiler-mongodb

JSON →
library0.4.2jsnpmunverified

Compiles PivotQL ASTs into MongoDB query objects. This library is part of the PivotQL ecosystem, a DSL for filtering and querying data structures. Current stable version is 0.4.2, released as an alpha. It is designed for Node.js environments that use MongoDB. Key differentiators: allows writing expressive, SQL-like filter syntax that gets transpiled into MongoDB's native query language. Minimal dependencies; relies on the PivotQL parser and MongoDB driver. Suitable for APIs where user-defined filters need to be safely converted to MongoDB queries.

npm install pivotql-compiler-mongodb
INSTALL
IMPORT
SIG · PIVOTQL-COMPILER-M
P
pivotql-compiler-mongodb
databasejavascriptv0.4.2
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.

compile
✓ import { compile } from 'pivotql-compiler-mongodb'
✗ const compile = require('pivotql-compiler-mongodb')
Package is ESM-only; commonjs require will fail.
compile
✓ import { compile } from 'pivotql-compiler-mongodb'
✗ import compile from 'pivotql-compiler-mongodb'
compile is a named export, not default.
parse (from pivotql-parser-expression)
✓ import { parse } from 'pivotql-parser-expression'
✗ import { compile } from 'pivotql-parser-expression'
parse is from the parser package, not the compiler.

Parses a PivotQL expression string into an AST and compiles it to a MongoDB query object.

import { parse } from 'pivotql-parser-expression'; import { compile } from 'pivotql-compiler-mongodb'; const query = '( height <= 20 or favorites.color == "green" ) and firstname in ["john", "doug"]'; const ast = parse(query); const queryMongo = compile(ast); console.log(JSON.stringify(queryMongo)); // {"$and":[{"$or":[{"height":{"$lte":20}},{"favorites.color":"green"}]},{"firstname":{"$in":["john","doug"]}}]}
Debug
Known issues
gotchaThe compile function expects an AST object, not a string. Passing a string throws a silent error.
fix
Always parse your query string with the pivotql-parser-expression first, then pass the result to compile.
affects: >=0.0.0
gotchaPackage is ESM-only. Using CommonJS require will result in a runtime error.
fix
Use ES module import syntax or set type: "module" in package.json.
affects: >=0.4.0
deprecatedAlpha version (0.4.2). API may change without major version bump.
fix
Pin to exact version and test upgrades carefully.
affects: <1.0.0
gotchaField paths like 'favorites.color' are interpreted as dot notation. The compiler does not automatically handle nested objects with dots in keys.
fix
Avoid field keys containing dots; they will be treated as nested path separators.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'pivotql-compiler-mongodb' or its corresponding type declarations.
Package does not ship TypeScript definitions. TypeScript users see this error when importing.
fix
Create a custom declaration file (e.g., globals.d.ts) with `declare module 'pivotql-compiler-mongodb';`
TypeError: compile is not a function
Importing the package incorrectly (e.g., using default import instead of named import).
fix
Use `import { compile } from 'pivotql-compiler-mongodb'` correctly.
The requested module 'pivotql-compiler-mongodb' is a CommonJS module, which may not support all module.exports as ESM.
If mistakenly finding a CommonJS build, but package is ESM-only.
fix
Ensure package version >=0.4.0 and use ESM import. If using bundler, check resolve config.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
pivotql-parser-expressionrequiredParses PivotQL expression strings into ASTs required by this compiler
Agent activity
11 hits · last 30 days
node
10
Resources
pivotql-compiler-mongodb — npm install pivotql-compiler-mongodb · libregistry