π gq-to-sql v0.2.0 β Now with Grouping, Joins, and PostgreSQL Support!
I'm excited to announce the release of gq-to-sql
v0.2.0 β a powerful JavaScript utility that turns Microsoft Graph-style query strings into safe, parameterized SQL.
Whether you're building a REST API, internal tool, or dashboard interface, this utility gives you clean SQL generation from URLs like:
$select=name&$expand=roles($select=label)&$filter=roles.label eq 'admin'
β Whatβs New in v0.2.0
-
$expand=table($select=...)
with JOIN support $apply=groupby(..., aggregate(...))
- Combine
$apply + $filter
in one query - Support for SQL dialects:
-
mysql
(default):?
-
postgres
:$1
,$2
, ...
-
- Improved alias mapping & schema-based JOINs
π¦ Example
const query = "$select=name&$expand=roles($select=label)&$filter=roles.label eq 'admin'";
const { sql, params } = buildSQL(query, {
table: 'users',
schema: {
users: {
alias: 'u',
columns: ['id', 'name', 'role_id'],
joins: {
roles: {
type: 'LEFT',
on: 'u.role_id = r.id',
alias: 'r'
}
}
},
roles: {
alias: 'r',
columns: ['id', 'label']
}
},
placeholderStyle: 'postgres'
});
π Output:
SELECT u.name, r.label FROM users u LEFT JOIN roles r ON u.role_id = r.id WHERE r.label = $1
Install it:
npm install gq-to-sql
Source: github.com/masem1899/graphql-to-sql
npm: npmjs.com/package/gq-to-sql
Website: https://masem.at
Top comments (0)