database-ql

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript

A MongoDB-like query syntax library for JavaScript/TypeScript environments, designed for use with Laf cloud development platform. Version 1.0.0 (beta) provides a fluent API for database operations including CRUD, query commands (eq, gt, in, etc.), update commands (inc, push, etc.), aggregation, and regex queries. It supports both client-side (laf-client-sdk) and server-side (laf) usage, with ESM and TypeScript support. Unlike direct MongoDB drivers, it offers a simplified, promise-based interface with automatic request batching and Laf-specific security features (CVE-2023-48225 fixed in beta.14).

error Cannot find module 'database-ql'
cause Package not installed or missing in package.json dependencies.
fix
Run npm install database-ql and ensure version is >=1.0.0.
error TypeError: db.collection is not a function
cause Using `new Database()` directly instead of `cloud.database()`.
fix
Use const db = cloud.database(); where cloud is imported from @lafjs/cloud.
error Property 'command' does not exist on type 'Database'
cause Attempting to access `db.command` without initializing via `cloud.database()`.
fix
Ensure you call cloud.database() first to get the db instance with commands.
breaking CVE-2023-48225: Unauthorized database access due to missing permission checks in laf before beta.14.
fix Upgrade to laf >=1.0.0-beta.14 or apply the security patch.
deprecated The `serverDate` function is deprecated in favor of `Date` object or server-side timestamps.
fix Use `new Date()` or rely on laf's automatic timestamp insertion.
gotcha The `get()` method returns `{ data: [], requestId: string }` not a direct array.
fix Access the array via `result.data` instead of treating the result as an array.
npm install database-ql
yarn add database-ql
pnpm add database-ql

Basic CRUD operations using the Laf cloud database with query and update commands.

import cloud from '@lafjs/cloud';

export default async function (ctx: FunctionContext) {
  const db = cloud.database();
  const collection = db.collection('users');

  // Insert a document
  const { id } = await collection.add({ name: 'Alice', age: 30 });

  // Query with conditions
  const result = await collection.where({
    age: db.command.gte(18)
  }).get();

  console.log('Users:', result.data);

  // Update using update commands
  await collection.doc(id).update({
    age: db.command.inc(1)
  });

  // Delete a document
  await collection.doc(id).remove();
}