Registry / database / rate-sql

rate-sql

JSON →
library0.2.0jsnpmunverified

rate-sql is a lightweight SQL query builder for Node.js and the browser, currently at version 0.2.0. It provides a programmatic way to construct SQL queries with support for parameterization, joins, and subqueries. Different from ORMs like Sequelize or Knex, rate-sql focuses on minimal overhead and zero dependencies. Its release cadence is irregular as it is still in early development. Ideal for developers who want direct SQL control with a clean API and TypeScript types included.

npm install rate-sql
INSTALL
IMPORT
SIG · RATE-SQL
R
rate-sql
databasejavascriptv0.2.0
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.

default
import RateSQL from 'rate-sql'
const RateSQL = require('rate-sql')
ESM-only; CommonJS require will fail in Node < 22 or without proper configuration.
QueryBuilder
import { QueryBuilder } from 'rate-sql'
import { queryBuilder } from 'rate-sql'
Named export is PascalCase; common mistake is using camelCase.
types
import type { SQLFragment } from 'rate-sql'
import { SQLFragment } from 'rate-sql'
SQLFragment is a type, prefer TypeScript type-only import to avoid runtime overhead.

Shows how to create a simple SELECT query with parameterized WHERE clause and retrieve the generated SQL text and values.

import RateSQL from 'rate-sql'; const sql = new RateSQL(); const query = sql .select('id', 'name') .from('users') .where('age', '>', 18) .build(); console.log(query.text); // 'SELECT id, name FROM users WHERE age > $1' console.log(query.values); // [18]
Debug
Known issues
breakingIn v0.2.0, the build() method returns { text, values } instead of the previous raw SQL string.
fix
Update code to destructure .text and .values from the result.
affects: >=0.2.0
deprecatedThe .raw() method is deprecated and will be removed in v1.0. Use .sql`` template literal instead.
fix
Replace .raw('SELECT * FROM table') with .sql`SELECT * FROM table`.
affects: >=0.1.5
gotchaCalling .build() twice on the same query instance yields the same result; the builder is immutable after build.
fix
Clone the instance before building if you need to reuse it.
affects: >=0.0.1
gotchaIn browser environments, window is used for global object; if not available, the library throws an error.
fix
Provide a polyfill for globalThis or use a bundler that injects it.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'rate-sql'
Package not installed or incorrect import path.
fix
Run 'npm install rate-sql' and ensure import is correct: import RateSQL from 'rate-sql'.
TypeError: RateSQL is not a constructor
Attempting to instantiate default export incorrectly, possibly due to CommonJS require in ESM context.
fix
Use ESM import: import RateSQL from 'rate-sql'; then new RateSQL().
node:internal/process/esm_loader:34 internalBinding('errors').triggerUncaughtException( ^ TypeError: Cannot read properties of undefined (reading 'text')
Destructuring result from .build() before calling it.
fix
Call .build() before destructuring: const result = query.build(); const { text, values } = result;
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
@types/nodeoptionalTypeScript type definitions required in development
Agent activity
7 hits · last 30 days
node
6
Meta
1
Resources
rate-sql — npm install rate-sql · libregistry