Registry / database / coral-sql

coral-sql

JSON →
library1.5.5jsnpmunverified

A Node.js SQL query builder library inspired by the Knex-style fluent API. Current stable version 1.5.5 (as of 2024). Released as needed; no fixed cadence. Differentiators: lightweight, zero dependencies, TypeScript support, and a simple builder pattern for constructing parameterized SQL queries with column escaping, joins, subqueries, and aggregations. Focuses on MySQL/MariaDB compatibility and avoids ORM features.

npm install coral-sql
INSTALL
IMPORT
SIG · CORAL-SQL
C
coral-sql
databasejavascriptv1.5.5
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.

createBuilder
import { createBuilder } from 'coral-sql'
const { createBuilder } = require('coral-sql')
coral-sql is ESM-only since v1.0. Use import syntax or dynamic import().
raw
import { raw } from 'coral-sql'
const raw = require('coral-sql').raw
raw is a named export used for unescaped SQL fragments.
Builder
import type { Builder } from 'coral-sql'
import { Builder } from 'coral-sql'
Builder is a TypeScript type, not a runtime value. Use type import.

Demonstrates building a parameterized SELECT with raw SQL fragment, WHERE conditions, ordering, and limit using the fluent builder.

import { createBuilder, raw } from 'coral-sql'; const builder = createBuilder() .columns('id', raw('UPPER(name)'), 'email') .from('users') .where('age', '>', 18) .andWhere('status', 'active') .orderBy('created_at', 'desc') .limit(10); const [sql, bindings] = builder.toSQL(); console.log('SQL:', sql); console.log('Bindings:', bindings); // SQL: SELECT `id`, UPPER(name), `email` FROM `users` WHERE `age` > ? AND `status` = ? ORDER BY `created_at` DESC LIMIT ? // Bindings: [18, 'active', 10]
Debug
Known issues
breakingSince v1.0, coral-sql is ESM-only. CommonJS require() will throw an error.
fix
Use import syntax or dynamic import('coral-sql').
affects: >=1.0
gotchaColumn references are automatically escaped with backticks; use raw() for column names that should not be escaped or for SQL functions.
fix
Pass unescaped SQL via raw() helper.
affects: >=0.1
gotchaMethod toSQL() returns an array [sql, bindings], not an object.
fix
Destructure the result: const [sql, bindings] = builder.toSQL();
affects: >=0.1
deprecatedThe method `where` with a single object argument is deprecated in favor of explicit equality checks.
fix
Use multiple where calls or spread object keys.
affects: >=1.4
Errors
Common errors & fixes
TypeError: require(...) is not a function
Using CommonJS require() on ESM-only package.
fix
Switch to import syntax or use dynamic import: const mod = await import('coral-sql');
Cannot find module 'coral-sql'
Package not installed or incorrect import path.
fix
Run npm install coral-sql and ensure the import path is correct.
TypeError: builder.toSQL is not a function
Using an older version where toSQL is named differently (e.g., build).
fix
Use .toSQL() (v1.0+) or check documentation for version compatibility.
Upgrade
Version history
1.5.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
OpenAI (training)
1
Resources
coral-sql — npm install coral-sql · libregistry