An open API service indexing awesome lists of open source software.

https://github.com/oriiyx/bde

Boring Database Engine
https://github.com/oriiyx/bde

cli cli-app database-connector php php-database-connection

Last synced: 18 days ago
JSON representation

Boring Database Engine

Awesome Lists containing this project

README

          

# 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

```bash
# Initialize a new project
bde init

# Generate code from your SQL files
bde generate
```

## Example

Define your SQL schema:

```sql
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:

```sql
-- 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
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