baza/README.md

70 lines
1.8 KiB
Markdown
Raw Normal View History

2025-01-28 14:16:39 +07:00
# Baza
2025-01-28 14:07:30 +07:00
Lightweight binary database by pure PHP<br>
2024-12-14 23:31:20 +07:00
2025-01-28 14:07:30 +07:00
## Dependencies
2025-01-28 14:26:22 +07:00
1. [PHP 8.4](https://www.php.net/releases/8.4/en.php)
2. [Composer](https://getcomposer.org/) (php package manager)
2024-11-24 00:14:28 +07:00
## Installation
2025-01-28 14:16:39 +07:00
`composer require mirzaev/baza`
2024-11-24 00:14:28 +07:00
## Example
```php
<?php
2025-01-28 14:16:39 +07:00
use use mirzaev\baza\database,
mirzaev\baza\column,
mirzaev\baza\record,
mirzaev\baza\enumerations\encoding,
mirzaev\baza\enumerations\type;
2024-11-24 00:14:28 +07:00
// Initializing the database
2025-01-28 14:07:30 +07:00
$database = new database()
->encoding(encoding::utf8)
->columns(
new column('name', type::string, ['length' => 32]),
new column('second_name', type::string, ['length' => 64]),
new column('age', type::integer),
new column('height', type::float)
)
->connect(__DIR__ . DIRECTORY_SEPARATOR . 'database.ba');
2024-11-24 00:14:28 +07:00
// Initializing the record
2025-01-28 14:07:30 +07:00
$record = $database->record(
'Arsen',
'Mirzaev',
23,
(float) 165
);
if ($database->write($record)) {
// Writed the record into the database
// Updating the record in the database
$updated = $database->read(
filter: fn($record) => $record->name === 'Arsen',
update: fn(&$record) => $record->age = 24,
amount: 1
);
// Reading the record from the database
$readed = $database->read(
filter: fn($record) => $record->name === 'Arsen' && $record->age === 24,
amount: 1
);
2024-11-24 00:14:28 +07:00
2025-01-28 14:07:30 +07:00
// Deleting the record from the database
$deleted = $database->read(
filter: fn($record) => $record->age < 25,
delete: true,
amount: 1000
);
}
2024-11-24 00:14:28 +07:00
?>
```
## Used by
2025-01-28 14:07:30 +07:00
- My site-article about how i was kidnapped by PMC Wagner operatives [mirzaev/repression](https://git.svoboda.works/mirzaev/repression)
- My decentralized P2P blockchain chats project [mirzaev/notchat](https://git.svoboda.works/mirzaev/notchat)
- Svoboda Telegram chat-robot [svoboda/negotiator](https://git.svoboda.works/svoboda/negotiator)