envor/laravel-managed-databases
最新稳定版本:v1.1.4
Composer 安装命令:
composer require envor/laravel-managed-databases
包简介
A small package for managing multiple databases and their connections at runtime using laravel tools.
README 文档
README
A small package for managing multiple databases and their connections at runtime using laravel tools
Installation
You can install the package via composer:
composer require envor/laravel-managed-databases
Usage
createDatabase()
runOnDatabase()
configureDatabase()
#ManagedDatabases::createDatabase()
The createDatabase() method will
- Cache the current default database connection config
- Set the connection to the
$managerConnection - Purge the connection and reconnect
- Create the physical database
- Purge the connection
- Restore original default connection
- Purge and reconnect
Tip
The $managerConnection must exist and be a configured database connection.
This package creates a few defaults: manager_sqlite, manager_mysql and manager_mariadb.
They are bootstrapped into memory by cloning the default configs for sqlite, mysql and mariadb.
use Envor\ManagedDatabases\ManagedDatabases; $managerConnection = 'manager_sqlite'; $name = 'database' ManagedDatabases::createDatabase($name, $managerConnection); // database
#ManagedDatabases::runOnDatabase()
The runOnDatabase() method will connect the given $database using a new connection created with the credentials and options from the given $managerConnection, execute the given $callback, then finally, restore the original default database connection.
- Cache the current default database connection config
- Create a new connection config for the database by cloning the
$managerConnectionconfig - Set the database as default and connect to it
- Run the given callback
- Purge the connection
- Restore original default connection
- Purge and reconnect
use Envor\ManagedDatabases\ManagedDatabases; ManagedDatabases::runOnDatabase( $database = 'database', $callback = fn() => Artisan::call('migrate', ['--force' => true]), $managerConnection = 'manager_sqlite' );
The package also includes an artisan wrapper for the runOnDatabase() method called managed-databases:run.
The simplest and most harmless way to check it out is by pasting the following command into your terminal:
php artisan managed-databases:run "migrate:fresh --seed" --database=":memory:" --managerConnection="sqlite"
This will run your migrations and seeders harmlessly against an in-memory sqlite database. A great way to quickly check if they can run without errors.
#ManagedDatabases::configureDatabase()
The configureDatabase() method will set the given database as the default on on a brand new connection modeled after the given $managerConnection
use Envor\ManagedDatabases\ManagedDatabases; ManagedDatabases::createDatabase('database2', 'sqlite'); ManagedDatabases::useDatabase('database2', 'sqlite'); config('database.default'); // database2 config('database.connections.database2') // [ // "driver" => "sqlite", // "url" => null, // "database" => "/home/forge/mysite.com/storage/app/managed_database2.sqlite", // "prefix" => "", // "foreign_key_constraints" => true, // ]
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
envor/laravel-managed-databases 适用场景与选型建议
envor/laravel-managed-databases 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「envor」 「laravel-managed-databases」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 envor/laravel-managed-databases 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 envor/laravel-managed-databases 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 envor/laravel-managed-databases 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Some helpful (database level) macros for laravel's schema builder. Requires Laravel 11.
This is my package platform
On Prem Laravel
Database per team starter kit for Laravel based on Laravel Jetstream and Livewire
Alfabank REST API integration
This is my package libstream
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-08