当前位置: 首页 > news >正文

javascript写一个本地数据库支持SQL查询-SAAS本地化未来之窗行业应用跨平台架构

一、sql语句优点

数据查询灵活:
可以通过各种条件进行精确查询,比如使用 WHERE 子句指定特定的筛选条件,轻松从庞大的数据库中获取所需数据。例如,“SELECT * FROM employees WHERE department = 'Sales'” 可以快速找出销售部门的所有员工信息。
支持多表关联查询,能够从不同的表中提取相关数据进行整合分析。例如,通过 “JOIN” 操作可以将员工表和部门表关联起来,查询出每个员工所在部门的详细信息

二、代码

/*
未来之窗 client db v1
*/
var CyberWin_MS=function(table , dbname){var database_name=dbname;var table=table;var sql_p="";var sql_v="";var condition="";console.log(dbname);this.database_name=dbname;this.table=table;this.condition="";//2024-7-17 默认值this.test=function() {console.log("测试"+database);}this.createTable=function() {}this.insert = function () {}this.query = function (sql,callback) {var 未来之窗数据库=this.database_name+"AAAA"+this.table;
}this.update = function (id, name) {}
this.del = function (id) {}this.dropTable = function () {}//this.exec=function(sql,callback) {}//this.add = function(cyberobj,callback){//console.log(cyberobj);//JSON.stringify(obj);var 未来之窗数据库=this.database_name+"AAAA"+this.table;window.localStorage.setItem(`${未来之窗数据库}`, JSON.stringify(cyberobj));/*//console.log(typeof cyberarray);// console.log("add结果:"+cyberobj.length);sql_p="insert into "+table +"(";sql_v="values ( ";for(var key in cyberobj){//int32View[i] = i*2;console.log(key);console.log(cyberobj[key]);sql_p=sql_p+key+"  ,"sql_v=sql_v+"'"+cyberobj[key]+"',"}sql_v = sql_v.substring(0,sql_v.length-1);sql_p = sql_p.substring(0,sql_p.length-1);sql_v=sql_v +")";sql_p=sql_p +")";var sql=sql_p+sql_v;//console.log(sql_p);//console.log(sql_v);//console.log(sql);dataBase.transaction(function (tx) {tx.executeSql(sql,[],function () { //alert('添加数据成功'); callback(true);},function (tx, error) {//alert('添加数据失败: ' + error.message);callback(error.message);} );});*/}this.where = function (cyberobj){var where_str="";if(typeof(cyberobj)=='string'){this.condition=cyberobj;return ;}for(var key in cyberobj){//int32View[i] = i*2;sql_p=sql_p+key+"  ,"where_str=where_str+""+key+" = '"+cyberobj[key]+"',";}this.condition=where_str;}//this.find = function (callback) {console.clear();// console.log("未来之窗数据库解码");//  console.log(this.condition);var 未来之窗数据库_条件_解码 =  this._parseCondition(this.condition);//console.log(未来之窗数据库_条件_解码);var 未来之窗数据库=this.database_name+"AAAA"+this.table;var 未来之窗数据库数据str =	window.localStorage.getItem(`${未来之窗数据库}`);未来之窗数据库数据 = eval("(" + 未来之窗数据库数据str + ")");//console.log("未来之窗数据库数据");//console.log(未来之窗数据库数据);//空值查询console.log("============空值查询=============");console.log(未来之窗数据库_条件_解码);console.log("condition="+this.condition);console.log(未来之窗数据库数据);console.log("============空值查询=============");if(未来之窗数据库_条件_解码 ==""){console.log("空值查询");if(typeof callback === "function"){ // 如果传入的参数func是函数//2024-7-16 callback("wlzc", 未来之窗符合条件数据);}return 未来之窗数据库数据;}//  callback(tx, error);const 未来之窗符合条件数据 = [];for (const dataone of 未来之窗数据库数据) {//console.log("dataone=巡逻数值=>");//console.log(dataone);for (const cond条件 of 未来之窗数据库_条件_解码) {//field, operator, valueconsole.log("未来之窗数据库数据==>"+cond条件.field+ " operator="+cond条件.operator+" value="+cond条件.value);if(dataone[cond条件.field]){var 巡逻数值 =""+dataone[cond条件.field];console.log("未来之窗数据库数据=巡逻数值=>"+巡逻数值);if(巡逻数值.includes(cond条件.value)==true){console.log("存在符合=>"+cond条件.field);未来之窗符合条件数据.push(dataone);}else{console.log("存在不符合=>"+cond条件.field+",查找;"+cond条件.value);}}else{console.log("不存在这个=>"+cond条件.field);}}}if(typeof callback === "function"){ // 如果传入的参数func是函数//2024-7-16 callback("wlzc", 未来之窗符合条件数据);}return 未来之窗符合条件数据;}this.delete = function (callback) {}this._parseCondition = function (whereClause) {whereClause=""+whereClause;if(whereClause == ""){//2024-7-17 判定无条件return "";}// 去除前后空格whereClause = whereClause.trim();// 按逻辑运算符分割const conditions = whereClause.split(/\s*(AND|OR)\s*/gi);// console.log("未来之窗数据库解码conditions====");//	console.log(conditions);const parsedConditions = [];for (const condition of conditions) {// 提取字段名和操作符//const match = condition.match(/(\w+)\s*([=<>!]+)\s*(\w+)/);//const match = condition.match(/(\w+)\s*([=<>!|like]+)\s*(\w+)/);//	const match = condition.match(/(\w+)\s*([=<>!|like]+)\s*(\w+)/);///^[\w\u4e00-\u9fff]+$/  中文操作const match = condition.match(/(\w+)\s*([=<>!|like]+)\s*([\w\u4e00-\u9fff]+)/);//	console.log("未来之窗数据库解码condition");//console.log(condition);if (match) {const field = match[1];const operator = match[2];const value = match[3];parsedConditions.push({ field, operator, value });}}return parsedConditions;}}


http://www.mrgr.cn/news/13023.html

相关文章:

  • 【JVM】OOM与调优(一)
  • 多线程资源占用问题
  • 【PostgreSQL教程】PostgreSQL 高级篇之触发器
  • 无线通信-WIFI通信
  • 前后端分离项目实战-通用管理系统搭建(前端Vue3+ElementPlus,后端Springboot+Mysql+Redis)第八篇:Tab标签页的实现
  • 缓存Mybatis一级缓存与二级缓存
  • 传奇开服教程之新GOM引擎登录器配置教程
  • flutter 开发中常用的 Widget
  • Java 8 Optional用法【总结记录】
  • 谷粒商城实战笔记-233~235-商城业务-认证服务-单点登录流程-原理
  • 使用正则表达式在Python中提取车牌号:深入解析与实战指南
  • linux驱动 -- IICBH1750
  • Leetcode每日刷题之904.水果成篮
  • 2024Go语言面试宝典Golang零基础实战项目面试八股力扣算法笔记等
  • [Algorithm][综合训练][比那名居的桃子][chika和蜜柑][礼物的最大价值]详细讲解
  • 微商城系统api.php接口存在任意文件上传漏洞
  • 快速学习安装使用etcd
  • 识别不到开发板串口问题(故事版)
  • 【动态规划】背包问题 - 二维费用的01背包问题
  • Docker 搭建redis集群