Registry / database / tougo-query-builder

tougo-query-builder

JSON →
library1.3.7jsnpmunverified

A lightweight JavaScript query builder for PostgreSQL that constructs raw SQL queries programmatically. Version 1.3.7 is current, with a dependency on the 'pg' package added in 1.3.5 allowing direct database queries from Express routes. It supports SELECT, FROM, JOIN, WHERE, UPDATE, and spatial functions (ST_Transform, ST_GeomFromText). Distinctive for its minimal API and optional direct query execution via connection string, but lacks TypeScript types and modern ESM support. Suitable for small projects needing simple SQL generation without an ORM.

npm install tougo-query-builder
INSTALL
IMPORT
SIG · TOUGO-QUERY-BUILDE
T
tougo-query-builder
databasejavascriptv1.3.7
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 (Constructor)
var qb = require('tougo-query-builder');
import qb from 'tougo-query-builder';
Package is CommonJS only; ES import will fail.
spatial
var qsp = new qb.spatial;
var qsp = qb.spatial();
spatial is a constructor property on the main constructor, not a function. Must instantiate with 'new'.
query property
var q = qb.select('*').from('property').query;
var q = qb.select('*').from('property');
The .query property (not method) returns the final SQL string. Accessing the builder object directly yields an object, not a string.

Demonstrates basic query building and spatial function usage with tougo-query-builder.

var qb = require('tougo-query-builder'); var builder = new qb(); var sql = builder.select('*').from('users').where('id = 1').query; console.log(sql); // SELECT * FROM users WHERE id = 1 var qsp = new qb.spatial(); var spatialSql = qsp.Transform("POINT(0 0)", 4326, 32633).query; console.log(spatialSql); // ST_Transform(ST_GeomFromText('POINT(0 0)',4326),32633)
Debug
Known issues
breakingv1.3.5 introduced a hard dependency on the 'pg' package. Direct query execution via connectandquery may fail if 'pg' is not installed.
fix
npm install pg
affects: >=1.3.5
gotchaThe .query property returns the final SQL string but is accessed as a property, not a method. Accidentally calling it as a function returns undefined.
fix
Always access .query without parentheses: builder.select(...).query;
affects: *
gotchaSpatial functions require separate instantiation via new qb.spatial(). Cannot call qb.spatial.Transform() directly.
fix
var qsp = new qb.spatial(); qsp.Transform(...);
affects: *
deprecatedPackage is CommonJS-only with no ESM exports. Using 'import' will error.
fix
Use require() or switch to an ESM-compatible query builder.
affects: *
Errors
Common errors & fixes
Cannot find module 'tougo-query-builder'
Package not installed or misspelled in require/import.
fix
npm install tougo-query-builder
qb.spatial is not a constructor
Trying to use qb.spatial as a function directly.
fix
var qsp = new qb.spatial();
TypeError: qb.select is not a function
Forgot to instantiate the constructor: var qb = require('tougo-query-builder'); then new qb();
fix
var instance = new (require('tougo-query-builder'))();
Upgrade
Version history
1.3.7latest on npm
Audit
Dependencies
pgoptionalRequired for connectandquery and direct database interaction since v1.3.5
Agent activity
16 hits · last 30 days
node
12
Meta
1
Amazon
1
OpenAI (training)
1
Resources
tougo-query-builder — npm install tougo-query-builder · libregistry