Registry / database / sql-motif

sql-motif

JSON →
library0.5.6jsnpmunverified

A flexible SQL query fragment builder for Node.js that generates partial or full SQL queries. Current stable version is 0.5.6, released on an irregular cadence. It supports custom types, compound column expansion (e.g., addresses becoming multiple columns), and join/collation utilities. Unlike full ORMs, it focuses on composing fragments for tedious parts like field lists, leaving full query control to the developer. It includes validation and fill features for records, and supports PostgreSQL and MySQL dialects.

npm install sql-motif
INSTALL
IMPORT
SIG · SQL-MOTIF
S
sql-motif
databasejavascriptv0.5.6
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 motif from 'sql-motif'; const instance = motif({ types, dialect });
✗ const motif = require('sql-motif');
Package exports a factory function; must call it to get instance.
Table
✓ const { Table } = require('sql-motif')({ /* options */ });
✗ const { Table } = require('sql-motif');
Table is not a direct export; it's returned from the factory function.
Join
✓ const motif = require('sql-motif')({ /* options */ }); const table = new motif.Table({...}); table.join({...});
✗ const { Join } = require('sql-motif');
Join is method on Table instance, not a standalone class.

Creates a table, joins another table, and generates a SELECT query with a WHERE clause.

const motif = require('sql-motif')({ types: {}, dialect: 'mysql' }); const orders = new motif.Table({ name: 'orders', columns: [ { name: 'order_id', type: 'char(36)', notNull: true, primaryKey: true }, { name: 'order_date', type: 'date' }, { name: 'customer_name', type: 'varchar(40)' } ] }); const join = orders.join({ table: new motif.Table({ name: 'order_lines', columns: [ { name: 'order_id', type: 'char(36)' }, { name: 'product', type: 'varchar(100)' } ] }), name: 'lines', on: 'order_id' }); const query = join.SelectWhere('*', { order_date: '2020-04-16' }); console.log(query); // Outputs: SELECT orders.*, order_lines.* FROM orders LEFT JOIN order_lines ON orders.order_id = order_lines.order_id WHERE orders.order_date = '2020-04-16'
Debug
Known issues
gotchaFactory function must be called with options object, otherwise returns default instance.
fix
Ensure motif = require('sql-motif')({ types, dialect });
affects: >=0.0.0
deprecatedThe 'dialect' option may be deprecated or renamed; check documentation for supported dialects.
fix
Use valid dialect string like 'mysql', 'postgresql', or omit for default.
affects: <=0.5.6
gotchaSelectWhere (capital S) omits SELECT keyword; use selectWhere (lowercase s) to include SELECT.
fix
Use join.selectWhere() if you need SELECT keyword in output.
affects: >=0.0.0
gotchaColumn types are case-sensitive and must match defined types exactly.
fix
Ensure type names match exactly, e.g., 'addressLine' not 'addressline'.
affects: >=0.0.0
gotchaCompound types (e.g., address) expand to multiple columns; column count may cause unexpected SQL errors.
fix
Define compound types carefully and use them only in table definitions.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: motif.Table is not a constructor
Imported motif without calling the factory function first.
fix
const instance = require('sql-motif')({ types: {} }); const orders = new instance.Table({...});
Error: Missing required option 'dialect'
No dialect specified or dialect string invalid.
fix
Pass { dialect: 'mysql' } or { dialect: 'postgresql' } to factory.
ReferenceError: uuid is not defined
Used 'id' type with default that calls uuid.v4() without importing uuid.
fix
Install and import uuid: const uuid = require('uuid'); then use it in type definitions.
Upgrade
Version history
0.5.6latest on npm
Audit
Dependencies
uuidoptionalUsed for generating default UUIDs in type definitions
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
sql-motif — npm install sql-motif · libregistry