更新记录
1.0.0(2026-09-15)
- 首发 App 原生 SQLite UTS API:打开 / 关闭 / 执行 / 查询 / 事务。
- Android
SQLiteDatabase,iOSSQLite3混编,鸿蒙relationalStore。
平台兼容性
uni-app(4.83)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | - | × | × |
uni-app x(4.83)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| × | × | √ | √ | √ | × |
umi-sqlite
uni-app x App 原生 SQLite 插件(Android / iOS / HarmonyOS)。
- Android:
android.database.sqlite.SQLiteDatabase(openOrCreateDatabase/compileStatement/rawQuery) - iOS:系统
SQLite3C API(Swift 混编UmiSqliteKit,sqlite3_open_v2+sqlite3_bind_*+sqlite3_step) - 鸿蒙:
@kit.ArkDatarelationalStore(getRdbStore/executeSql/querySql/beginTransaction)
仅 App。Android、iOS 真机运行必须打 自定义基座。鸿蒙走原生编译,无需自定义基座。
加密后的普通授权版只能从 @/uni_modules/umi-sqlite 导入,不要写 utssdk/ 内部路径。
API
| API | 说明 |
|---|---|
openDatabase(options) |
打开或创建数据库 |
isOpenDatabase(options) |
是否已打开(同步 boolean) |
closeDatabase(options) |
关闭连接,文件保留 |
executeSql(options) |
DDL / INSERT / UPDATE / DELETE 等非查询 SQL |
selectSql(options) |
SELECT,返回 UTSJSONObject[] |
transaction(options) |
begin / commit / rollback |
页面里用工厂函数构造参数,不要给插件 class 的 boolean 字段赋值:
import {
sqliteOpenOptions,
sqliteNameOptions,
sqliteSqlOptions,
sqliteSqlOptionsWithArgs,
sqliteTxOptions,
openDatabase,
isOpenDatabase,
closeDatabase,
executeSql,
selectSql,
transaction,
readAnyErrMsg,
UmiSqliteExecResult
} from '@/uni_modules/umi-sqlite'
const DB = 'umi_demo'
openDatabase(sqliteOpenOptions(DB)).then(() => {
executeSql(sqliteSqlOptions(DB, 'CREATE TABLE IF NOT EXISTS todo (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, done INTEGER)')).then((_ddl : UmiSqliteExecResult) => {
executeSql(sqliteSqlOptionsWithArgs(DB, 'INSERT INTO todo(title, done) VALUES (?, ?)', ['hello', 0])).then((ins : UmiSqliteExecResult) => {
selectSql(sqliteSqlOptions(DB, 'SELECT id, title, done FROM todo ORDER BY id DESC')).then((rows : UTSJSONObject[]) => {
console.log(rows, ins.lastInsertRowId)
})
})
})
}, (err : any | null) => {
console.log(readAnyErrMsg(err, '打开失败'))
})
事务:
transaction(sqliteTxOptions(DB, 'begin')).then(() => {
executeSql(sqliteSqlOptionsWithArgs(DB, 'INSERT INTO todo(title, done) VALUES (?, ?)', ['a', 0])).then(() => {
transaction(sqliteTxOptions(DB, 'commit'))
}, (err : any | null) => {
transaction(sqliteTxOptions(DB, 'rollback'))
})
})
自定义路径(Android / iOS 为真实 sqlite 文件;鸿蒙写入应用沙箱 databaseDir/rdb/,path 只解析文件名和相对 customDir):
openDatabase(sqliteOpenOptionsAt(DB, '/storage/emulated/0/Android/data/包名/files/demo.db'))
注意
executeSql不要跑 SELECT;查询用selectSql。- Android
rawQuery的绑定参数只能是字符串,数字/布尔会转成文本再绑定。写操作走SQLiteStatement,可按 null / 整数 / 浮点 / 文本绑定。 - 鸿蒙库文件由
StoreConfig.name管理,不要指望任意绝对路径可写。 - 跨插件不要事后写 boolean 字段;本插件 options 只用 string / number /
any[]。 - 页面
import的函数必须出现在各端utssdk/app-*/index.uts的export function/export class中。

收藏人数:
购买源码授权版(
试用
使用 HBuilderX 导入示例项目
赞赏(0)
下载 1457
赞赏 4
下载 12604344
赞赏 1949
赞赏
京公网安备:11010802035340号