Compare commits
3 Commits
1ad13ddd3f
...
670d7a0730
| Author | SHA1 | Date | |
|---|---|---|---|
| 670d7a0730 | |||
| b08051ccd3 | |||
| beccbfee1e |
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
composer.json
Normal file → Executable file
0
composer.json
Normal file → Executable file
8
mirzaev/record/system/interfaces/record.php
Normal file → Executable file
8
mirzaev/record/system/interfaces/record.php
Normal file → Executable file
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace mirzaev\record\interfaces;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record as baza_record;
|
||||
|
||||
// Built-in libraries
|
||||
use InvalidArgumentException as exception_invalid_argument;
|
||||
|
||||
@@ -16,6 +19,7 @@ use InvalidArgumentException as exception_invalid_argument;
|
||||
*
|
||||
* @package mirzaev\record\interfaces
|
||||
*
|
||||
* @method void __construct(record|null $record) Constructor
|
||||
* @method static|false read(callable $filter) Read from the database
|
||||
* @method static|false update() Update the record in the database
|
||||
*
|
||||
@@ -29,9 +33,11 @@ interface record
|
||||
*
|
||||
* @throws exception_invalid_argument If not initialized the database columns parameters
|
||||
*
|
||||
* @param baza_record|null $record The record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct();
|
||||
public function __construct(?baza_record $record = null);
|
||||
|
||||
/**
|
||||
* Read
|
||||
|
||||
37
mirzaev/record/system/traits/record.php
Normal file → Executable file
37
mirzaev/record/system/traits/record.php
Normal file → Executable file
@@ -10,7 +10,7 @@ use svoboda\time\statement as svoboda;
|
||||
// Baza database
|
||||
use mirzaev\baza\database,
|
||||
mirzaev\baza\column,
|
||||
mirzaev\baza\record as baza,
|
||||
mirzaev\baza\record as baza_record,
|
||||
mirzaev\baza\enumerations\encoding,
|
||||
mirzaev\baza\enumerations\type;
|
||||
|
||||
@@ -44,9 +44,32 @@ trait record
|
||||
/**
|
||||
* Record
|
||||
*
|
||||
* @var baza $record The record instance
|
||||
* @var baza_record $record The record instance
|
||||
*/
|
||||
protected baza $record;
|
||||
protected baza_record $record;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @method baza_record|null $record The record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(?baza_record $record = null)
|
||||
{
|
||||
// Initializing the database
|
||||
/* $this->database = new database()
|
||||
->encoding(encoding::utf8)
|
||||
->columns(
|
||||
new column('identifier', type::long_long_unsigned),
|
||||
new column('updated', type::integer_unsigned),
|
||||
new column('created', type::integer_unsigned)
|
||||
)
|
||||
->connect($this->file); */
|
||||
|
||||
// Initializing the record
|
||||
$record instanceof baza_record and $this->record = $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read
|
||||
@@ -64,7 +87,7 @@ trait record
|
||||
offset: 0
|
||||
)[0] ?? false;
|
||||
|
||||
if ($record instanceof baza) {
|
||||
if ($record instanceof baza_record) {
|
||||
// Initialized the record
|
||||
|
||||
// Exit (success)
|
||||
@@ -86,8 +109,8 @@ trait record
|
||||
{
|
||||
// Writing into the database
|
||||
$record = $this->database->read(
|
||||
filter: fn(baza $record) => $record->identifier === $this->record->identifier,
|
||||
update: function (baza &$record) {
|
||||
filter: fn(baza_record $record) => $record->identifier === $this->record->identifier,
|
||||
update: function (baza_record &$record) {
|
||||
$this->record->updated = svoboda::timestamp();
|
||||
$record = $this->record;
|
||||
},
|
||||
@@ -95,7 +118,7 @@ trait record
|
||||
offset: 0
|
||||
)[0] ?? false;
|
||||
|
||||
if ($record instanceof record) {
|
||||
if ($record instanceof baza_record) {
|
||||
// Initialized the record
|
||||
|
||||
// Exit (success)
|
||||
|
||||
Reference in New Issue
Block a user