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-16 20:59:08 +00:00
|
|
|
const { treeToSql, dumpSqlSelect } = require('dbgate-sqltree');
|
|
|
|
const engines = require('dbgate-engines');
|
2020-11-16 20:35:18 +00:00
|
|
|
|
|
|
|
const select = {
|
|
|
|
commandType: 'select',
|
|
|
|
from: { name: 'Album' },
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
exprType: 'column',
|
|
|
|
columnName: 'name',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})),
|
|
|
|
orderBy: [
|
|
|
|
{
|
|
|
|
exprType: 'column',
|
|
|
|
columnName: 'id',
|
|
|
|
direction: 'ASC',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const sql = treeToSql(engines('mysql'), select, dumpSqlSelect);
|
|
|
|
console.log('Generated SQL', sqll);
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2020-11-16 20:59:08 +00:00
|
|
|
yarn add dbgate-sqltree
|