Without Laravel
The parser core has no Laravel dependency. Use it in plain PHP scripts, packages, or long-running workers.
Transpile
use Kwasii\LaravelSqlParser\Dialects\Dialect;
Dialect::transpile('SELECT IFNULL(a, 1)', read: 'mysql', write: 'postgres');
// ['SELECT COALESCE(a, 1)']
Parse
$tree = Dialect::get('mysql')->parseOne('SELECT 1');
$tree->sql('postgres');
$tree->sql('sqlite');
Resolve dialects
$dialect = Dialect::get('mysql'); // by name
$dialect = Dialect::get('pgsql'); // Laravel driver names work too
$dialect = Dialect::get($dialect); // instances pass through
Register custom dialects without config:
Dialect::register('mydialect', MyDialect::class);
What needs Laravel
Only these features require the framework:
- The
LaravelSqlParser facade and service provider
default_dialect fallback to your DB connection driver
- Query-builder macros (
toSqlFor, bindingsFor, toRawSqlFor)
- Laravel cache integration and the
sql:transpile Artisan command
Everything else — tokenizing, parsing, generating, building, optimizing, serializing — is framework-free.