{"id":18263,"library":"database-ql","title":"database-ql","description":"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).","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/labring/laf","tags":["javascript","laf","laf-client-sdk","database-ql","typescript"],"install":[{"cmd":"npm install database-ql","lang":"bash","label":"npm"},{"cmd":"yarn add database-ql","lang":"bash","label":"yarn"},{"cmd":"pnpm add database-ql","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only package; CommonJS require may fail in Node.js < 14 or without ESM support.","wrong":"const Database = require('database-ql')","symbol":"Database","correct":"import { Database } from 'database-ql'"},{"note":"In Laf environment, database is obtained via cloud.database() not directly instantiated.","wrong":"const db = new Database()","symbol":"cloud.database","correct":"import cloud from '@lafjs/cloud'; const db = cloud.database()"},{"note":"The query/update commands are accessed via db.command, not a named export.","wrong":"import { command } from 'database-ql'","symbol":"db.command","correct":"import cloud from '@lafjs/cloud'; const db = cloud.database(); const _ = db.command"},{"note":"Available for TypeScript type annotations, but not typically used directly.","wrong":"","symbol":"Collection","correct":"import { Collection } from 'database-ql'"}],"quickstart":{"code":"import cloud from '@lafjs/cloud';\n\nexport default async function (ctx: FunctionContext) {\n  const db = cloud.database();\n  const collection = db.collection('users');\n\n  // Insert a document\n  const { id } = await collection.add({ name: 'Alice', age: 30 });\n\n  // Query with conditions\n  const result = await collection.where({\n    age: db.command.gte(18)\n  }).get();\n\n  console.log('Users:', result.data);\n\n  // Update using update commands\n  await collection.doc(id).update({\n    age: db.command.inc(1)\n  });\n\n  // Delete a document\n  await collection.doc(id).remove();\n}","lang":"typescript","description":"Basic CRUD operations using the Laf cloud database with query and update commands."},"warnings":[{"fix":"Upgrade to laf >=1.0.0-beta.14 or apply the security patch.","message":"CVE-2023-48225: Unauthorized database access due to missing permission checks in laf before beta.14.","severity":"breaking","affected_versions":"<1.0.0-beta.14"},{"fix":"Use `new Date()` or rely on laf's automatic timestamp insertion.","message":"The `serverDate` function is deprecated in favor of `Date` object or server-side timestamps.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Access the array via `result.data` instead of treating the result as an array.","message":"The `get()` method returns `{ data: [], requestId: string }` not a direct array.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install database-ql` and ensure version is >=1.0.0.","cause":"Package not installed or missing in package.json dependencies.","error":"Cannot find module 'database-ql'"},{"fix":"Use `const db = cloud.database();` where `cloud` is imported from `@lafjs/cloud`.","cause":"Using `new Database()` directly instead of `cloud.database()`.","error":"TypeError: db.collection is not a function"},{"fix":"Ensure you call `cloud.database()` first to get the db instance with commands.","cause":"Attempting to access `db.command` without initializing via `cloud.database()`.","error":"Property 'command' does not exist on type 'Database'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}