Db
Overview
The Db module focuses on custom database tables. Table defines the schema contract, and Custom_Table implements common CRUD operations on top of wpdb.
Types in this module
Lipe\Lib\Db\Table(interface)Lipe\Lib\Db\Custom_Table
Table
Schema contract for a custom table.
Methods
public function get_column_formats(): arraypublic function get_id_field(): stringpublic function get_table_base(): string
Custom_Table
High-level helper for reading and writing rows in a custom table.
Key public methods
public function table(): stringpublic function get(array $where = [], ?int $count = null, ?string $order_by = null, string $order = 'ASC'): arraypublic function get_one(array $where = [], ?string $order_by = null, string $order = 'ASC'): ?arraypublic function get_paginated(int $page, int $per_page, array $where = [], ?string $order_by = null, string $order = 'ASC'): arraypublic function get_by_id(int $id): ?arraypublic function add(array $columns): ?intpublic function delete(int $id): boolpublic function delete_where(array $where): bool|intpublic function update(int $id, array $columns): boolpublic function update_where(array $where, array $columns): bool|intpublic function replace(array $columns): int|boolpublic function get_select_query(array $columns, array $where, ?int $count = null, ?string $order_by = null, string $order = 'ASC', ?int $offset = null): stringpublic function get_wpdb(): \wpdbpublic static function factory(Table $config): static
Example
<?php
use Lipe\Lib\Db\Custom_Table;
use Lipe\Lib\Db\Table;
final class Book_Table implements Table {
public function get_column_formats(): array { return ['ID' => '%d', 'title' => '%s']; }
public function get_id_field(): string { return 'ID'; }
public function get_table_base(): string { return 'acme_books'; }
}
$books = Custom_Table::factory(new Book_Table());
$books->add(['title' => 'Domain-Driven WordPress']);