pyaesoneaung/to-raw-sql

从 Laravel 查询构建器获取原始 SQL

v1.1.3 2023-07-07 08:25 UTC

README

Cover

GitHub Workflow Status Packagist Downloads

原始 SQL

⚠️ 默认情况下,toRawSql() 函数包含在 Laravel 10.15.0 中。如果你的 Laravel 版本高于 10.14.1,则不需要安装此包 ⚠️

从 Laravel 查询构建器和 Eloquent 构建器获取原始 SQL

安装

composer require pyaesoneaung/to-raw-sql

使用

User::where('votes', '>', 100)
    ->orWhere(function ($query) {
        $query->where('name', 'Abigail')
            ->where('votes', '>', 50);
    })
    ->toRawSql();

// "select * from `users` where `votes` > 100 or (`name` = 'Abigail' and `votes` > 50)"
DB::table('users')
   ->whereBetween('votes', [1, 100])
   ->toRawSql();

// "select * from `users` where `votes` between 1 and 100"

版本历史

  • 1.1.3
    • 如果 Laravel 版本高于 10.14.1,则不要注册 toRawSql()
  • 1.1.2
    • 遇到 PostgreSQL jsonb 操作符错误时抛出 ToRawSqlException
  • 1.1.1
    • 修复了 pgsql 的布尔绑定
  • 1.1.0
    • 支持 Illuminate\Database\Query\Builder
  • 1.0.2
    • 支持 DateTimeInterface 绑定
  • 1.0.1
    • 修复了字符串绑定
  • 1.0.0
    • 支持 Illuminate\Database\Eloquent\Builder

测试

composer test