Installation:
composer require dovstone/pairdb
Verify compatibility with your Laravel version (check composer.json requirements if documented).
Publish Configuration (if applicable):
php artisan vendor:publish --provider="Dovstone\PairDB\PairDBServiceProvider"
(Note: Provider/class names are speculative; adjust based on actual package structure.)
Basic Usage:
use Dovstone\PairDB\Facades\PairDB;
// Set a key-value pair
PairDB::set('user:123:preferences', ['theme' => 'dark']);
// Retrieve a value
$preferences = PairDB::get('user:123:preferences');
// Delete a key
PairDB::delete('user:123:preferences');
First Use Case:
src/ for core classes (e.g., PairDBManager, Connection).config/pairdb.php (if published) for default settings.tests/Feature/) to infer usage patterns.pairdb_keys or similar).Key-Value Abstraction:
cache() helper or Redis, but with MySQL persistence.PairDB::set("user:{$user->id}:last_active", now()->toDateTimeString());
$lastActive = PairDB::get("user:{$user->id}:last_active");
Bulk Operations:
PairDB::batch([
'product:101:stock' => 50,
'product:102:stock' => 30,
]);
Expiration:
PairDB::set('temp:token', $token, 3600); // Expires in 1 hour
Query Patterns:
user:{id}:* to scope data (e.g., for a user’s records).order:123:items:5 for order line items).Laravel Service Integration:
$this->app->singleton('pairdb', function ($app) {
return new \Dovstone\PairDB\PairDBManager(config('pairdb'));
});
public function __construct(private PairDB $pairDB) {}
Event-Driven Updates:
saved) to sync PairDB:
User::saved(function ($user) {
PairDB::set("user:{$user->id}:updated_at", now());
});
Fallback for Missing Data:
AppServiceProvider to populate default values:
public function boot()
{
$defaults = PairDB::get('app:defaults', []);
config(['app.defaults' => $defaults]);
}
Database Migrations:
Schema::create('pairdb_entries', function (Blueprint $table) {
$table->string('key')->primary();
$table->json('value');
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
Caching Layer:
$value = cache()->remember("pairdb:{$key}", 60, function () use ($key) {
return PairDB::get($key);
});
Testing:
PairDB facade in tests:
PairDB::shouldReceive('get')->with('key')->andReturn(['data']);
No Schema Enforcement:
TEXT vs. JSON columns).Concurrency Issues:
DB::transaction(function () {
PairDB::delete('cart:123:item:4');
PairDB::set('cart:123:total', $newTotal);
});
Key Collisions:
app:, user: prefixes), keys may clash across features. Enforce a convention:
$key = "feature:{$featureName}:{$id}:{$subKey}";
Performance:
PairDB::all()) will be slow. Avoid full-table queries.Laravel Conflicts:
cache).PairDB conflicts with another facade, alias it:
'aliases' => [
'PairDB' => Dovstone\PairDB\Facades\PairDB::class,
],
Query Logging:
DB::enableQueryLog();
PairDB::get('key');
dd(DB::getQueryLog());
Missing Keys:
null errors:
$value = PairDB::get('key', []); // Defaults to empty array
Connection Issues:
config(['pairdb.connection' => 'mysql']);
Extension Points:
Dovstone\PairDB\Contracts\Store to add Redis/S3 backends.PairDB::set('key', encrypt($value));
Configuration:
config/pairdb.php:
'table' => 'custom_pairdb_entries',
'default_ttl' => 86400, // 1 day
Monitoring:
events:
PairDB::set('key', $value);
event(new PairDBStored($key, $value));
Fallback Strategy:
$value = cache()->remember("pairdb:{$key}", 300, function () use ($key) {
return PairDB::get($key);
});
Documentation Workarounds:
phpDocumentor:
vendor/bin/phpdoc src/
How can I help you explore Laravel packages today?