postgresql-to-knex
postgresql-to-knex is a library for converting Postgresql queries into knex.js.
Installation
Use the package manager npm to install postgresql-to-knex.
npm i postgresql-to-knex
Description
postgresql-to-knex is a library to accelerate the project development process. Usually, many developers first write SQL queries than convert that code to knex. Sometimes SQL queries are a long line of code and it is difficult to convert that code into knex. postgresql-to-knex library can help developers with this problem. The developer can pass the SQL query to the library function and get knex code.
Example
const to_knex = console// knex.select(`*`, ).from(`users`) console// knex.select(`a`, `fruit_a`, `b`, `fruit_b`, ).from(`basket_a`).innerJoin(`basket_b`, function() { this.on("fruit_a","=","fruit_b")}) console// knex.select(`*`, ).from(`top_rated_films`).union([knex.select(`*`, ).from(`most_popular_films`)]) console// knex.select(`*`, ).from(`users`).groupByRaw(`count`).having("count",">","100").orderByRaw(`name DESC`) console// knex.with(`cte`, (knex) => { (knex.select(`id`, `name`, `age`, `address`, `salary`, ).from(`company`)) }).select(`*`, ).from(`cte`) console// knex.withRecursive(`r`, (knex) => { (knex.select(knex.raw(`1 AS i`),knex.raw(`1 AS factorial`),).union([knex.select(knex.raw(`i + 1 AS i`),knex.raw(`factorial * i + 1 AS factorial`),).from(`r`).where("i","<","10")])) }).select(`*`, ).from(`r`)
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Note, this package is in the development process. INSERT, DELETE queries haven't been implemented yet.
Authors
Davronbek Tursunov
email: davron.tursunov.2014@mail.ru
gitHub: https://github.com/davrontb