Registry / database / sql-bricks-mysql

sql-bricks-mysql

JSON →
library0.1.4jsnpmunverified

MySQL extension for the SQL Bricks query builder library. Provides MySQL-specific features such as proper date conversion, correct escaping of MySQL reserved words, and support for LIMIT/OFFSET clauses. Compatible with Node.js >=5.0.0. Current version 0.1.4. Lightweight and minimal alternative to larger ORMs.

npm install sql-bricks-mysql
INSTALL
IMPORT
SIG · SQL-BRICKS-MYSQL
S
sql-bricks-mysql
databasejavascriptv0.1.4
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 (library)
import sql from 'sql-bricks-mysql'
import sql from 'sql-bricks-mysql/sql-bricks-mysql'
Default import gives you the extended SQL Bricks instance.
require
const sql = require('sql-bricks-mysql')
const sql = require('sql-bricks-mysql').default
CJS require works directly; no .default needed.
named import (if using specific features)
import { select, insert } from 'sql-bricks-mysql'
import { select, insert } from 'sql-bricks'
Named exports mirror sql-bricks but with MySQL overrides.

Demonstrates basic SELECT with LIMIT and INSERT with automatic date conversion using sql-bricks-mysql.

const sql = require('sql-bricks-mysql'); // SELECT with LIMIT const query = sql.select().from('users').where({active: true}).limit(10); console.log(query.toString()); // SELECT * FROM users WHERE active = TRUE LIMIT 10 // INSERT with dates const insert = sql.insert('events', { name: 'test', date: new Date('2024-01-01') }); console.log(insert.toString()); // INSERT INTO events (name, date) VALUES ('test', '2024-01-01 00:00:00')
Debug
Known issues
gotchaLIMIT must be called before OFFSET in chain or results in incorrect SQL order.
fix
Always call .limit() before .offset() to ensure correct syntax.
affects: >=0.0.0
deprecatedNode.js <5.0.0 is not supported; using older Node will cause errors.
fix
Upgrade Node.js to version 5.0.0 or higher.
affects: <5.0.0
gotchaReserved word escaping is MySQL-specific; using this library with other databases may produce invalid SQL.
fix
Only use this extension for MySQL databases.
affects: >=0.0.0
gotchaDate conversion is automatically applied to Date objects; if you pass a date string, it will not be converted and may cause SQL errors.
fix
Ensure date values are JavaScript Date objects, not strings.
affects: >=0.0.0
gotchaLIMIT and OFFSET only work with SELECT statements; applying them to INSERT/UPDATE/DELETE may produce unexpected SQL.
fix
Only chain .limit() and .offset() on SELECT queries.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: sql.select(...).limit is not a function
Using sql-bricks instead of sql-bricks-mysql; .limit() is only available in the MySQL extension.
fix
Replace require('sql-bricks') with require('sql-bricks-mysql').
Error: MySQL syntax error near 'LIMIT 10 OFFSET 5'
Calling .offset() before .limit() in a method chain.
fix
Reorder methods: .limit(10).offset(5) instead of .offset(5).limit(10).
ReferenceError: sql is not defined
Forgetting to import or require sql-bricks-mysql before use.
fix
Add const sql = require('sql-bricks-mysql'); at the top of your file.
Invalid Date in SQL output
Passing a date string instead of a Date object to an INSERT or UPDATE.
fix
Use new Date('2024-01-01') instead of '2024-01-01'.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
sql-bricksrequiredCore SQL query builder library that this extension builds upon.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
2
Meta
1
Resources
sql-bricks-mysql — npm install sql-bricks-mysql · libregistry