Giter Site home page Giter Site logo

growmies / sqlgenerate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jdrew1303/sqlgenerate

0.0 5.0 0.0 6.61 MB

Generates SQL when given an AST from the Codeschool/sqlite-parser

License: MIT License

JavaScript 0.83% PLpgSQL 30.93% TSQL 68.25%

sqlgenerate's Introduction

Overview | Features | Installation | Credits | Issues


Overview

SQLGenerate takes the Codeschool sqlite-parser AST and generates SQL from it. This allows you to read code (using the Codeschool parser), manipulate the AST (using SQLTraverse) and then generate SQL (using this library ๐Ÿ˜„).

โฌ†๏ธ

Features

โฌ†๏ธ

Installation

npm install sqlgenerator ๐Ÿ‘ done!

โฌ†๏ธ

Using this project

The blow example is a simple case of parsing SQL to an ast and then back again to SQL. One of the better use case for this is to modify your SQL somehow. To do this you can use sqltraverse (yes it's a shameless plug ๐Ÿ˜).

import parser       from 'sqlite-parser';
import { generate } from 'sqlgenerate';
import { format }   from "sql-formatter";

const example = `
  SELECT m.title, r.id AS [Theatre Number]
  FROM Movies AS m
  INNER JOIN (
    SELECT r2.movie_id
    FROM Rooms AS r2
    WHERE (r2.seats >= 50)
  ) AS r
  ON ((m.id = r.movie_id) AND (m.title != 'Batman'));`

const ast = parser(sql);
const regeneratedSQL = generate(ast);

console.log(format(regeneratedSQL));

โฌ†๏ธ

Credits

jdrew1303

Copyright (c) 2016

Issues

  • Tests, tests and more tests.
  • Documentation currently under construction (The examples need to be worked through for SQL instead of JavaScript).
  • AST is currently in a state of flux for some node types. We also probably need a builder for these nodes (another project).
  • You need to pass in ast.statement and not just the raw ast given back from the parser (This is an issue with the base node not having a type).
  • Adding support for comments.
  • Adding support for source-maps.

โฌ†๏ธ

sqlgenerate's People

Contributors

jdrew1303 avatar

Watchers

Scott Hillman avatar James Cloos avatar Cordon Davies avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.