guagualai/query-builder-helper

生成 SQL 语句并将参数传递进去

v1.0.0 2024-06-26 05:05 UTC

This package is auto-updated.

Last update: 2024-09-19 07:46:17 UTC


README

QueryBuilderHelper 是一个 PHP 包,旨在与 Laravel 的 Eloquent 查询构建器一起使用。它提供了一种方便的方式来获取原始 SQL 查询及其绑定,这对于调试和记录非常有用。

安装

您可以通过 composer 安装此包

composer require guagualai/query-builder-helper

用法

以下是如何使用 QueryBuilderHelper 的一个简单示例

use Guagualai\QueryBuilderHelper\SqlHelper;
use Illuminate\Database\Eloquent\Model;

class YourModel extends Model
{
    // Your model's methods...
}

$query = YourModel::where('column', 'value')->getQuery();
$sqlWithBindings = SqlHelper::getWithBindings($query);

echo $sqlWithBindings;

这将输出包含绑定的原始 SQL 查询,使得更容易看到将要针对数据库运行的实际查询。

示例输出

当您使用 QueryBuilderHelper 时,您可能会看到类似以下输出

// Example Eloquent query
$query = YourModel::where('name', 'John')->where('age', '>', 25)->getQuery();
$sqlWithBindings = SqlHelper::getWithBindings($query);

echo $sqlWithBindings;

输出将是

select * from `your_models` where `name` = 'John' and `age` > 25

许可证

MIT 许可证 (MIT)。请参阅许可证文件获取更多信息。