ForeverSmiYngEcologyKit/JS直接操作数据库.js

35 lines
2.0 KiB
JavaScript

/*
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
前端执行SQL查询语句
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
// let SQL_sentence = `SELECT loginid as id,password as pw FROM hrmresource`;
// let cols = "id,pw";
function SelectByGSL(SQL_sentence, cols) {
const getUrl = '/api/gSl/GSl/gsl';
const Query1 = SQL_sentence;//编写SQL语句
const jiami = ecCom.WeaTools.Base64.encode(Query1);
const result1 = ecCom.WeaTools.Base64.encode(cols);//编写查询内容
const mynewJSON = `{
"expression": "${jiami}",
"result": "${result1}"
}`;
const result = await ecCom.WeaTools.callApi(getUrl, 'POST', JSON.parse(mynewJSON));
return result;
}
/*
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
前端执行SQL增、删、改语句
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
// let SQL_sentence = `update hrmresource set fieldname='123' where id='43' `;
function insertOrDeleteOrUpdateByGSL(SQL_sentence) {
const getUrl = '/api/gSl/GSl/setTable';
const Query1 = SQL_sentence;//编写SQL语句
const jiami = ecCom.WeaTools.Base64.encode(Query1);
const mynewJSON = `{
"expression": "${jiami}",
}`;
const result = await ecCom.WeaTools.callApi(getUrl, 'POST', JSON.parse(mynewJSON));
return result;
}