mini\Database\DatabaseInterface::getSchema()
Method
public
abstract
Signature
public abstract function getSchema(): mini\Table\Contracts\TableInterface
Returns
Documentation
Get database schema as a TableInterface
Returns schema metadata as a queryable table without creating temp tables. The table can be filtered, iterated, and composed like any other TableInterface.
Schema columns:
- table_name: Name of the table
- name: Column name or index name
- type: 'column', 'primary', 'unique', or 'index'
- data_type: Data type for columns (null for indexes)
- is_nullable: 1 if nullable, 0 if NOT NULL (null for indexes)
- default_value: Default value expression (null for indexes)
- ordinal: Position (1-based for columns, null for indexes)
- extra: For indexes: comma-separated list of indexed columns
Example:
// Get all columns for a table
$columns = db()->getSchema()->eq('type', 'column')->eq('table_name', 'users');
// List all tables
$tables = db()->getSchema()->eq('type', 'column')->select('table_name')->distinct();
// Find all indexes
$indexes = db()->getSchema()->in('type', ['primary', 'unique', 'index']);
// Find primary key for a table
$pk = db()->getSchema()->eq('table_name', 'users')->eq('type', 'primary')->one();