102 lines
2.3 KiB
Markdown
102 lines
2.3 KiB
Markdown
# `Aiosqliteor` 类技术文档
|
|
|
|
```python
|
|
import re
|
|
from .sqlite3or import SQLite3or
|
|
|
|
class Aiosqliteor(SQLite3or):
|
|
@classmethod
|
|
def isMe(self, name):
|
|
return name == 'aiosqlite'
|
|
```
|
|
|
|
## 概述
|
|
|
|
`Aiosqliteor` 是一个继承自 `SQLite3or` 的子类,用于标识和处理与异步 SQLite 库 `aiosqlite` 相关的操作。该类主要用于运行时判断当前数据库驱动是否为 `aiosqlite`。
|
|
|
|
---
|
|
|
|
## 继承关系
|
|
|
|
- **父类**: `SQLite3or`
|
|
- **模块路径**: `.sqlite3or.SQLite3or`
|
|
|
|
> 说明:`SQLite3or` 是一个通用的 SQLite 操作基类,可能支持多种后端实现(如标准库 `sqlite3` 或异步库 `aiosqlite`)。
|
|
|
|
---
|
|
|
|
## 类方法
|
|
|
|
### `isMe(name)`
|
|
|
|
#### 描述
|
|
类方法,用于判断传入的数据库名称是否匹配 `aiosqlite` 驱动。
|
|
|
|
#### 签名
|
|
```python
|
|
@classmethod
|
|
def isMe(cls, name: str) -> bool
|
|
```
|
|
|
|
#### 参数
|
|
| 参数名 | 类型 | 说明 |
|
|
|--------|--------|------|
|
|
| `name` | `str` | 表示数据库驱动名称的字符串(例如 `'aiosqlite'`, `'sqlite3'` 等) |
|
|
|
|
#### 返回值
|
|
| 类型 | 说明 |
|
|
|---------|------|
|
|
| `bool` | 如果 `name` 等于 `'aiosqlite'`,返回 `True`;否则返回 `False` |
|
|
|
|
#### 示例
|
|
```python
|
|
assert Aiosqliteor.isMe('aiosqlite') == True
|
|
assert Aiosqliteor.isMe('sqlite3') == False
|
|
assert Aiosqliteor.isMe('other') == False
|
|
```
|
|
|
|
#### 实现逻辑
|
|
```python
|
|
return name == 'aiosqlite'
|
|
```
|
|
通过简单的字符串比较来判断是否为 `aiosqlite` 驱动。
|
|
|
|
---
|
|
|
|
## 用途
|
|
|
|
此方法通常被框架或工厂函数调用,以动态选择合适的数据库操作类:
|
|
|
|
```python
|
|
db_name = 'aiosqlite'
|
|
if Aiosqliteor.isMe(db_name):
|
|
db_handler = Aiosqliteor()
|
|
```
|
|
|
|
---
|
|
|
|
## 注意事项
|
|
|
|
- 此类目前仅提供识别功能,具体异步数据库操作需在父类或自身中实现。
|
|
- 名称比对是**大小写敏感**的,确保输入为小写的 `'aiosqlite'`。
|
|
- 依赖于 `SQLite3or` 基类的功能扩展,应确保基类已正确定义并具备所需接口。
|
|
|
|
---
|
|
|
|
## 版本信息
|
|
|
|
- **语言**: Python
|
|
- **依赖**: `aiosqlite`(运行时)、`sqlite3`(间接)
|
|
- **模块位置**: `your_package.db.engines.Aiosqliteor`
|
|
|
|
> 注:实际使用中需确保已安装 `aiosqlite` 包:
|
|
> ```bash
|
|
> pip install aiosqlite
|
|
> ```
|
|
|
|
---
|
|
|
|
## 参考
|
|
|
|
- [aiosqlite on GitHub](https://github.com/omnilib/aiosqlite)
|
|
- `SQLite3or` 基类文档(见相关模块) |