Comments (15)
Query 1
Select * from Table_Name where Column1=value1 and (Column2=value2 or Column3=value3);
Jsstore
select({
from: table_name,
where: [{
column1: value1
}, {
column2: value2,
or: {
column3: value3
}
}]
})
from jsstore.
Thanks,
Select * from Table_Name where Column1=value1 and ((Column2=value2 and Column4=value4) or (Column3=value3 and Column5=value5));
`
select({
from: table_name,
where: [{
column1: value1,
}, {
column2: value2,
Column4=value4,
or: {
column3: value3,
Column5=value5
}
}]
})
`
Is it correct to write this way?
from jsstore.
yes this is correct.
from jsstore.
Okay, thank you. I'll test it and get back to you later
from jsstore.
Take a look at this link - https://jsstore.net/tutorial/adv-sql-example/
from jsstore.
Select * from Products where supplierId = 1 and((categoryId = 1 and price = 18) or(categoryId = 2 and price = 39));
select({
from: "Products",
where: [{
supplierId: 1,
}, {
categoryId: 1,
price: 18,
or: {
categoryId: 2,
price: 39,
}
}]
});
The result is incorrect!
from jsstore.
Are you still there? @ujjwalguptaofficial
from jsstore.
from jsstore.
Try this -
select({
from: "Products",
where: [{
supplierId: 1,
}, {
categoryId: 1,
price: 18,
}, {
or: {
categoryId: 2,
price: 39,
}
}]
});
Treat every parenthis in sql as object query
here.
from jsstore.
Thanks! Problem solved
from jsstore.
Nice :). I am also working on making documentation better 🎉 .
from jsstore.
// 新增
connection.insert = async function(body) {
// if(body['into']== 'Members') console.log('开始插入',body)
// console.log('开始插入',body)
if (!isOpen()) await openDb();
//获取表格字段
let tableItems = initTable.filter(el => {
return el.name == body['into']
})
// console.log('tableItems',tableItems)
const tableItem = {...tableItems[0]['columns']}
Object.keys(tableItem).forEach(mkk => {
// 如果是主键自增字段,删除数据,让他自增长
if ('autoIncrement' in tableItem[mkk] && tableItem[mkk]['autoIncrement']) {
delete tableItem[mkk];
return;
}
//如果设置了联合索引,删除字段不做处理
if ('keyPath' in tableItem[mkk] ) {
delete tableItem[mkk];
return;
}
})
let sqlStr = ``;
Object.keys(body).forEach(key => {
if (key == 'into') {
if ('upsert' in body && body['upsert']) {
// 如果存在旧数据与新数据冲突,删除旧数据插入新数据
sqlStr += `REPLACE INTO ${body[key]} `
} else {
// 与主键冲突的数据会忽略插入
sqlStr += `INSERT IGNORE INTO ${body[key]} `
}
}
if (key == 'values') {
let keys = "";
let values = "";
if (Array.isArray(body[key])) {
Object.keys(tableItem).forEach(m => {
keys += m + ',';
})
keys = keys.replace(/^(\s|,)+|(\s|,)+$/g, '');
body[key].forEach(n => {
values += `(`;
Object.keys(tableItem).forEach(mk => {
if (mk in n) {
if (tableItem[mk]['dataType'] == 'number') {
if (Number(n[mk]) == 0 || Number(n[mk])) {
values += `'${ Number(n[mk])}',`;
} else {
values += '-1,';
}
} else {
values += `'${ n[mk]? sqliteEscape(n[mk]) : ""}',`;
}
} else {
if (tableItem[mk]['dataType'] == 'number') {
values += '-1,';
} else {
values += '"",';
}
}
})
values = values.replace(/^(\s|,)+|(\s|,)+$/g, '');
values += `),`;
})
// console.log('值',values)
keys = keys.replace(/^(\s|,)+|(\s|,)+$/g, '');
values = values.replace(/^(\s|,)+|(\s|,)+$/g, '');
sqlStr += `(${keys}) VALUES ${values}`;
} else {
// console.log('进入222')
Object.keys(body[key]).forEach(s => {
keys += s + ',';
// values+=body[key][s]+',';
if (typeof body[key][s] == 'string') {
values += `'${sqliteEscape(body[key][s]) }',`;
} else {
values += `${body[key][s]},`;
}
});
keys = keys.replace(/^(\s|,)+|(\s|,)+$/g, '');
values = values.replace(/^(\s|,)+|(\s|,)+$/g, '');
sqlStr += `(${keys}) VALUES(${values})`;
}
}
})
// if(body['into']== 'Members') console.log('新增sql语句',sqlStr)
// console.log('新增sql语句',sqlStr)
return new Promise((resolve, reject) => {
plus.sqlite.executeSql({
name: DbName,
sql: sqlStr,
success: async (e) => {
// console.log('插入成功...' + sqlStr)
if (body['return']) {
// console.log(body['into'])
let rowId = await getLastId(body['into']);
resolve(rowId);
} else {
resolve(e);
}
},
fail(e) {
console.log('e----', e)
console.log('sqlStr', sqlStr)
reject(e);
}
})
})
}
To be compatible with sqlite, I loop through the query objects of the jsstore and concatenate them into sqlite syntax. Would it be easier to implement using sqlweb?
from jsstore.
No, I think this is fine. In SqlWeb - syntax might be little different but feel free to experiment it.
from jsstore.
Because the way to loop jsstore query objects and concatenate them into sqlite syntax is a bit complicated, if sqlweb could pass in the sqlite syntax directly, then I wouldn't have to loop concatenate syntax。
from jsstore.
One more question, is batch updating with a transaction faster than direct updating?
from jsstore.
Related Issues (20)
- Typescript complaints about the `or` clause HOT 5
- JSStore Encrypt Data issues HOT 3
- I now need to do three-end compatibility HOT 1
- Left join with multiple conditions HOT 7
- Problems performing a query using 'OR'. HOT 1
- Multi nesting in sql query does not work - SELECT * from Products where supplierID=1 and ((categoryId=1 and price=18) or (categoryId=2 and price=22)) HOT 7
- Federated queries are used with or queries, and the query data is incorrect HOT 5
- keyPath incompatible with AND logic HOT 3
- The union query is used with an or query and is used with multiple conditions. The query data is incorrect HOT 9
- "MySql : Sound Like " Query support in JsStore HOT 3
- Feature - Helpers: remove HOT 1
- add Middleware select query join not run Middleware HOT 3
- Unexpected Behavior: Different Results Based on Argument Order in 'where' Clause HOT 1
- Trying to run Jsstore in a web worker w/o its own webworker - onmessage problem HOT 5
- Is it possible to share a worker with multiple connections? HOT 4
- or condition and array in where does not works when using within joins HOT 3
- Timestamp Concatenate and String Comparison Not Working HOT 3
- Type Typo issue HOT 2
- count function has a serious bug: where conditions are not be use correct. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsstore.