当前位置: 首页> 游戏> 单机 > javascript写一个本地数据库支持SQL查询-SAAS本地化未来之窗行业应用跨平台架构

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

时间:2025/7/10 2:01:13来源:https://blog.csdn.net/cybersnow/article/details/141508341 浏览次数:0次

一、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;}}

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: