0.1.0 • Published 4 years ago

pg-ast v0.1.0

Weekly downloads
9
License
SEE LICENSE IN LI...
Repository
github
Last release
4 years ago

pg-ast Build Status

Create PostgreSQL ASTs with JavaScript

Installation

npm install pg-ast

Usage

import * as ast from 'pg-ast';
const node = ast.A_Expr({
    kind: 0,
    name: [ast.String({ str: '=' })],
    lexpr: ast.Integer({ ival: 0 }),
    rexpr: ast.Integer({ ival: 0 })
});

Pairs well with pgsql-parser

https://github.com/pyramation/pgsql-parser

You can create ASTs manually, and then generate your SQL:

import * as ast from '../src';
import { deparse } from 'pgsql-parser';

const node = ast.A_Expr({
  kind: 0,
  name: [ast.String({ str: '=' })],
  lexpr: ast.Integer({ ival: 0 }),
  rexpr: ast.Integer({ ival: 0 })
});
const sqlCode = deparse([node]);