sqlite-manage database visualization management uniqpp

1. Introduction to sqlite-manage

sqlite-manage is a SQLite database visualization management plug-in, which is more convenient for viewing and operating SQLite databases in the early stage, providing convenience for APP developers and avoiding repeated wheel creation .
Built-in tools for adding, deleting, modifying, and checking can be referenced globally or individually as needed .

Second, use sqlite to open the module option

insert image description here

3. Page display

Please add a picture description Please add a picture description Please add a picture description

4. How to use visualization

1. Download the plug-in

https://ext.dcloud.net.cn/publish?id=13429&op=edit
insert image description here

2. Use the visualization module

Create a new page to import the sqliteManage module

Receive parameters

parameter name type describe
dbName String Name database
tableSqls Array Sql statement to create a table
<template>
	<view>
		<sqlite-manage :dbName="dbName" :tableSqls="tableSqls"></sqlite-manage>
	</view>
</template>

<script>
	// 导入可视化页面组件
	import sqliteManage from '@/uni_modules/zjy-sqlite-manage/components/zjy-sqlite-manage/zjy-sqlite-manage.vue'

	export default {
    
    
		components: {
    
    
			sqliteManage
		},
		data() {
    
    
			return {
    
    
				title: 'Hello',
				//数据库名称
				dbName: 'testDb',
				//初始化的表
				tableSqls: [{
    
    
					tableName: 'user',
					sql: `CREATE TABLE "user" (
						  "id" text NOT NULL,
						  "name" TEXT NOT NULL, --名称
						  "createTime" DATE, --创建时间
						  "remark" TEXT, --描述
						  PRIMARY KEY ("id") --主键
						);`
				}, {
    
    
					tableName: 'hobby',
					sql: `CREATE TABLE "hobby" (
						  "id" text NOT NULL, --ID
						  "userId" text, --用户ID
						  "hobby" text, --爱好
						  "createTime" DATE, --创建时间
						  "remark" TEXT, --描述
						  PRIMARY KEY ("id") --主键
						);`
				}]
			}
		},
	}
</script>
<style>
</style>

5. Use database tools

1. dbUtils toolkit

(partial import)

You can directly refer to the toolkit on the page to use it.

// 使用内置SQLite数据库操作工具类
import dbUtils from '@/uni_modules/zjy-sqlite-manage/components/zjy-sqlite-manage/dbUtils.js'

(global import)

Import the toolkit in the main.js file and mount it to a global variable.

import dbUtils from "/common/dbUtils.js"
// Vue2
Vue.prototype.$dbUtils = dbUtils 
// Vue3
app.config.globalProperties.$dbUtils = dbUtils;

insert image description here

2. Method instructions

When using global references:

this.$dbUtils.open('testDb');

When using local references:

dbUtils.open('testDb');
method name Parameter meaning describe
openDb(name) (library name) open database
init(name, tableSqls) (library name, array of Sql statements to create tables)
array format [{tableName:'',sql:''},tableName:'',sql:''}]
Initialize the database
getTable(name) (library name) Get all table information
getCount(name, tabName) (library name, table name) The total number of query table data
isTable(name, tabName) (library name, table name) Does the table exist
updateSQL(name, tabName, setData, setName, setVal) (Library name, table name, object to be updated such as: {id: 1, name: 'Zhang San', age: 18}, condition name such as: id, condition value such as: 1) change the data
delData(name, tabName, setData) (Library name, table name, conditions such as: {name:'Zhang San',age:18}) Delete database data
closeSQL(name) (library name) close database
isOpen(name) (library name) Monitor whether the database is open
delTable(name, tabName) (library name, table name) delete table
addTab(name, sql) (library name, Sql statement to create a table) create table
addTabItem(name, tabName, obj) (Library name, table name, inserted object such as: {id: 1, name: 'Zhang San', age: 18}) adding data
mergeSql(name, tabName, tabs) (Library name, target table name such as: user, data source table name collection such as: ['user1', 'user2', 'user3']) Merge data
getDataList(name, tabName, num, size, byName, byType) (library name, table name, page number, number of entries per page, sorting field, sorting type) Get paged database data
selectDataList(name, tabName, setData, byName, byType) (library name, table name, query condition, sort field, sort type) Query database data
selectCount(name, tabName, setData) (library name, table name, query condition) Query the number of data

Leave a message or private message if you have any questions

Guess you like

Origin blog.csdn.net/y393016244/article/details/131599349