Files
cunkebao_v3/Moncter/app/service/DataSource/DataSourceAdapterInterface.php
2026-01-05 10:16:20 +08:00

74 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\service\DataSource;
/**
* 数据源适配器接口
*
* 职责:
* - 定义统一的数据源访问接口
* - 支持多种数据库类型MySQL、PostgreSQL、MongoDB 等)
* - 提供基础查询能力
*/
interface DataSourceAdapterInterface
{
/**
* 建立数据库连接
*
* @param array<string, mixed> $config 数据源配置
* @return bool 是否连接成功
*/
public function connect(array $config): bool;
/**
* 关闭数据库连接
*
* @return void
*/
public function disconnect(): void;
/**
* 测试连接是否有效
*
* @return bool 连接是否有效
*/
public function isConnected(): bool;
/**
* 执行查询(返回多条记录)
*
* @param string $sql SQL 查询语句(或 MongoDB 查询条件)
* @param array<string, mixed> $params 查询参数(绑定参数或 MongoDB 查询选项)
* @return array<array<string, mixed>> 查询结果数组
*/
public function query(string $sql, array $params = []): array;
/**
* 执行查询(返回单条记录)
*
* @param string $sql SQL 查询语句(或 MongoDB 查询条件)
* @param array<string, mixed> $params 查询参数
* @return array<string, mixed>|null 查询结果(单条记录)或 null
*/
public function queryOne(string $sql, array $params = []): ?array;
/**
* 批量查询(分页查询,用于大数据量场景)
*
* @param string $sql SQL 查询语句
* @param array<string, mixed> $params 查询参数
* @param int $offset 偏移量
* @param int $limit 每页数量
* @return array<array<string, mixed>> 查询结果数组
*/
public function queryBatch(string $sql, array $params = [], int $offset = 0, int $limit = 1000): array;
/**
* 获取数据源类型
*
* @return string 数据源类型mysql、postgresql、mongodb 等)
*/
public function getType(): string;
}