Giter Site home page Giter Site logo

sql2builder.github.io's Introduction

sql2builder.github.io

Convert legacy SQL to Laravel query builder.

Run in local

  1. npm install
  2. npm run start

sql2builder.github.io's People

Contributors

dependabot[bot] avatar liquid207 avatar sql2builder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sql2builder.github.io's Issues

Readme for local install

Dear author,

I am trying to run your project locally, but cannot succeed. Can you please provide a short readme on running the sql2builder converter locally?

Best wishes,
Tural

Support for: INSERT ... SET expression

at this moment, this expression is 'silently' throwing an error complaining about 'VALUES' key that does not exists. It should combine UPDATE features

can't do limits

SELECT pondok.no_pondok FROM pondok ORDER BY pondok.id DESC limit 1;

DB::table('pondok') ->select('pondok.no_pondok') ->orderBy('pondok.id','desc') ->get();

it should be like this
DB::table('pondok') ->select('pondok.no_pondok') ->orderBy('pondok.id','desc') ->limit(1) ->get();

so much advice from me, thank you

Left join method not closing

SELECT
    order_notes.*
FROM
    order_new
    LEFT JOIN order_notes
                  ON order_notes.order_id = order_new.id AND order_notes.parent_order_note_id = 0 AND
                     order_notes.order_note_nr = 0
    LEFT JOIN mrt
                  ON mrt.id = order_notes.serial_id AND order_notes.serial_id > 0
    LEFT JOIN label
                  ON label.id = mrt.label_id AND mrt.label_id > 0
    LEFT JOIN id
                  ON id.id = label.id
WHERE
    order_new.id = 114

produces:

DB::table('order_new')
->select('order_notes.*')
->leftJoin('order_notes',function($join) {
	$join->on('order_notes.order_id','=','order_new.id')
	->where('order_notes.parent_order_note_id','=',0)
	->where('order_notes.order_note_nr','=',0);
}
->leftJoin('mrt',function($join) {
	$join->on('mrt.id','=','order_notes.serial_id')
	->where('order_notes.serial_id','>',0);
}
->leftJoin('label',function($join) {
	$join->on('label.id','=','mrt.label_id')
	->where('mrt.label_id','>',0);
}
->leftJoin('id','id.id','=','label.id')
->where('order_new.id','=',114)
->get();

There's a ) misssing after each leftJoin

Feature: Support Union

This request is to add a feature for SQL Unions.

Laravel Docs: Laravel Eloquent Unions
MySQL Docs: MySQL 8.1 UNION Clause

Union Example

Example SQL input:

(select * from `users` where `last_name` is null) union (select * from `users` where `first_name` is null)

Example Eloquent output:

DB::table('users')
->whereNull('last_name')
->union(
            DB::table('users')
            ->whereNull('first_name')
)
->get();

Union All Example

Example SQL input:

(select * from `users` where `last_name` is null) union all (select * from `users` where `first_name` is null)

Example Eloquent output:

DB::table('users')
->whereNull('last_name')
->unionAll(
            DB::table('users')
            ->whereNull('first_name')
)
->get();

Union with orderBy on id

Example SQL input:

(select * from `users` where `last_name` is null) 
union
(select * from `users` where `first_name` is null) 
order by `id` asc

Example Eloquent output:

DB::table('users')
->whereNull('last_name')
->unionAll(
            DB::table('users')
            ->whereNull('first_name')
)
->orderBy('id')
->get();

Additional Context

While Eloquent doesn't handle returning a UNION from multiple models well (everything will be shoved into the first model's class), it does handle it well as a subselect with multiple models. It makes it much easier to scan across many different models as part of a very complex where.

Bug with Table Aliases

I'm currently having trouble trying to convert SQL with table aliases. So with the following query:

select
	*
from
	purchase_order_headers poh
where
	not exists (
	select
		pr.id
	from
		purchase_requests pr
	where
		pr.purchase_order_header_id = poh.id)

I get results like the following code:

DB::table('purchase_order_headers')
    ->select('*')
    ->whereNotExists(function ($query) {
        $query->from('purchase_requests')
            ->select('purchase_requests.id')
            ->where('purchase_requests.purchase_order_header_id','=',DB::raw('poh.id'));
    }
    ->get();

The problem is in DB::raw('poh.id'), so instead of getting poh.id it should be purchase_order_headers.id. Hope this can be fixed, and thanks for this awesome tool!

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.