phpibe

phpibe / sqlc-php

Public

A PHP code generator inspired by sqlc

10
0
80% credibility
Found May 22, 2026 at 10 stars -- GitGems finds repos before they trend. Get early access to the next one.
Sign Up Free
AI Analysis
PHP
AI Summary

sqlc-php is a code generator for PHP developers who want type-safe database access without using an ORM. You write your database structure and SQL queries with simple annotations, and the tool generates PHP classes with properly typed properties and methods that execute your queries safely. It handles complex cases like JOINs, aggregate functions, and optional search filters automatically, producing clean code that's easy to understand and maintain.

How It Works

1
💭 The Problem

You're writing PHP code that talks to a database, and keeping track of types and parameters is becoming a nightmare.

2
🔍 Finding the Solution

You discover sqlc-php: a tool that reads your SQL queries and automatically creates perfectly typed PHP classes.

3
Setting Up

You install the tool and create a simple configuration file that points to your database structure and queries.

4
📝 Describing Your Database

You write out your table definitions in plain SQL, like CREATE TABLE users (id INT, email VARCHAR...).

5
🔧 Writing Your Queries

You add simple comments above your SQL queries to name them and say what they return, like 'give me all users' or 'find one user by email'.

6
Generating Your Code

You run the generator and watch it create PHP classes that match your database structure exactly.

🎉 Your Code Comes to Life

You now have clean, type-safe PHP objects and methods that run your queries with proper error handling, ready to use in your application.

Sign up to see the full architecture

5 more

Sign Up Free

Star Growth

See how this repo grew from 10 to 10 stars Sign Up Free
Repurpose This Repo

Repurpose is a Pro feature

Generate ready-to-use prompts for X threads, LinkedIn posts, blog posts, YouTube scripts, and more -- with full repo context baked in.

Unlock Repurpose
AI-Generated Review

What is sqlc-php?

sqlc-php is a PHP code generator that reads your SQL schema and annotated query files, then spits out fully-typed PHP classes. Instead of writing PDO code by hand or reaching for a full ORM, you write SQL with special comment annotations, run the CLI, and get type-safe query classes and DTOs. It targets PHP 8.3+ and uses PDO under the hood with no magic or runtime overhead.

Why is it gaining traction?

The optional parameter feature is the killer use case here. Mark a parameter with `@optional`, pass null at runtime to skip the filter, and the generated code rewrites the SQL condition for you. No more building query strings with conditionals in PHP. It also handles JOINs by generating result DTOs automatically, infers types from aggregate functions like COUNT and SUM, and supports type overrides in the config file for mapping SQL types to arbitrary PHP types.

Who should use this?

Backend developers tired of hand-writing PDO boilerplate or wrestling with ORM configuration will find this most useful. Teams with existing MySQL databases who want type-safe query classes without adopting a full framework will benefit most. Laravel users get a documented repository pattern for wiring generated code into the service container.

Verdict

This is a practical tool with a solid test suite (191 tests) and thorough documentation, though the GitHub star count is low. The credibility score of 0.800000011920929% reflects that maturity. If you want type-safe SQL queries in PHP without an ORM's overhead and you're comfortable with a smaller community project, this is worth evaluating.

Sign up to read the full AI review Sign Up Free

Similar repos coming soon.