{"id":43925,"library":"sql-motif","title":"sql-motif","description":"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.","status":"active","version":"0.5.6","language":"javascript","source_language":"en","source_url":"https://github.com/kanthoney/sql-motif","tags":["javascript","sql","query","builder","orm"],"install":[{"cmd":"npm install sql-motif","lang":"bash","label":"npm"},{"cmd":"yarn add sql-motif","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-motif","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for generating default UUIDs in type definitions","package":"uuid","optional":true}],"imports":[{"note":"Package exports a factory function; must call it to get instance.","wrong":"const motif = require('sql-motif');","symbol":"default","correct":"import motif from 'sql-motif'; const instance = motif({ types, dialect });"},{"note":"Table is not a direct export; it's returned from the factory function.","wrong":"const { Table } = require('sql-motif');","symbol":"Table","correct":"const { Table } = require('sql-motif')({ /* options */ });"},{"note":"Join is method on Table instance, not a standalone class.","wrong":"const { Join } = require('sql-motif');","symbol":"Join","correct":"const motif = require('sql-motif')({ /* options */ }); const table = new motif.Table({...}); table.join({...});"}],"quickstart":{"code":"const motif = require('sql-motif')({ types: {}, dialect: 'mysql' });\n\nconst orders = new motif.Table({\n  name: 'orders',\n  columns: [\n    { name: 'order_id', type: 'char(36)', notNull: true, primaryKey: true },\n    { name: 'order_date', type: 'date' },\n    { name: 'customer_name', type: 'varchar(40)' }\n  ]\n});\n\nconst join = orders.join({\n  table: new motif.Table({ name: 'order_lines', columns: [ { name: 'order_id', type: 'char(36)' }, { name: 'product', type: 'varchar(100)' } ] }),\n  name: 'lines',\n  on: 'order_id'\n});\n\nconst query = join.SelectWhere('*', { order_date: '2020-04-16' });\nconsole.log(query);\n// 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'","lang":"javascript","description":"Creates a table, joins another table, and generates a SELECT query with a WHERE clause."},"warnings":[{"fix":"Ensure motif = require('sql-motif')({ types, dialect });","message":"Factory function must be called with options object, otherwise returns default instance.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use valid dialect string like 'mysql', 'postgresql', or omit for default.","message":"The 'dialect' option may be deprecated or renamed; check documentation for supported dialects.","severity":"deprecated","affected_versions":"<=0.5.6"},{"fix":"Use join.selectWhere() if you need SELECT keyword in output.","message":"SelectWhere (capital S) omits SELECT keyword; use selectWhere (lowercase s) to include SELECT.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure type names match exactly, e.g., 'addressLine' not 'addressline'.","message":"Column types are case-sensitive and must match defined types exactly.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Define compound types carefully and use them only in table definitions.","message":"Compound types (e.g., address) expand to multiple columns; column count may cause unexpected SQL errors.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.5.6':23 'address':37 'becom':38 'builder':9,82 'cadenc':28 'column':34,40 'compos':50 'compound':33 'control':61 'current':19 'custom':31 'develop':64 'dialect':78 'e.g':36 'expans':35 'featur':70 'field':56 'fill':69 'flexibl':5 'focus':48 'fragment':8,51 'full':16,45,59 'generat':13 'includ':66 'irregular':27 'javascript':79 'join/collation':42 'leav':58 'like':55 'list':57 'motif':3 'multipl':39 'mysql':77 'node.js':11 'orm':46,83 'part':54 'partial':14 'postgresql':75 'queri':7,18,60,81 'record':72 'releas':24 'sql':2,6,17,80 'sql-motif':1 'stabl':20 'support':30,74 'tedious':53 'type':32 'unlik':44 'util':43 'valid':67 'version':21","created_at":"2026-06-05T17:02:08.320806+00:00","updated_at":"2026-06-05T17:02:08.320806+00:00","problems":[{"fix":"const instance = require('sql-motif')({ types: {} }); const orders = new instance.Table({...});","cause":"Imported motif without calling the factory function first.","error":"TypeError: motif.Table is not a constructor"},{"fix":"Pass { dialect: 'mysql' } or { dialect: 'postgresql' } to factory.","cause":"No dialect specified or dialect string invalid.","error":"Error: Missing required option 'dialect'"},{"fix":"Install and import uuid: const uuid = require('uuid'); then use it in type definitions.","cause":"Used 'id' type with default that calls uuid.v4() without importing uuid.","error":"ReferenceError: uuid is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/kanthoney/sql-motif#readme","github":"https://github.com/kanthoney/sql-motif","docs":null,"changelog":null,"pypi":null,"npm":"sql-motif","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}