jasny/persist-sql-query
A lightweight PHP package for persisting SQL queries, offering a simple way to store reusable query definitions and execute them later with bound parameters. Useful for keeping complex SQL organized, reducing duplication, and maintaining cleaner database-driven applications.
Build vs. buy for "query-as-data" features. Most of the value here lands in one product decision: do we treat a query as a code artifact (hand-written DB::select()) or as stored, editable data? jasny/persist-sql-query is built for the second model — a query object that can be built in PHP, rendered to SQL, re-parsed from SQL, and persisted (serialized) for later retrieval. That directly unlocks:
->where() chains.INSERT ... ON DUPLICATE KEY UPDATE, INSERT ... SELECT, joined UPDATE/DELETE, and grouped/nested result hydration — bulk imports, sync jobs, and denormalized upserts. Worth a spike before we hand-roll these with raw SQL in five places.Roadmap fit. Treat this as infrastructure behind a feature bet, not a feature itself. If saved searches / configurable reporting is on the roadmap for the next two quarters, this package shortens the discovery-to-ship path. If it isn't, there is no standalone reason to adopt it.
Buy-side caveat to price in. Last release 2020-10-21, ~33 stars, single-maintainer. That is a maintenance cost we must budget explicitly: MIT license means we can fork and vendor it, and the surface area is a query builder — tractable to own — but someone must own it.
Adopt only when most of the following hold:
Look elsewhere — or build thin in-house — when:
To executives — one line: This is a small, MIT-licensed MySQL query library that lets us store a query the way we store any other record, then load, modify, and re-run it later. It is the cheapest credible path to saved searches and self-serve reporting, which are repeatedly requested and currently expensive to build.
The business case: Today, configurable reporting is bespoke work per feature. Modeling a query as persisted data turns each new report into configuration rather than engineering. That's a leverage argument, not a technology argument — it changes the marginal cost of the next report.
To engineering — the honest version: It does two things our stack does not: it parses SQL back into an object, and it renders and persists that object. That enables round-trip editing and MySQL syntax we currently write by hand (upserts, joined updates, insert-from-select, grouped hydration). The cost is explicit: it is MySQL-only, it does not integrate with Eloquent, and it has had no release since October 2020. We would vendor and own it. The code is a query builder — contained, testable, and MIT-licensed — so ownership is bounded, but it is not free.
The ask: A one-week spike behind a single feature (saved search or upsert-heavy import) to validate PHP-version compatibility, real query shapes, and the parse round-trip on our data. Success criteria: round-trip fidelity on our top ten queries, no Eloquent interop surprises, and a written position on forking. Failure is cheap and informative; success gives us a reusable primitive and a concrete fork-or-follow decision rather than an open-ended dependency.
The risk we are naming, not hiding: single maintainer, stale release, narrow community. We mitigate with a fork, a pin, and an owner. If the spike shows we mostly need the builder and not the parser, we should stop and use Laravel's builder — the parser is the reason to be here.
How can I help you explore Laravel packages today?