更新记录

1.0.0(2024-05-18)

初次发布


平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 4.08,Android:5.0,iOS:不支持,HarmonyNext:不确定 × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

gooyado-Sqlite

  • 提供Sqlite数据库各种操作。

使用

UVUE

<template>
    <view class="content">
        <textarea placeholder="逐条输入sql语句" :value="sqlCode" @blur="inputValue"
            style="max-height: 200rpx; width: 100%;padding: 5px;background-color: #FFF8DC;"></textarea>
        <button type="primary" @click="searchData" style="width: 100%;margin-top: 10rpx;"> 执行 SQL </button>
        <button type="warn" @click="delDb" style="width: 100%;margin-top: 10rpx;"> 删除数据库 </button>
        <button type="default" v-if="dbisDel" @click="createDb" class="btn"> 方式1:新建数据库 </button>
        <button type="default" v-if="dbisDel" @click="initDb" class="btn"> 方式2:现有数据库 </button>
        <button type="default" v-if="dbisDel" @click="downDb" class="btn"> 方式3:下载数据库 </button>
        <text style="margin-top: 20rpx;">{{sqlResult}}</text>
    </view>
</template>

UTS

<script>
    import { SqliteHelper, SqliteDB, SqliteOptions, InitSql, initDatabase, downloadDb, DbDownOptions, InitDbOptions, executeSql, deleteDatabase } from "@/uni_modules/gooyado-Sqlite";
    export default {
        data() {
            return {
                cloudDbPath: 'https://xxxxxx/study.db',
                localDbPath: '/static/db/',
                dbName: 'study.db',
                newSqliteDB: null as SqliteDB,
                dbisDel: false,
                sqlCode: 'SELECT * FROM course',
                sqlResult: '',
            }
        },
        onLoad() {
            //方式1(创建数据库):
            this.createDb()
            //方式2(现有数据库):
            // this.initDb()
            //方式3(下载数据库):
            //this.downDb()
        },
        methods: {
            inputValue(e : UniTextareaBlurEvent) {
                this.sqlCode = e.detail.value;
            },
            createDb() {
                this.newSqliteDB = SqliteHelper({
                    DbName: this.dbName,
                    DbVersion: 1,
                    CreateAfterUpgrade: true,
                    CreateSql: "CREATE TABLE IF NOT EXISTS course (id INTEGER PRIMARY KEY AUTOINCREMENT, course TEXT)",
                    UpgradeSql: 'ALTER TABLE course ADD COLUMN teacher TEXT'
                } as InitSql);
                this.dbisDel = false
                this.sqlResult = ''
            },
            initDb() {
                initDatabase({
                    dbPath: this.localDbPath,
                    dbName: this.dbName,
                    isDel: false,
                    success: res => {
                        console.log('初始化成功', res);
                    },
                    fail: err => {
                        console.log('初始化失败', err);
                    }
                } as InitDbOptions)
                this.dbisDel = false
                this.sqlResult = ''
            },
            downDb() {
                downloadDb({
                    url: this.cloudDbPath,
                    dbName: this.dbName,
                    isDel: false,
                    success: res => {
                        console.log('下载成功', res);
                    },
                    fail: err => {
                        console.log('下载失败', err);
                    }
                } as DbDownOptions)
                this.dbisDel = false
                this.sqlResult = ''
            },
            searchData() {
                executeSql({
                    dbName: this.dbName,
                    sql: this.sqlCode,
                    success: res => {
                        console.log('执行成功', res);
                        if (res.Data[0].Success && res.Data[0].Type == 'SELECT') {
                            this.sqlResult = res.Msg + '->' + res.Data[0].Sql + '\n\n' + res.Data[0].Result?.toString()!
                        }
                    }, fail: err => {
                        console.log('执行失败', err);
                        this.sqlResult = err.errMsg
                    }
                } as SqliteOptions)
            },
            delDb() {
                let res = deleteDatabase(this.dbName)
                console.log(res)
                this.dbisDel = true
                this.sqlResult = ''
            },
        }
    }
</script>

隐私、权限声明

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

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

插件不采集任何数据

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

暂无用户评论。

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