WP-Query-Builder/Database.php

54 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2025-01-27 19:35:17 +01:00
<?php
namespace DatabaseHelper;
2025-02-05 12:29:49 +01:00
class Database
2025-01-27 19:35:17 +01:00
{
2025-02-05 12:29:49 +01:00
/**
* Creates a new TableBlueprint instance for the specified table name.
* @param string $tableName The name of the table to create.
* @return Table A blueprint instance representing the table.
*/
public static function makeTable(string $tableName): Table {
2025-01-28 16:53:37 +01:00
return new Table($tableName);
2025-01-27 19:35:17 +01:00
}
2025-02-05 12:29:49 +01:00
public static function makeMigration(Table $table): Migration {
2025-01-27 19:35:17 +01:00
// TODO: Implement makeMigration() method.
}
2025-02-05 12:29:49 +01:00
/**
* Creates a new QueryBuilder instance for the specified table.
* @param Table $table The table to query on.
* @return Query instance supporting method chaining.
*/
public static function makeQuery(Table $table): Query {
return new Query($table);
2025-01-27 19:35:17 +01:00
}
2025-01-28 16:53:37 +01:00
2025-02-05 12:29:49 +01:00
public static function makeDeletion(Table $table): Deletion {
2025-01-28 16:53:37 +01:00
// TODO: Implement makeDeletion() method.
}
2025-02-05 12:29:49 +01:00
public static function makeInsertion(Table $table): Insertion {
2025-01-27 19:35:17 +01:00
// TODO: Implement makeInsertion() method.
}
2025-02-05 12:29:49 +01:00
public static function makeUpdate(Table $table): Update {
2025-01-27 19:35:17 +01:00
// TODO: Implement makeUpdate() method.
}
2025-02-03 14:31:13 +01:00
/**
* Adds the WordPress database prefix to table names if not already present.
* @param string ...$tableName Array of table names to process
* @return void
*/
2025-01-27 19:35:17 +01:00
public static function standardizeTableNames(string &...$tableName): void {
global $wpdb;
$dbPrefix = $wpdb->prefix;
foreach ($tableName as &$name)
if (!str_starts_with($name, $dbPrefix))
$name = $dbPrefix . $name;
}
}