update 2023-06-20 03:05:20
This commit is contained in:
parent
6cff5ffe50
commit
5fa40eb556
@ -16,8 +16,9 @@ class Load << (F,LightGreen) >> #Green {
|
|||||||
# Database $load
|
# Database $load
|
||||||
+ __construct(Table $table, Model $model, ...)
|
+ __construct(Table $table, Model $model, ...)
|
||||||
+ value(array $keys, string $field, ...) : mixed
|
+ value(array $keys, string $field, ...) : mixed
|
||||||
+ item(array $keys, ?string $table) : ?object
|
+ item(array $keys, string $table) : ?object
|
||||||
+ items(array $ids, string $table) : ?array
|
+ items(array $keys, string $table) : ?array
|
||||||
|
- prefix(array $keys) : array
|
||||||
}
|
}
|
||||||
|
|
||||||
note right of Load::__construct
|
note right of Load::__construct
|
||||||
@ -88,6 +89,13 @@ Example: $this->items($ids, 'table_name');
|
|||||||
return: ?array
|
return: ?array
|
||||||
end note
|
end note
|
||||||
|
|
||||||
|
note right of Load::prefix
|
||||||
|
Add prefix to the keys
|
||||||
|
|
||||||
|
since: 2.0.1
|
||||||
|
return: array
|
||||||
|
end note
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ final class Load
|
|||||||
* @return object|null
|
* @return object|null
|
||||||
* @since 2.0.1
|
* @since 2.0.1
|
||||||
*/
|
*/
|
||||||
public function item(array $keys, ?string $table): ?object
|
public function item(array $keys, string $table): ?object
|
||||||
{
|
{
|
||||||
// check if this is a valid table
|
// check if this is a valid table
|
||||||
if ($this->prefix($keys) && $this->table->exist($table))
|
if ($this->prefix($keys) && $this->table->exist($table))
|
||||||
@ -154,20 +154,20 @@ final class Load
|
|||||||
* );
|
* );
|
||||||
* Example: $this->items($ids, 'table_name');
|
* Example: $this->items($ids, 'table_name');
|
||||||
*
|
*
|
||||||
* @param array $ids The item ids
|
* @param array $keys The item keys
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
* @since 2.0.1
|
* @since 2.0.1
|
||||||
*/
|
*/
|
||||||
public function items(array $ids, string $table): ?array
|
public function items(array $keys, string $table): ?array
|
||||||
{
|
{
|
||||||
// check if this is a valid table
|
// check if this is a valid table
|
||||||
if ($this->prefix($keys) && $this->table->exist($table))
|
if ($this->prefix($keys) && $this->table->exist($table))
|
||||||
{
|
{
|
||||||
return $this->model->items(
|
return $this->model->items(
|
||||||
$this->load->items(
|
$this->load->items(
|
||||||
['all' => 'a.*'], ['a' => $table], ['a.id' => $ids]
|
['all' => 'a.*'], ['a' => $table], $keys
|
||||||
),
|
),
|
||||||
$table
|
$table
|
||||||
);
|
);
|
||||||
@ -175,5 +175,24 @@ final class Load
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add prefix to the keys
|
||||||
|
*
|
||||||
|
* @param array $keys The query keys
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @since 2.0.1
|
||||||
|
*/
|
||||||
|
private function prefix(array $keys): array
|
||||||
|
{
|
||||||
|
// update the key values
|
||||||
|
$bucket = [];
|
||||||
|
foreach ($keys as $k => $v)
|
||||||
|
{
|
||||||
|
$bucket['a.' . $k] = $v;
|
||||||
|
}
|
||||||
|
return $bucket;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@
|
|||||||
* @return object|null
|
* @return object|null
|
||||||
* @since 2.0.1
|
* @since 2.0.1
|
||||||
*/
|
*/
|
||||||
public function item(array $keys, ?string $table): ?object
|
public function item(array $keys, string $table): ?object
|
||||||
{
|
{
|
||||||
// check if this is a valid table
|
// check if this is a valid table
|
||||||
if ($this->prefix($keys) && $this->table->exist($table))
|
if ($this->prefix($keys) && $this->table->exist($table))
|
||||||
@ -128,20 +128,20 @@
|
|||||||
* );
|
* );
|
||||||
* Example: $this->items($ids, 'table_name');
|
* Example: $this->items($ids, 'table_name');
|
||||||
*
|
*
|
||||||
* @param array $ids The item ids
|
* @param array $keys The item keys
|
||||||
* @param string $table The table
|
* @param string $table The table
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
* @since 2.0.1
|
* @since 2.0.1
|
||||||
*/
|
*/
|
||||||
public function items(array $ids, string $table): ?array
|
public function items(array $keys, string $table): ?array
|
||||||
{
|
{
|
||||||
// check if this is a valid table
|
// check if this is a valid table
|
||||||
if ($this->prefix($keys) && $this->table->exist($table))
|
if ($this->prefix($keys) && $this->table->exist($table))
|
||||||
{
|
{
|
||||||
return $this->model->items(
|
return $this->model->items(
|
||||||
$this->load->items(
|
$this->load->items(
|
||||||
['all' => 'a.*'], ['a' => $table], ['a.id' => $ids]
|
['all' => 'a.*'], ['a' => $table], $keys
|
||||||
),
|
),
|
||||||
$table
|
$table
|
||||||
);
|
);
|
||||||
@ -149,3 +149,22 @@
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add prefix to the keys
|
||||||
|
*
|
||||||
|
* @param array $keys The query keys
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @since 2.0.1
|
||||||
|
*/
|
||||||
|
private function prefix(array $keys): array
|
||||||
|
{
|
||||||
|
// update the key values
|
||||||
|
$bucket = [];
|
||||||
|
foreach ($keys as $k => $v)
|
||||||
|
{
|
||||||
|
$bucket['a.' . $k] = $v;
|
||||||
|
}
|
||||||
|
return $bucket;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user