{"id":18258082,"url":"https://github.com/guanhui07/database","last_synced_at":"2025-07-15T21:33:40.428Z","repository":{"id":65699667,"uuid":"597640982","full_name":"guanhui07/database","owner":"guanhui07","description":"基于 illuminate/database 做的连接池用于适配Swoole的协程环境 开箱即用Laravel Orm","archived":false,"fork":false,"pushed_at":"2024-10-25T12:14:54.000Z","size":28,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T10:03:49.570Z","etag":null,"topics":["database","illuminate-database","mysql","orm","php","swoole"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/guanhui07/database","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guanhui07.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-05T06:51:10.000Z","updated_at":"2024-10-25T11:37:22.000Z","dependencies_parsed_at":"2024-08-23T16:25:07.113Z","dependency_job_id":null,"html_url":"https://github.com/guanhui07/database","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"a11f52e0d1b696d79d86f94b94b1db6870384c03"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/guanhui07/database","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanhui07%2Fdatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanhui07%2Fdatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanhui07%2Fdatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanhui07%2Fdatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guanhui07","download_url":"https://codeload.github.com/guanhui07/database/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guanhui07%2Fdatabase/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265461417,"owners_count":23769794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","illuminate-database","mysql","orm","php","swoole"],"created_at":"2024-11-05T10:28:57.801Z","updated_at":"2025-07-15T21:33:40.022Z","avatar_url":"https://github.com/guanhui07.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"### 基于Swoole 封装的`连接池`以及适配了`illuminate/database`\n###### 目前基于PDO规范 支持MySQL，SQL Server，Postgres和SQLite。\n\n#### 1. 安装\n```\ncomposer require guanhui07/database\n```\n#### 2. 创建`配置`实例\n```php\n/**\n * 创建配置\n */\n(new \\Guanhui07\\SwooleDatabase\\PDOConfig())-\u003e\nwithDriver('mysql')-\u003e // 驱动类型\nwithHost('127.0.0.1')-\u003e // 主机地址\nwithDbname('test')-\u003e // 数据库名\nwithUsername('root')-\u003e // 用户名\nwithPassword('123456')-\u003e // 密码\nwithCharset('utf8mb4')-\u003e // 字符集编码\nsetConfig('default'); // 设置全局访问(默认为default)\n```\n#### 3. 设置\n```php\n\\Guanhui07\\SwooleDatabase\\PoolManager::addPool(64,'default'); // 设置指定连接池尺寸(连接名称默认为 default)\n```\n\n#### 4. 使用协程环境模拟Swoole 的任务执行\n```php\n/**\n * 开启协程(如果框架内已经开启可忽略)\n */\n\\Swoole\\Runtime::enableCoroutine();\n/**\n * 协程化IO钩子\n */\n\\Swoole\\Coroutine::set(['hook_flags' =\u003e SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL]);\n/**\n* 记录开始时间\n */\n$s = microtime(true);\n\\Swoole\\Coroutine\\run(function () {\n    /**\n     * 循环创建协程(模拟HTTP 请求 执行任务)\n     */\n    for ($i = 0; $i \u003c 20; $i++) {\n        \\Swoole\\Coroutine::create(function () {\n            /**\n             * 创建表\n             */\n//            \\Guanhui07\\SwooleDatabase\\Manager::schema()-\u003ecreate('test',function(\\Illuminate\\Database\\Schema\\Blueprint $table){\n//                $table-\u003eincrements('id');\n//                $table-\u003estring('name')-\u003enullable()-\u003edefault(1);\n//                $table-\u003etimestamps();\n//            });\n            /**\n             * 模型查询\n             */\n//            $lists = \\Guanhui07\\SwooleDatabase\\Model::query()-\u003efirst();\n            /**\n             * Connection 直接查询\n             */\n            $lists = \\Guanhui07\\SwooleDatabase\\Adapter\\Manager::table('bd_live_plan')-\u003efirst();\n            var_dump(boolval($lists));\n            /**\n             * 协程销毁会自动归还连接(不需要手动处理)\n             */\n        });\n    }\n});\necho '所有任务用了:' . (microtime(true) - $s) . '秒';\n```\n\n### model  用法和laravel orm 一致\n\n```php\nclass UserModel extends \\Guanhui07\\SwooleDatabase\\Adapter\\Model\n{\n    protected $table = 'user';\n\n}\n```\n\n## 类laravel orm DB\n```php\nuse Guanhui07\\SwooleDatabase\\Adapter\\Manager as DB ;\n\n$test = DB::table('user')-\u003ewhere('id', '\u003e', 1)\n    -\u003eorderBy('id', 'desc')-\u003elimit(2)-\u003eget(['id']);\nprint_r($test-\u003etoArray());\n$test = DB::select('select 1');\nvar_dump($test);\n\n\n```\n\n\n\n## 我的其他包：\nhttps://github.com/guanhui07/dcr  借鉴Laravel实现的 PHP Framework ，FPM模式、websocket使用的workerman、支持容器、PHP8特性attributes实现了路由注解、中间件注解、Laravel Orm等特性\n\nhttps://github.com/guanhui07/redis Swoole模式下 Redis连接池\n\nhttps://github.com/guanhui07/facade  facade、门面 fpm模式下可使用\n\nhttps://github.com/guanhui07/dcr-swoole-crontab 基于swoole实现的crontab秒级定时任务\n\nhttps://github.com/guanhui07/timer php定时器，参考了workerman源码 实现一个单进程(守护进程)的定时器。\n\n\nhttps://github.com/guanhui07/database  基于 illuminate/database 做的连接池用于适配Swoole的协程环境\n\nhttps://github.com/guanhui07/dcr-swoole  高性能PHP Framework ，Cli模式，基于Swoole实现，常驻内存，协程框架，支持容器、切面、PHP8特性attributes实现了路由注解、中间件注解、支持Laravel Orm等特性\n\nhttps://github.com/guanhui07/open-ai  open-ai  chatgpt调用\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguanhui07%2Fdatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguanhui07%2Fdatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguanhui07%2Fdatabase/lists"}