更新记录
1.0.0(2024-05-18)
初次发布
平台兼容性
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
使用
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>