Registry / database / waterline-sql-builder

waterline-sql-builder

JSON →
library3.0.1jsnpmunverified

Generate SQL queries (stage 5 queries) from Waterline statements (stage 4 queries). Latest version 3.0.1. Released March 2023. Used internally by Sails/Waterline SQL adapters. Replaces Waterline-Sequel; not backwards compatible. Uses knex to compile SQL and supports PostgreSQL, MySQL, Oracle, MSSQL. Intended for adapter authors, not app-level code.

npm install waterline-sql-builder
INSTALL
IMPORT
SIG · WATERLINE-SQL-BUIL
W
waterline-sql-builder
databasejavascriptv3.0.1
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
const SQLBuilder = require('waterline-sql-builder');
import SQLBuilder from 'waterline-sql-builder';
This package does not export ES modules; use CommonJS require().
compile
const compile = require('waterline-sql-builder')({ dialect: 'postgres' }).generate;
const { compile } = require('waterline-sql-builder');
Call the default export with a config object, then use the .generate method on the returned instance.
SQLBuilder
const SQLBuilder = require('waterline-sql-builder'); const builder = SQLBuilder({ dialect: 'postgres' }); const compile = builder.generate;
Create an instance by calling the constructor with a dialect option.

Creates a SQL builder instance for PostgreSQL and compiles a Waterline stage 4 query into a SQL template string with bindings.

const SQLBuilder = require('waterline-sql-builder'); const compile = SQLBuilder({ dialect: 'postgres' }).generate; const report = compile({ select: ['id', 'name'], where: { age: { '>': 18 }, status: 'active' }, from: 'users', limit: 10 }); console.log(report.sql); console.log(report.bindings);
Debug
Known issues
breakingThis package is NOT backwards compatible with Waterline-Sequel.
fix
Migrate from Waterline-Sequel to waterline-sql-builder; see migration guide in Waterline adapter interface docs.
affects: >=1.0.0
gotchaThis package is meant for adapter authors, not app-level code. Using Waterline statements from app-level code is experimental and may break with major version bumps.
fix
Use Sails's model methods (e.g., User.find()) for app-level queries instead of waterline-sql-builder directly.
affects: >=1.0.0
deprecatedThe 'mssql' dialect may not be fully supported in future versions.
fix
Consider using 'mssql' only if necessary; test thoroughly.
affects: >=2.0.0
gotchaThe package expects a stage 4 query; providing an invalid or malformed query may result in unexpected errors.
fix
Validate your stage 4 query structure against Waterline's architecture docs before passing it to compile.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'waterline-sql-builder'
Package not installed or installed incorrectly.
fix
Run 'npm install waterline-sql-builder --save'
TypeError: SQLBuilder is not a constructor
Using ES import syntax with a CommonJS-only module.
fix
Use 'const SQLBuilder = require('waterline-sql-builder');' instead of import.
Error: Unrecognized dialect. Supported dialects: postgresql, postgres, mysql, oracle, mssql, sqlite3
Providing an unsupported dialect in the config object.
fix
Use one of the supported dialects: 'postgresql', 'postgres', 'mysql', 'oracle', 'mssql', or 'sqlite3'.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
knexrequiredUsed internally to compile SQL queries
@sailshq/lodashrequiredUtility library for object/array manipulation
Agent activity
23 hits · last 30 days
node
18
Meta
2
OpenAI (training)
1
Resources
waterline-sql-builder — npm install waterline-sql-builder · libregistry