| | |
| | | |
| | | /** |
| | | * Fluent factory method |
| | | * |
| | | * @param string $tableName Table name without prefix/BASE |
| | | * @param string $tableName |
| | | * @param bool $user |
| | | * @param bool $auth |
| | | * @param bool $useTransactions |
| | | * @return self |
| | | * |
| | | * @example CustomTable::for('favourites')->insert($data); |
| | | */ |
| | | public static function for(string $tableName, bool $user = false, bool $auth = false, bool $useTransactions = false): self |
| | |
| | | |
| | | /** |
| | | * Find or create a record |
| | | * |
| | | * @param array $searchData Data to search for |
| | | * @param array $createData Optional additional data for creation |
| | | * @return array ['id' => int, 'created' => bool, 'record' => object] |
| | | * @return int|false The ID of the created record, or false |
| | | * |
| | | * @example |
| | | * $result = CustomTable::for('favourites')->findOrCreate( |
| | | * ['user_id' => 1, 'target_id' => 123], |
| | | * ['type' => 'tattoo'] |
| | | * ); |
| | | * // Returns: ['id' => 456, 'created' => false, 'record' => object] |
| | | * $result = CustomTable::for('favourites')->findOrCreate( |
| | | * ['user_id' => 1, 'target_id' => 123], |
| | | * ['type' => 'tattoo'] |
| | | * ); |
| | | */ |
| | | public function findOrCreate(array $searchData, array $createData = []):int|false |
| | | { |
| | |
| | | |
| | | /** |
| | | * Get multiple records |
| | | * |
| | | * @param array $args Query arguments: where, orderby, order, limit, offset |
| | | * @param bool $itemsOnly |
| | | * @param string $output OBJECT, ARRAY_A, or ARRAY_N |
| | | * @return array |
| | | * |
| | | * @example |
| | | * $favs = $table->getMany([ |
| | | * 'where' => ['user_id' => 1], |
| | | * 'orderby' => 'date_added', |
| | | * 'order' => 'DESC', |
| | | * 'per_page' => 20 |
| | | * ]); |
| | | * $favs = $table->getMany([ |
| | | * 'where' => ['user_id' => 1], |
| | | * 'orderby' => 'date_added', |
| | | * 'order' => 'DESC', |
| | | * 'per_page' => 20 |
| | | * ]); |
| | | */ |
| | | public function getMany(array $args = [], bool $itemsOnly = true, string $output = OBJECT): array |
| | | { |
| | |
| | | return sanitize_sql_orderby($orderby); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Get a specific column value from all matches |
| | | * @param string $column |
| | | * @param array $where |
| | | * @param string|null $orderby |
| | | * @param string|null $order |
| | | * @param int|null $limit |
| | | * @return array |
| | | */ |
| | | public function pluck(string $column, array $where = [], ?string $orderby = null, ?string $order = null, ?int $limit = null): array |