fatrbaby/knob

A simple, lightweight database query builder inspired by Laravel.

Maintainers

Package info

github.com/fatrbaby/knob

pkg:composer/fatrbaby/knob

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.6.0 2026-05-27 10:23 UTC

This package is auto-updated.

Last update: 2026-05-28 09:29:56 UTC


README

Knob is a simple, lightweight database query builder inspired by Laravel. It provides a fluent, chainable interface for building SQL queries across multiple database drivers.

Requirements

  • PHP 8.2+
  • PDO extension

Supported Databases

  • MySQL / MariaDB
  • PostgreSQL
  • SQLite
  • SQL Server

Installation

composer require fatrbaby/knob

Quick Start

use Knob\Knob;

// Set PDO connection (driver is auto-detected)
Knob::using($pdo);

// Build queries
$users = Knob::table('users')
    ->select('id', 'name', 'email')
    ->where('status', 'active')
    ->orderBy('created_at', 'DESC')
    ->limit(10)
    ->get();

// Insert
Knob::table('users')->insert([
    ['name' => 'Alice', 'email' => 'alice@example.com'],
]);

// Update
Knob::table('users')
    ->where('id', 1)
    ->update(['name' => 'Updated Name']);

// Delete
Knob::table('users')->where('id', 1)->delete();

// Aggregates
$count = Knob::table('users')->count();

OpenSpec

This project uses OpenSpec for spec-driven changes.

  • Workflow entry: openspec/README.md
  • Baseline specs: openspec/specs/
  • Active proposals: openspec/changes/

Testing

Run the default test suite:

make test

MySQL, PostgreSQL, and SQL Server smoke tests are optional and only run when their DSN environment variables are configured:

cp .env.example .env

Fill in the database credentials in .env, then run:

make smoke-mysql
make smoke-pgsql
make smoke-sqlsrv

Use make smoke to run all configured database smoke tests. Empty DSNs are skipped.

License

Apache-2.0