PHPackages                             tangwei/database-doris - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. tangwei/database-doris

ActiveLibrary[Database &amp; ORM](/categories/database)

tangwei/database-doris
======================

The doris driver for hyperf/database.

v0.1.1(6d ago)00MITPHPPHP &gt;=8.1

Since Mar 13Pushed 5d agoCompare

[ Source](https://github.com/tw2066/database-doris)[ Packagist](https://packagist.org/packages/tangwei/database-doris)[ Docs](https://hyperf.io)[ RSS](/packages/tangwei-database-doris/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

Hyperf Database Doris
=====================

[](#hyperf-database-doris)

[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![PHP](https://camo.githubusercontent.com/7663c9d53dc13cedaf0660a8745a7e77d2dd711257f36aa86ebce12a0600ef42/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c75652e737667)](http://www.php.net)[![Hyperf](https://camo.githubusercontent.com/09ec635c75f6e9b1970b42d4de78e82abaadf98a59801d7277ee194e7ad69ddb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6879706572662d7e332e312e302d7265642e737667)](https://hyperf.io)

📖 简介
----

[](#-简介)

`database-doris` 是专为 Hyperf 框架设计的数据库连接组件，提供对 Apache Doris 数据库的完整支持。通过 Doris 的 Multi-Catalog 功能，可以使用一套 MySQL 协议连接和操作多种异构数据源，实现统一的数据访问层。

✨ 特性
----

[](#-特性)

- 🚀 **完整的 Doris 支持** - 基于 `hyperf/database` ~3.1.0，完美兼容 Hyperf ORM
- 🔌 **Multi-Catalog 集成** - 通过 Doris 访问 MySQL、PostgreSQL、SQL Server、Elasticsearch 等数据源
- ⚡ **SQL 透传模式** - 支持 SQL 自动转换，优化查询性能
- 🎯 **标准 ORM 操作** - 完全支持 Hyperf 的 Model、查询构造器等功能
- 💾 **多连接池配置** - 支持多个 Doris 连接和 Catalog 配置
- 🛠️ **模型生成** - 支持通过命令行自动生成数据模型

📦 安装
----

[](#-安装)

```
composer require tangwei/database-doris
```

🔧 配置
----

[](#-配置)

在 `config/autoload/databases.php` 中添加 Doris 连接配置：

### 1. 基础 Doris 连接

[](#1-基础-doris-连接)

```
'doris' => [
    'driver'    => 'doris',
    'host'      => '127.0.0.1',
    'database'  => 'your_database',
    'port'      => 9030,
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'prefix'    => '',
    'pool'      => [
        'min_connections' => 1,
        'max_connections' => 20,
        'connect_timeout' => 10.0,
        'wait_timeout'    => 8.0,
        'heartbeat'       => -1,
        'max_idle_time'   => 60,
    ],
],
```

### 2. Doris Catalog 连接（推荐）

[](#2-doris-catalog-连接推荐)

Catalog 模式允许通过 Doris 访问外部数据源，无需在本地安装其他数据库驱动。

#### 2.1 MySQL Catalog

[](#21-mysql-catalog)

```
'doris_catalog_mysql' => [
    'driver'    => 'doris_catalog_mysql',
    'host'      => '127.0.0.1',
    'catalog'   => 'mysql',  // Doris 中创建的 MySQL Catalog 名称
    'database'  => 'target_database',
    'port'      => 9030,
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'prefix'    => '',
    'pool'      => [
        'min_connections' => 1,
        'max_connections' => 20,
        'connect_timeout' => 10.0,
        'wait_timeout'    => 8.0,
        'heartbeat'       => -1,
        'max_idle_time'   => 60,
    ],
],
```

#### 2.2 PostgreSQL Catalog

[](#22-postgresql-catalog)

```
'doris_catalog_pgsql' => [
    'driver'    => 'doris_catalog_pgsql',
    'host'      => '127.0.0.1',
    'catalog'   => 'postgresql',  // Doris 中创建的 PG Catalog 名称
    'database'  => 'public',
    'port'      => 9030,
    'username'  => 'postgres',
    'password'  => 'password',
    'charset'   => 'utf8',
    'prefix'    => '',
    'pool'      => [
        'min_connections' => 1,
        'max_connections' => 20,
        'connect_timeout' => 10.0,
        'wait_timeout'    => 8.0,
        'heartbeat'       => -1,
        'max_idle_time'   => 60,
    ],
],
```

#### 2.3 SQL Server Catalog

[](#23-sql-server-catalog)

```
'doris_catalog_sqlsrv' => [
    'driver'    => 'doris_catalog_sqlsrv',
    'host'      => '127.0.0.1',
    'catalog'   => 'sqlserver',  // Doris 中创建的 SQL Server Catalog 名称
    'database'  => 'dbo',
    'port'      => 9030,
    'username'  => 'sa',
    'password'  => 'password',
    'charset'   => 'utf8',
    'prefix'    => '',
    'pool'      => [
        'min_connections' => 1,
        'max_connections' => 20,
        'connect_timeout' => 10.0,
        'wait_timeout'    => 8.0,
        'heartbeat'       => -1,
        'max_idle_time'   => 60,
    ],
],
```

#### 2.4 Elasticsearch Catalog

[](#24-elasticsearch-catalog)

```
'doris_es' => [
    'driver'    => 'doris_catalog',
    'host'      => '127.0.0.1',
    'catalog'   => 'es',              // Doris 中创建的 ES Catalog 名称
    'database'  => 'default_db',
    'port'      => 9030,
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'prefix'    => '',
    'pool'      => [
        'min_connections' => 1,
        'max_connections' => 20,
        'connect_timeout' => 10.0,
        'wait_timeout'    => 8.0,
        'heartbeat'       => -1,
        'max_idle_time'   => 60,
    ],
],
```

#### 2.5 Oracle Catalog

[](#25-oracle-catalog)

```
    'doris_catalog_oracle' => [
    'driver'    => 'doris_catalog_oracle',
    'host'      => '127.0.0.1',
    'catalog'   => 'oracle',  // Doris 中创建的 oracle Catalog 名称
    'database'  => 'dbo',
    'port'      => 9030,
    'username'  => 'sa',
    'password'  => 'password',
    'charset'   => 'utf8',
    'prefix'    => '',
    'pool'      => [
        'min_connections' => 1,
        'max_connections' => 20,
        'connect_timeout' => 10.0,
        'wait_timeout'    => 8.0,
        'heartbeat'       => -1,
        'max_idle_time'   => 60,
    ],
],
```

### 配置说明

[](#配置说明)

- `driver`: 驱动类型

    - `doris` - 直接连接 Doris
    - `doris_catalog` - 通用 Catalog 连接
    - `doris_catalog_mysql` - MySQL Catalog 连接
    - `doris_catalog_pgsql` - PostgresSQL Catalog 连接
    - `doris_catalog_sqlsrv` - SQL Server Catalog 连接
    - `doris_catalog_oracle` - Oracle Catalog 连接
- `catalog`: Doris 中创建的 Catalog 名称（仅 Catalog 模式需要）
- `passthrough_sql_select`: 是否启用 SELECT 语句透传（默认：`false`），启用后会自动处理参数绑定，提升查询性能

💡 使用指南
------

[](#-使用指南)

### 1. 创建 Model

[](#1-创建-model)

#### 1.1 直接连接 Doris

[](#11-直接连接-doris)

```
