update to 3.2.0, add zm_sqlite() (portable sqlite)

This commit is contained in:
crazywhalecc
2023-06-06 20:23:19 +08:00
committed by Jerry Ma
parent 8866c1de11
commit 731e1d81da
7 changed files with 126 additions and 17 deletions

View File

@@ -55,6 +55,9 @@ const ZM_PLUGIN_TYPE_COMPOSER = 3; // Composer 依赖的插件
const LOAD_MODE_SRC = 0; // 从 src 加载
const LOAD_MODE_VENDOR = 1; // 从 vendor 加载
const ZM_DB_POOL = 1; // 数据库连接池
const ZM_DB_PORTABLE = 2; // SQLite 便携数据库
/* 定义工作目录 */
define('WORKING_DIR', getcwd());

View File

@@ -25,6 +25,7 @@ use ZM\Plugin\OneBot\BotMap;
use ZM\Plugin\ZMPlugin;
use ZM\Schedule\Timer;
use ZM\Store\Database\DBException;
use ZM\Store\Database\DBPool;
use ZM\Store\Database\DBQueryBuilder;
use ZM\Store\Database\DBWrapper;
use ZM\Store\KV\KVInterface;
@@ -254,6 +255,32 @@ function sql_builder(string $name = ''): DBQueryBuilder
return (new DBWrapper($name))->createQueryBuilder();
}
/**
* 获取一个便携 SQLite 操作类
*
* @param string $name 使用的 SQLite 连接文件名
* @param bool $create_new 是否在文件不存在时创建新的
* @param bool $keep_alive 是否维持 PDO 对象以便优化性能
* @throws DBException
*/
function zm_sqlite(string $name, bool $create_new = true, bool $keep_alive = true): DBWrapper
{
return DBPool::createPortableSqlite($name, $create_new, $keep_alive);
}
/**
* 获取便携 SQLite 操作类的 SQL 语句构造器
*
* @param string $name 使用的 SQLite 连接文件名
* @param bool $create_new 是否在文件不存在时创建新的
* @param bool $keep_alive 是否维持 PDO 对象以便优化性能
* @throws DBException
*/
function zm_sqlite_builder(string $name, bool $create_new = true, bool $keep_alive = true): DBQueryBuilder
{
return zm_sqlite($name, $create_new, $keep_alive)->createQueryBuilder();
}
/**
* 获取 Redis 操作类
*