hershel-theodore-layton/sql-queryf
Composer 安装命令:
composer require hershel-theodore-layton/sql-queryf
包简介
Render queryf-style SQL queries to strings for logging and debugging
README 文档
README
Render queryf-style SQL queries to strings for logging and debugging.
SqlQueryf\ToString\engine() will render queries for logging and
debugging purposes. For example, if you have a syntax error in the query you
just ran, you might want to add the query to the exception message to aid the
developer in fixing it.
Security Notice
SqlQueryf\ToString\engine() is meant for logging and debugging. Do NOT
pass the returned query to a database. This is a bad idea, since SQL escaping
has been mocked out with fake_mysql_escape_UNSAFE. Please for all that
is good, don't!
Why don't I use HH\Lib\SQL\Query’s built-in methods?
If your application uses HH\Lib\SQL\Query, and want to use
toString__FOR_DEBUGGING_ONLY for this purpose, you might tear down your
entire hhvm instance with a segmentation fault. This method is broken and
should not be used. The method toUnescapedString__FOR_DEBUGGING_ONLY__UNSAFE
does work, but the result is very difficult to read. Strings with quotes or
slashes break the SQL syntax and the renderer tries to save bytes by
inserting as little whitespace as possible.
Migration
If you use HH\Lib\SQL\Query, create these functions in your namespace:
type QueryType = SQL\Query; function queryf( HH\FormatString<SQL\QueryFormat> $format, mixed ...$args )[defaults]: QueryType { return \HH\FIXME\UNSAFE_CAST<dynamic, dynamic>(SQL\Query::class) |> new $$($format, $args); } function query_to_native(QueryType $query)[]: SQL\Query { return $query; }
Replace usages of new SQL\Query() with queryf() and $db->queryAsync($q)
with $db->queryAsync(query_to_native($q)). Then replace references to the
SQL\Query type with the QueryType type. This will change nothing about
your application.
You are now ready to make the switch to:
type QueryType = SqlQueryf\HipHopLibSqlQueryPack; function queryf( HH\FormatString<ToString\Sql> $format, mixed ...$args )[]: SqlQueryf\HipHopLibSqlQueryPack { return SqlQueryf\HipHopLibSqlQueryPack::createWithoutTypechecking_UNSAFE( $format as string, vec($args), ); } function query_to_native( SqlQueryf\HipHopLibSqlQueryPack $query, )[defaults]: SQL\Query { $args = vec[]; foreach ($pack->getArguments() as $a) { if ($a is SqlQueryf\HipHopLibSqlQueryPack) { $args[] = query_to_native($a); } else { $args[] = $a; } } return \HH\FIXME\UNSAFE_CAST<dynamic, dynamic>(SQL\Query::class) |> new $$($pack->getFormat(), $args); }
Use of the __FOR_DEBUGGING_ONLY methods will now be a type error.
Replace them with a call to:
function queryf_to_string( SqlQueryf\HipHopLibSqlQueryPack $query )[]: string { return ToString\engine($query->getFormat(), $query->getArguments()) |> \vsprintf(...$$); }
Congratulations on a successful migration.
Expanding the possibilities
Now that you own the HH\FormatString<T> type for your queries, you may want
to add specifiers that are not part of the set provided by SQL\Query.
You can create any engine() and transform from PackedQuery to SQL\Query.
hershel-theodore-layton/sql-queryf 适用场景与选型建议
hershel-theodore-layton/sql-queryf 是一款 基于 Hack 开发的 Composer 扩展包,目前已累计 669 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hershel-theodore-layton/sql-queryf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hershel-theodore-layton/sql-queryf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 669
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-22