2020-11-16 20:59:08 +00:00
# dbgate-sqltree
2020-11-16 20:35:18 +00:00
JavaScript/TypeScript SQL query-builder library
2020-11-16 20:59:08 +00:00
dbgate-sqltree hold query definition in RAW JSON objects.
2020-11-16 20:35:18 +00:00
## Sample usage
```javascript
2020-11-17 07:27:14 +00:00
const { treeToSql, dumpSqlSelect } = require("dbgate-sqltree");
2020-11-30 19:13:31 +00:00
const dbgatePluginMysql = require("dbgate-plugin-mysql");
2020-11-16 20:35:18 +00:00
const select = {
2020-11-17 07:27:14 +00:00
commandType: "select",
from: {
name: {
pureName: "Album",
},
},
2020-11-16 20:35:18 +00:00
columns: [
2020-11-17 07:27:14 +00:00
{
exprType: "column",
columnName: "name",
},
],
2020-11-16 20:35:18 +00:00
orderBy: [
{
2020-11-17 07:27:14 +00:00
exprType: "column",
columnName: "id",
direction: "ASC",
2020-11-16 20:35:18 +00:00
},
],
};
2020-11-30 19:13:31 +00:00
const sql = treeToSql(dbgatePluginMysql.driver, select, dumpSqlSelect);
2020-11-17 07:27:14 +00:00
console.log("Generated query:", sql);
2020-11-16 20:35:18 +00:00
```
2021-02-11 09:11:34 +00:00
See [TypeScript definitions ](https://github.com/dbgate/dbgate/blob/master/packages/sqltree/src/types.ts ) for complete list of available SQL command options.
2020-11-17 07:27:14 +00:00
2020-11-16 20:35:18 +00:00
## Installation
2020-11-16 20:59:08 +00:00
yarn add dbgate-sqltree