Skip to content

Latest commit

 

History

24 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BDE (Boring Database Engine) - On Hold

Project Status: Development Paused

Boring Database Engine (BDE)

A type-safe SQL toolkit for PHP built with Rust

About

Boring Database Engine (BDE) is a code generator that transforms your SQL queries into type-safe PHP functions. Inspired by the Go-based SQLC project, BDE brings the same productivity and safety benefits to the PHP ecosystem.

The "boring" philosophy is intentional - database interactions should be predictable, reliable, and free from unexpected behavior. BDE focuses on generating straightforward, maintainable code without unnecessary complexity.

Features

  • Type-safe SQL: Generate PHP functions with proper type signatures from your SQL queries
  • Compile-time validation: Catch SQL errors before runtime
  • Performance: Rust-powered parsing and code generation
  • Minimal dependencies: Clean, straightforward PHP output with no runtime dependencies
  • MySQL support: First-class support for MySQL (additional databases planned)

Getting Started

# Initialize a new project
bde init

# Generate code from your SQL files
bde generate

Example

Define your SQL schema:

CREATE TABLE users
(
    id         SERIAL PRIMARY KEY,
    username   VARCHAR(255) NOT NULL UNIQUE,
    email      VARCHAR(255) NOT NULL UNIQUE,
    created_at TIMESTAMP    NOT NULL DEFAULT NOW()
);

Write your queries:

-- name: GetUserByID :one
SELECT *
FROM users
WHERE id = $1;

-- name: ListUsers :many
SELECT *
FROM users
ORDER BY created_at DESC;

-- name: CreateUser :one
INSERT INTO users (username, email)
VALUES ($1, $2) RETURNING *;

BDE will generate type-safe PHP code:

<?php

class User
{
    public int $id;

    public string $name;

    public string $email;

    public string $created_at;
}

class Queries
{
    private \PDO $pdo;

    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    public function getUserById(int $id): ?User
    {
        $stmt = $this->pdo->prepare("SELECT * FROM users WHERE id = ?");
        $stmt->execute([$id]);
        $row = $stmt->fetch(\PDO::FETCH_ASSOC);

        if (!$row) {
            return null;
        }

        $user = new User();
        $user->id = (int)$row['id'];
        $user->name = $row['name'];
        $user->email = $row['email'];
        $user->created_at = $row['created_at'];

        return $user;
    }

    public function listUsers(): array
    {
        // Implementation generated by BDE
    }

    public function createUser(string $username, string $email): User
    {
        // Implementation generated by BDE
    }
}

Status

BDE is currently in development.

Contributing

Contributions are currently not welcomed.

License

MIT

Author

Peter Paravinja

About

Boring Database Engine

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages