更新记录

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 简单封装了一下

查看更多

平台兼容性

Vue2 Vue3
× ×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.3.13 app-vue app-nvue × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

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>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问