4 Commits

Author SHA1 Message Date
1ad13ddd3f __construct(?record $record) 2025-11-16 12:59:13 +03:00
14c2629fb3 Merge branch 'stable' of https://git.svoboda.works/mirzaev/record into stable 2025-11-04 02:07:01 +07:00
a5a79f2143 a little fix 2025-11-04 02:05:31 +07:00
b1ee745aac small fixes 2025-11-03 16:59:44 +03:00
4 changed files with 41 additions and 117 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
vendor
composer.lock

97
composer.lock generated
View File

@@ -1,97 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0c82d08a56b9613dcd0f25c1e08ce433",
"packages": [
{
"name": "mirzaev/baza",
"version": "3.4.0",
"source": {
"type": "git",
"url": "https://git.svoboda.works/mirzaev/baza",
"reference": "ec2721dc7727ebcd43b780892f3df6831dfff06b"
},
"require": {
"php": "^8.4"
},
"type": "database",
"autoload": {
"psr-4": {
"mirzaev\\baza\\": "mirzaev/baza/system/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"WTFPL"
],
"authors": [
{
"name": "Arsen Mirzaev Tatyano-Muradovich",
"email": "arsen@mirzaev.sexy",
"homepage": "https://mirzaev.sexy",
"role": "Programmer"
}
],
"description": "Lightweight binary database by pure PHP",
"homepage": "https://git.svoboda.works/mirzaev/baza",
"keywords": [
"Plain",
"binary",
"lightweight"
],
"support": {
"email": "arsen@mirzaev.sexy",
"issues": "https://git.svoboda.works/mirzaev/baza/issues",
"wiki": "https://git.svoboda.works/mirzaev/baza/wiki"
},
"time": "2025-08-08T14:27:29+00:00"
},
{
"name": "svoboda/time",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://git.svoboda.works/svoboda/time",
"reference": "0764960606d56a9f0865ebb07671d30a7d232b6a"
},
"require": {
"php": "^8.4"
},
"type": "library",
"autoload": {
"psr-4": {
"svoboda\\time\\": "svoboda/time/system"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"WTFPL"
],
"authors": [
{
"name": "Arsen Mirzaev Tatyano-Muradovich",
"email": "arsen@mirzaev.sexy",
"homepage": "https://mirzaev.sexy",
"role": "Programmer"
}
],
"description": "Time since Svoboda was created",
"homepage": "https://git.svoboda.works/svoboda/time",
"time": "2025-02-02T11:04:25+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^8.4"
},
"platform-dev": {},
"plugin-api-version": "2.6.0"
}

View File

@@ -4,21 +4,11 @@ declare(strict_types=1);
namespace mirzaev\record\interfaces;
// Svoboda time
use svoboda\time\statement as svoboda;
// Baza database
use mirzaev\baza\database,
mirzaev\baza\column,
mirzaev\baza\record,
mirzaev\baza\enumerations\encoding,
mirzaev\baza\enumerations\type;
use mirzaev\baza\record as baza;
// Built-in libraries
use Exception as exception,
RuntimeException as exception_runtime,
LogicException as exception_logic,
InvalidArgumentException as exception_invalid_argument;
use InvalidArgumentException as exception_invalid_argument;
/**
* Active Record
@@ -29,13 +19,14 @@ use Exception as exception,
*
* @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
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
interface ar
interface record
{
/**
* Constructor
@@ -44,7 +35,7 @@ interface ar
*
* @return void
*/
public function __construct();
public function __construct(?baza $record = null);
/**
* Read

View File

@@ -10,8 +10,7 @@ use svoboda\time\statement as svoboda;
// Baza database
use mirzaev\baza\database,
mirzaev\baza\column,
mirzaev\baza\record,
mirzaev\baza\enumerations\encoding,
mirzaev\baza\record as baza,
mirzaev\baza\enumerations\type;
// Built-in libraries
@@ -41,6 +40,36 @@ use Exception as exception,
*/
trait record
{
/**
* Record
*
* @var baza $record The record instance
*/
protected baza $record;
/**
* Constructor
*
* @method record|null $record The record
*
* @return void
*/
public function __construct(?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 record and $this->record = $record;
}
/**
* Read
*
@@ -57,7 +86,7 @@ trait record
offset: 0
)[0] ?? false;
if ($record instanceof record) {
if ($record instanceof baza) {
// Initialized the record
// Exit (success)
@@ -79,9 +108,9 @@ trait record
{
// Writing into the database
$record = $this->database->read(
filter: fn(record $record) => $record->identifier === $this->record->identifier,
update: function (record &$record) {
$this->record->updated = mirzaev::timestamp();
filter: fn(baza $record) => $record->identifier === $this->record->identifier,
update: function (baza &$record) {
$this->record->updated = svoboda::timestamp();
$record = $this->record;
},
amount: 1,