Registry / database / chill-sql

chill-sql

JSON →
library2.0.0jsnpmunverified

Type-safe MySQL query builder for TypeScript (v2.0.0). Creates SQL queries with full TypeScript inference from user-defined table schemas, supporting select, insert, update, delete, joins, subqueries, transactions, and logging. Requires mysql2 at runtime. Release cadence appears slow (v2.0.0 significant change from v1). Differentiator: zero global side-effects, NULL vs undefined semantics correctly map to IS NULL vs skip, and where(undefined) is a no-op for dynamic conditions. Ships TypeScript types. Requires Node.js >= 18 and TypeScript >= 4.7.

npm install chill-sql
INSTALL
IMPORT
SIG · CHILL-SQL
C
chill-sql
databasejavascriptv2.0.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.

createMysqlClient
✓ import { createMysqlClient } from 'chill-sql'
✗ import { createMysqlClient } from 'chill-sql/query'
Main factory function, always from top-level module
mysql2
✓ import { PoolOptions } from 'mysql2'
✗ import { PoolOptions } from 'chill-sql'
mysql2 is a peer dependency, not bundled
chill-sql
✓ import { createMysqlClient } from 'chill-sql'
✗ const chillSql = require('chill-sql')
Require works but lacks TypeScript types; prefer ESM

Shows creating a MySQL client with table schemas, selecting all rows, inserting, and updating with a condition.

import { createMysqlClient } from 'chill-sql'; // Define table schemas type User = { user_id: string; user_name: string; user_email?: string; }; type MyTables = { user: User }; // Create client const mysqlClient = createMysqlClient<MyTables>({ host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test', }); // Query all users const users = await mysqlClient.tables.user.select('*').exec(); // Insert a user await mysqlClient.tables.user.insert({ user_id: 'abc', user_name: 'Bob' }).exec(); // Update with condition await mysqlClient.tables.user.update({ user_email: 'bob@example.com' }) .where(e => e.user_id.eq('abc')) .exec();
Debug
Known issues
breakingv2.0.0 changed the API significantly from v1.x. The `mysqlClient.tables` pattern replaced older query builder. All existing code using the old API will break.
fix
Migrate to v2.0.0 API: define table types, use mysqlClient.tables.tableName.select(...).exec() instead of the previous chain.
affects: <=1.x
deprecatedSome users may rely on undocumented internal methods (e.g., `toSqlQuery`) that could be removed in future minor releases.
fix
Use only documented public API: `exec()`, `toSqlQuery()` is public but not guaranteed stable; consider refactoring.
affects: >=2.0.0
gotchaNULL vs undefined: passing null to insert/update writes SQL NULL; passing undefined skips the field. Confusing if you expect undefined to become NULL.
fix
Use null explicitly when you want to set a column to NULL, undefined when you want to omit the column from the query.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'mysql2'
mysql2 is a peer dependency and must be installed separately.
fix
Run `npm install mysql2` or ensure it's in your package.json dependencies.
Property 'select' does not exist on type 'Table<...>'
Using a table object directly instead of via mysqlClient.tables.tableName
fix
Use `mysqlClient.tables.user.select('*').exec()` not `tables.user.select(...)`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
mysql2requiredRuntime database driver, not included by chill-sql
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
chill-sql — npm install chill-sql · libregistry