ody/database
Composer 安装命令:
composer require ody/database
包简介
Database package for ody API framework
README 文档
README
⚠️ IMPORTANT: This repository is automatically generated from the ody repo and is read-only.
A high-performance database integration framework for PHP applications leveraging Swoole's coroutines.
Overview
The ODY Database module provides a connection pool implementation that works with popular PHP ORM solutions. It's designed to maximize performance in Swoole environments by efficiently managing database connections across coroutines.
Features
- Connection pooling with Swoole coroutine awareness
- Support for Doctrine ORM, and standalone DBAL
- Automatic connection binding to coroutines
- Built-in connection lifecycle management
- Connection health checks and leak detection
- Configurable pool size and connection settings
Installation
composer require ody/database
Doctrine ORM
composer require doctrine/orm doctrine/dbal symfony/cache
DBAL
composer require doctrine/dbal
Basic Usage
Configuration
Define your database configuration:
// config/database.php return [ 'environments' => [ 'local' => [ 'driver' => 'mysql', 'host' => 'localhost', 'port' => 3306, 'database' => 'your_database', 'username' => 'your_username', 'password' => 'your_password', 'charset' => 'utf8mb4', ], ], 'connection_pool_enabled' => true, 'pool_size' => 10, ];
Using with Doctrine ORM
use Ody\DB\Doctrine\Facades\ORM; use App\Entities\User; // Get entity manager $entityManager = ORM::entityManager(); // Working with entities $user = $entityManager->find(User::class, 1); $entityManager->persist($user); $entityManager->flush();
Using with Doctrine DBAL
use Ody\DB\Doctrine\Facades\DBAL; // Execute queries $users = $this->connection->fetchAllAssociative('SELECT * FROM users WHERE active = ?', [1]); // Using query builder $queryBuilder = $this->connection->createQueryBuilder(); $result = $queryBuilder ->select('u.*') ->from('users', 'u') ->where('u.active = :active') ->setParameter('active', 1) ->executeQuery() ->fetchAllAssociative();
Direct Connection Pool Access
use Ody\DB\ConnectionManager; // Initialize the pool ConnectionManager::initPool($config); // Get a connection from the pool $connection = ConnectionManager::getConnection(); // Use the PDO connection $stmt = $connection->prepare('SELECT * FROM users WHERE id = ?'); $stmt->execute([1]); $user = $stmt->fetch(PDO::FETCH_ASSOC); // No need to return the connection - it's automatically returned when the coroutine ends
Advanced Configuration
The connection pool can be finely tuned with options for:
- Minimum idle connections
- Idle timeout
- Maximum connection lifetime
- Borrowing timeout
- Connection health checks
- Leak detection threshold
For detailed documentation on advanced configuration and usage, refer to the full documentation.
Performance Benefits
- Connections are reused across requests, eliminating the overhead of establishing new connections
- Automatic binding to coroutines ensures connection safety in concurrent environments
- Connection health checks prevent using broken connections
- Leak detection helps identify and fix connection leaks
- Configurable pool size matches your application needs and server resources
License
This package is licensed under the MIT License.
ody/database 适用场景与选型建议
ody/database 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ody/database 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ody/database 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-28