PHPackages                             hershel-theodore-layton/sql-queryf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. hershel-theodore-layton/sql-queryf

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

hershel-theodore-layton/sql-queryf
==================================

Render queryf-style SQL queries to strings for logging and debugging

v0.2.2(2mo ago)0421↓33.3%1MITHackCI passing

Since Jul 5Pushed 2mo agoCompare

[ Source](https://github.com/hershel-theodore-layton/sql-queryf)[ Packagist](https://packagist.org/packages/hershel-theodore-layton/sql-queryf)[ RSS](/packages/hershel-theodore-layton-sql-queryf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (1)

SQL Queryf
==========

[](#sql-queryf)

*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
---------------

[](#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?
-------------------------------------------------------

[](#why-dont-i-use-hhlibsqlquerys-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
---------

[](#migration)

If you use `HH\Lib\SQL\Query`, create these functions in your namespace:

```
type QueryType = SQL\Query;

function queryf(
  HH\FormatString $format,
  mixed ...$args
)[defaults]: QueryType {
  return \HH\FIXME\UNSAFE_CAST(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 $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(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
---------------------------

[](#expanding-the-possibilities)

Now that you own the `HH\FormatString` 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 `QueryPack` to `SQL\Query`.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance84

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~77 days

Total

4

Last Release

83d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d16d159b7061287c506d4ab44d05ae042bc4ec697116d1bd132a007634d9ff21?d=identicon)[Hershel Theodore Layton](/maintainers/Hershel%20Theodore%20Layton)

---

Top Contributors

[![hershel-theodore-layton](https://avatars.githubusercontent.com/u/81193606?v=4)](https://github.com/hershel-theodore-layton "hershel-theodore-layton (15 commits)")

### Embed Badge

![Health badge](/badges/hershel-theodore-layton-sql-queryf/health.svg)

```
[![Health](https://phpackages.com/badges/hershel-theodore-layton-sql-queryf/health.svg)](https://phpackages.com/packages/hershel-theodore-layton-sql-queryf)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[ekino/newrelic-bundle

Integrate New Relic into Symfony2

28111.2M8](/packages/ekino-newrelic-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
