更新记录
1.0.2(2022-03-22) 下载此版本
字段值 单引号 转换 , 防止 sql被注入 增加guid 示例
1.0.1(2022-03-22) 下载此版本
简化调用方式 初步解决 sql 语句 拼接错误问题 增加分页查询 增加 Sqlite.guid函数 增加 自增主键模式 key=2自增 type只能设置integer 否则无效 key=1 为主键 key=0或其他 非主键
1.0.0(2022-03-21) 下载此版本
安卓sqlite 简单封装了一下
查看更多平台兼容性
uni-app
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
× | × | - | - | √ | √ | - | - | - |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
× | × | × | × | - | - | - | × | - | × | × |
ran-sqlite
自增id 主键示例
<script>
import {
Sqlite,
Item,
TEXT,
INT
} from '@/uni_modules/ran-sqlite/js_sdk/ran-sql.js'
export default {
data() {
return {
dat: {
"propertyJson": "{\"iconBackgroundColor\":\"\",\"moduleId\":\"5ce0f4d7692744438d740e479dce43d3\"}",
"enCode": "lingyongshenqing",
"fullName": "\"'123345'\"",
"icon": "ym-custom ym-custom-cloud-print-outline",
"id": "2d6ee4165cf64c00bc2f0f3d26088c97",
"urlAddress": "/pages/apply/apply/features/index?id=5ce0f4d7692744438d740e479dce43d3"
},
db: new Sqlite()
}
},
async onLoad() {
const _t = this
if (!_t.db.is_open()) {
await _t.db.open().then(e => {
console.log('openDatabase success!');
}).catch(e => {
console.log('openDatabase failed: ' + JSON.stringify(e));
})
}
let its = [
new Item("id", INT, 11, 0, true, 2),
new Item("propertyJson"),
new Item("enCode"),
new Item("fullName"),
new Item("icon"),
new Item("urlAddress"),
new Item("mId")
]
// await _t.db.drop("menu")
await _t.db.create('menu', its).then(e => {
console.log(JSON.stringify(e))
}).catch(e => {
console.log(JSON.stringify(e))
})
let line = Object.assign({}, _t.dat)
delete line.id
line.mId = _t.dat.id
await _t.db.insert('menu', line)
.then(e => {
console.log(JSON.stringify(e))
})
.catch(e => console.log(JSON.stringify(e)))
_t.db.page('select m.id,m.propertyJson,m.fullName from menu m', null, null,null, " m.fullName like '%123%' ").then(e =>
console.log(
e)).catch(
e => console.log(JSON.stringify(e)))
},
destroyed() {
if (this.db.is_open()) {
this.db.close().then(e => {
console.log(JSON.stringify(e))
}).catch(e => {
console.log(JSON.stringify(e))
})
}
},
</script>
guid主键示例
<script>
import {
Sqlite,
Item,
TEXT,
INT
} from '@/uni_modules/ran-sqlite/js_sdk/ran-sql.js'
export default {
data() {
return {
dat: {
"propertyJson": "{\"iconBackgroundColor\":\"\",\"moduleId\":\"5ce0f4d7692744438d740e479dce43d3\"}",
"enCode": "lingyongshenqing",
"fullName": "\"'123345'\"",
"icon": "ym-custom ym-custom-cloud-print-outline",
"id": "2d6ee4165cf64c00bc2f0f3d26088c97",
"urlAddress": "/pages/apply/apply/features/index?id=5ce0f4d7692744438d740e479dce43d3"
},
db: new Sqlite()
}
},
async onLoad() {
const _t = this
if (!_t.db.is_open()) {
await _t.db.open().then(e => {
console.log('openDatabase success!');
}).catch(e => {
console.log('openDatabase failed: ' + JSON.stringify(e));
})
}
let its = [
// new Item("id", INT, 11, 0, true, 2),
new Item("id"),
new Item("propertyJson"),
new Item("enCode"),
new Item("fullName"),
new Item("icon"),
new Item("urlAddress"),
new Item("mId")
]
// await _t.db.drop("menu")
await _t.db.create('menu2', its).then(e => {
console.log(JSON.stringify(e))
}).catch(e => {
console.log(JSON.stringify(e))
})
let line = Object.assign({}, _t.dat)
delete line.id
line.mId = _t.dat.id
line.id = Sqlite.guid()
await _t.db.insert('menu2', line)
.then(e => {
console.log(JSON.stringify(e))
})
.catch(e => console.log(JSON.stringify(e)))
_t.db.page('select m.id,m.propertyJson,m.fullName from menu2 m', null, null, null,
" m.fullName like '%123%' ").then(e =>
console.log(
e)).catch(
e => console.log(JSON.stringify(e)))
},
destroyed() {
if (this.db.is_open()) {
this.db.close().then(e => {
console.log(JSON.stringify(e))
}).catch(e => {
console.log(JSON.stringify(e))
})
}
},
</script>