michael-rubel/laravel-sql-function-repository
A lightweight Laravel package that brings the repository pattern to SQL functions, letting you call database functions and stored procedures through clean, testable classes with bound parameters instead of scattered raw queries.
What the package is. A thin repository abstraction over PostgreSQL stored functions — you define a repository, and calling a method translates into a SELECT * FROM fn_name(?, ?)-style invocation through Laravel's DB layer. It is a convenience wrapper, not an ORM, not a query builder, and not a persistence layer. Package surface is small (repository base class plus supporting traits/contracts), which still matters a great deal for the risk calculation below.
Architecture fit. Fits only if three conditions hold simultaneously: (1) the primary datastore is PostgreSQL and will remain so; (2) the team already owns or intends to own business logic inside database functions; (3) the codebase already uses a repository pattern, so this slots into an existing seam rather than introducing a new one. If the team's convention is "logic in PHP, database is dumb storage," this package is architecturally backwards and will be rejected in review regardless of quality. The 1.1.2 release does not change this calculus.
Integration feasibility. Mechanically trivial — composer require, extend the base repository, inject via container. No service provider complexity to speak of, no config surface, no migrations of its own. A competent Laravel developer can evaluate it end-to-end in under a day. The prior assessment flagged the package as archived; release 1.1.2 materially changes that premise by shipping Laravel 10 support via PR #2. That means the resolver is more likely to install cleanly on a Laravel 10 codebase, and the "archived dependency" governance blocker may no longer apply — but this needs confirmation against the repository's current maintenance status and our SCA policy, not just the release note.
Technical risk.
Key questions.
composer.json constraints for laravel/framework, illuminate/*, and php resolve against our exact stack, and confirm whether Laravel 11/12 is in scope for our roadmap.Stack fit. Laravel + PostgreSQL only. The 1.1.2 release specifically improves fit for Laravel 10, so if that is our target, the prior "resolver may simply refuse" concern is substantially reduced. Still verify against our exact Laravel minor and PHP version before anything else — added framework support does not guarantee PHP 8.3+ or Laravel 11/12 compatibility. Note the package predates recent Laravel skeleton changes and may rely on container or facade behavior that has since shifted.
Migration path. Three viable routes, with the recommendation shifting slightly:
app/Support/Database/ or publish as an internal Composer package under our own namespace. Preserves the API, removes dependency-policy exposure, and gives us a place to add PHP 8.4/Laravel 11+ support ourselves. Cost: roughly one engineer-day plus ongoing (small) ownership. Still the safest route for multi-year, revenue-critical use.DB::selectOne('select * from '.$fn.'(?)', $bindings) plus result hydration). Same behavior, zero external dependency, no fork overhead. Slightly more upfront work, strictly better long-term posture. Remains the cleanest option if we want the pattern without the package.Compatibility. Confirm function overloading, default arguments, and OUT/SETOF return shapes are handled — these are where naive wrappers break. Also check how numeric/decimal returns are cast; PDO will hand back strings and that will leak into API responses if unhandled. The Laravel 10 PR likely does not address these runtime concerns, so validate them explicitly.
Sequencing.
Maintenance. The 1.1.2 release reduces the "zero upstream maintenance" concern, but only modestly. We now have evidence of a maintainer responding to a Laravel compatibility gap, which is better than an archived repository. We do not have evidence of a release cadence, security process, or commitment to future Laravel majors. Every future Laravel or PHP upgrade may still require a manual compatibility check we own. The code is small enough that this is a recurring nuisance rather than a crisis, but it remains a permanent small tax. Budget for it; do not assume upstream will handle it.
Support. Upstream support exists again in the loosest sense — a maintainer merged a compatibility PR and cut a release. There is still no SLA, no commercial backing, and no documented security response path. Internal engineers remain the effective support tier. Acceptable for a small internal pattern; questionable if this becomes load-bearing for revenue-critical paths without an internal owner named.
Scaling. The real scaling concern is architectural, not the package: pushing logic into Postgres concentrates compute on the least horizontally-scalable tier. Application servers scale out cheaply; the primary database does not. Functions that begin as "simple" have a well-documented tendency to grow joins, loops, and row-by-row processing. This package makes that path easier to walk, which is a strategic caution, not a technical defect. Also flag connection poolers (PgBouncer in transaction mode) — any function that relies on session state or SET will behave inconsistently across pooled connections.
Failure modes.
UndefinedFunction exception; there is no schema-level safeguard in the package. Mitigate with a boot-time assertion or a smoke test per environment.EXECUTE grants for the app role → failures that appear only in staging/prod, never locally where the developer is superuser. Very common, very preventable.Ramp-up. Near zero. Any Laravel developer reads the source in an afternoon. The ramp-up cost is entirely in the PostgreSQL side: developers who have never authored or debugged PL/pgSQL functions will struggle, and that is a skills gap the package neither creates nor solves.
TPM recommendation. Update from the prior "do not add in archived form": 1.1.2 materially improves the dependency story for Laravel 10 and removes the archived-package blocker as the primary reason to reject. That said, this remains a narrow wrapper around an architectural choice — PostgreSQL functions as a first-class home for business logic — and the release does not validate that choice. If we are on Laravel 10, already use Postgres functions intentionally, and the use is internal or non-critical, direct dependency is now defensible after a one-day spike and SCA confirmation. For revenue-critical or multi-year paths, still prefer forking internally or reimplementing the pattern in-house; the package is small enough that ownership cost is low and the single-maintainer risk is easier to eliminate than to monitor. If we do not already use PostgreSQL functions, the correct action remains to skip this package and revisit the broader question of whether business logic belongs in the database at all. The package is cheap to try, cheap to leave, and solves a narrow problem; it is a pattern reference, not a platform decision.
How can I help you explore Laravel packages today?