Convert legacy SQL to Laravel query builder.
- npm install
- npm run start
Convert legacy SQL to Laravel query builder.
Home Page: https://sql2builder.github.io/
License: Apache License 2.0
I want to run UPDATE todo SET todo = "data update" WHERE todo.id = 14;
but the result are given SQL must start with select or SELECT
xx
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
at this moment, this expression is 'silently' throwing an error complaining about 'VALUES' key that does not exists. It should combine UPDATE features
xx
xx
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
I'm having a problem with this.
converts to whereNotIn and the sql has no .. SELECT ...NOT IN...
I think that it must be whereIn
Thx
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
This request is to add a feature for SQL Unions.
Laravel Docs: Laravel Eloquent Unions
MySQL Docs: MySQL 8.1 UNION Clause
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();
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();
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();
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.
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.