@madapes/query-engine (0.1.6)
Published 2026-02-15 13:57:53 +00:00 by vlad
Installation
@madapes:registry=npm install @madapes/query-engine@0.1.6"@madapes/query-engine": "0.1.6"About this package
@madapes/query-engine
High-performance query engine with UQF (Unified Query Format) support for Node.js.
Installation
npm install @madapes/query-engine
Prerequisites
This package uses native FFI bindings to the Rust query engine. You need:
- The compiled native library (
libquery_engine.dylibon macOS,libquery_engine.soon Linux,query_engine.dllon Windows) - Node.js >= 18.0.0
To build the native library:
cd /path/to/query-engine
cargo build --release
Then copy the library to bindings/nodejs/native/.
Usage
Basic Example
import { Engine, Documents, F, query } from '@madapes/query-engine';
// Create an engine and documents collection
const engine = new Engine();
const docs = new Documents();
// Add documents
docs.addMany([
{ id: 1, name: 'Alice', age: 30 },
{ id: 2, name: 'Bob', age: 25 },
{ id: 3, name: 'Charlie', age: 35 },
]);
// Build and execute a query
const result = engine.find(
query()
.filter(F.gte('age', 30))
.sort('age', 'asc')
.limit(10)
.build(),
docs
);
console.log(result.hits); // [{ id: 1, ... }, { id: 3, ... }]
// Clean up
docs.dispose();
engine.dispose();
Query Builder
The query builder provides a fluent API for constructing queries:
import { F, query } from '@madapes/query-engine';
// Complex filter
const q = query()
.filter(
F.and(
F.eq('status', 'active'),
F.or(
F.gt('age', 21),
F.eq('vip', true)
)
)
)
.sort('created_at', 'desc')
.limit(20)
.offset(0)
.fields('id', 'name', 'email')
.timeout(5000)
.build();
Available Filter Operators
Comparison
F.eq(field, value)- EqualF.ne(field, value)- Not equalF.gt(field, value)- Greater thanF.gte(field, value)- Greater than or equalF.lt(field, value)- Less thanF.lte(field, value)- Less than or equalF.between(field, low, high)- Between range
Set
F.in(field, values)- In arrayF.nin(field, values)- Not in array
String
F.prefix(field, prefix)- Starts withF.contains(field, substring)- ContainsF.regex(field, pattern)- Matches regex
Array
F.all(field, values)- Array contains allF.size(field, size)- Array size equalsF.elemMatch(field, filter)- Element matches filter
Logical
F.and(...filters)- All filters matchF.or(...filters)- Any filter matchesF.not(filter)- Filter does not match
Existence/Type
F.exists(field, exists?)- Field existsF.type(field, type)- Field is of typeF.true()- Always matchesF.false()- Never matches
Numeric
F.mod(field, divisor, remainder)- Modulo equals
Cancellation
import { Engine, Documents, CancelToken, F, query } from '@madapes/query-engine';
const engine = new Engine();
const docs = new Documents();
const token = new CancelToken();
// Start cancellation after 100ms
setTimeout(() => token.cancel(), 100);
try {
const result = engine.findCancellable(
query().filter(F.true()).build(),
docs,
token
);
} catch (err) {
if (err.code === QeErrorCode.Cancelled) {
console.log('Query was cancelled');
}
}
token.dispose();
docs.dispose();
engine.dispose();
Convenience Functions
import { findInMemory, countInMemory, F, query } from '@madapes/query-engine';
const docs = [
{ id: 1, status: 'active' },
{ id: 2, status: 'inactive' },
];
// One-shot find
const result = findInMemory(
query().filter(F.eq('status', 'active')).build(),
docs
);
// One-shot count
const count = countInMemory(
query().filter(F.true()).build(),
docs
);
API Reference
Engine
new Engine(config?)- Create a new engineEngine.version- Get library versionengine.validate(query)- Validate a queryengine.find(query, docs)- Execute a find queryengine.findCancellable(query, docs, token)- Execute with cancellationengine.count(query, docs)- Execute a count queryengine.cacheStats- Get cache statisticsengine.clearCache()- Clear the plan cacheengine.dispose()- Release resources
Documents
new Documents()- Create a new collectiondocs.add(doc)- Add a single documentdocs.addMany(docs)- Add multiple documentsdocs.count- Get document countdocs.dispose()- Release resources
CancelToken
new CancelToken()- Create a new tokentoken.cancel()- Signal cancellationtoken.isCancelled- Check if cancelledtoken.dispose()- Release resources
License
MIT
Dependencies
Development Dependencies
| ID | Version |
|---|---|
| @napi-rs/cli | ^2.18.4 |
| @types/node | ^20.0.0 |
| typescript | ^5.0.0 |
Optional Dependencies
| ID | Version |
|---|---|
| @madapes/query-engine-darwin-arm64 | 0.1.6 |
| @madapes/query-engine-darwin-x64 | 0.1.6 |
| @madapes/query-engine-linux-arm64-gnu | 0.1.6 |
| @madapes/query-engine-linux-x64-gnu | 0.1.6 |
| @madapes/query-engine-win32-x64-msvc | 0.1.6 |
Keywords
query
json
filter
database
uqf
Details
2026-02-15 13:57:53 +00:00
Assets (1)
Versions (3)
View all
npm
8
Mad Apes
MIT
20 KiB
query-engine-0.1.6.tgz
20 KiB