Registry / database / dbgate-sqltree

dbgate-sqltree

JSON →
library7.1.13jsnpmunverified

dbgate-sqltree is a JavaScript/TypeScript SQL query-builder library that represents SQL queries as raw JSON objects. The current stable version is 7.1.13. It supports multiple SQL dialects including MySQL, PostgreSQL, MSSQL, and SQLite through driver plugins. Unlike ORM-based solutions, it provides a low-level, flexible JSON structure for constructing queries programmatically. The library is part of the dbgate ecosystem and relies on external database plugins for SQL dialect specifics. It is primarily used for generating SQL strings from query trees.

npm install dbgate-sqltree
INSTALL
IMPORT
SIG · DBGATE-SQLTREE
D
dbgate-sqltree
databasejavascriptv7.1.13
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.

treeToSql
✓ import { treeToSql } from 'dbgate-sqltree'
✗ const treeToSql = require('dbgate-sqltree').treeToSql
ESM import is preferred; CommonJS require works as shown, but ensure you access the named export correctly.
dumpSqlSelect
✓ import { dumpSqlSelect } from 'dbgate-sqltree'
✗ const dumpSqlSelect = require('dbgate-sqltree').dumpSqlSelect
Similar to treeToSql, this is a named export used as the format function in treeToSql.
default
✓ import * as sqltree from 'dbgate-sqltree'
✗ const sqltree = require('dbgate-sqltree')
Default import is not available; use namespace import to access all exports.

Shows how to create a SELECT query tree and convert it to SQL using MySQL dialect.

import { treeToSql, dumpSqlSelect } from 'dbgate-sqltree'; import mysqlDriver from 'dbgate-plugin-mysql'; const select = { commandType: 'select', from: { name: { pureName: 'Album' } }, columns: [{ exprType: 'column', columnName: 'name' }], orderBy: [{ exprType: 'column', columnName: 'id', direction: 'ASC' }], }; const sql = treeToSql(mysqlDriver, select, dumpSqlSelect); console.log(sql); // SELECT "Album"."name" FROM "Album" ORDER BY "Album"."id" ASC
Debug
Known issues
breakingVersion 7.x changed the structure of query tree nodes: 'exprType' is required for column expressions, and table references use { pureName: string } instead of a simple string.
fix
Update query trees to include exprType for columns and use { pureName: 'tableName' } for table names.
affects: >=7.0.0
gotchaThe library does not validate query objects; invalid JSON structures produce runtime errors or malformed SQL.
fix
Ensure your query tree matches the expected TypeScript interfaces (see types.ts in repo).
affects: all
deprecatedOlder versions used a different import path: require('dbgate-sqltree') provides treeToSql and other functions, but the preferred method is ESM import.
fix
Switch to ESM imports with named exports.
affects: <7.0.0
gotchaWhen using CommonJS require, you must use require('dbgate-sqltree').treeToSql. const { treeToSql } = require('dbgate-sqltree') may not work in all bundlers.
fix
Use ESM imports or destructure from the require result.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'dbgate-plugin-mysql'
The mysql driver plugin is not installed.
fix
Run npm install dbgate-plugin-mysql
TypeError: treeToSql is not a function
Incorrect import; possibly default import instead of named export.
fix
Use import { treeToSql } from 'dbgate-sqltree'
SyntaxError: Unexpected token ':' in JSON at position X
Invalid query tree structure, usually missing 'exprType' or invalid key.
fix
Ensure query object follows the TypeScript interfaces; check for typos.
Upgrade
Version history
7.1.13latest on npm
Audit
Dependencies
dbgate-plugin-mysqloptionalRequired to generate dialect-specific SQL for MySQL; other plugins for PostgreSQL, MSSQL, etc.
Agent activity
8 hits · last 30 days
node
7
Resources
dbgate-sqltree — npm install dbgate-sqltree · libregistry