phpolar / mysql-storage
Adds support for MySQL storage in your application.
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 2
pkg:composer/phpolar/mysql-storage
Requires
- php: >=8.4
- ext-pdo_mysql: *
- phpolar/storage: ^7.0
Requires (Dev)
- ext-ast: *
- ext-openssl: *
- phan/phan: ^5.4
- php-coveralls/php-coveralls: ^2.5
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^2.0.3
- phpunit/phpunit: ^12
- squizlabs/php_codesniffer: ^4
This package is auto-updated.
Last update: 2025-12-11 16:28:43 UTC
README
Adds support for MySQL storage in your application.
Quick start
composer require phpolar/mysql-storage
Objectives
- Keep project small. See thresholds
- Automatically load and persist data
Note For more details see the acceptance tests results
Example 1
$mysqlStorage = new MySqlStorage( connection: $connection, tableName: "table_name", typeClassName: Person::class, ); $mysqlStorage->save($item1->id, $item); $mysqlStorage->replace($updatedItem->id, $updatedItem); $mysqlStorage->remove($item2->id); $item3 = $mysqlStorage->find("id3") ->orElse(static fn() => new NotFound()) ->tryUnwrap(); $allItems = $mysqlStorage->findAll();
Example Class for Items in Storage
use Phpolar\Phpolar\AbstractModel; class Person extends AbstractModel { #[PrimaryKey] #[Hidden] public string $id; public string $firstName; public string $lastName; public string $address1; public string $address2; public function getPrimaryKey(): string { return $id; } }
Thresholds
| Module | Source Code Size * | Memory Usage | Required |
|---|---|---|---|
| phpolar/mysql-storage | 900 B | 110 kB | x |
- Note: Does not include comments.