英文:
Get the result of exists query in typescript
问题
I'm trying to get the result of an exists query using typescript but I can't get the '1' or '0' of the object that the query is returning.
code.ts
const rslt1 = query(`SELECT EXISTS(SELECT * FROM patients WHERE cc=?)`, [params.ccInput]);
const rslt2 = query(`SELECT EXISTS(SELECT * FROM doctors WHERE specialty=?)`, [params.specialtyInput]);
(async () => {
const frslt1: object = await rslt1;
console.log(frslt1, Object.values(frslt1));
console.log(await rslt2);
})()
In the console I just get this:
[{ "EXISTS(SELECT * FROM patients WHERE cc='6465465465')": 0 } ] [ { "EXISTS(SELECT * FROM patients WHERE cc='6465465465')": 0 } ]
[{ "EXISTS(SELECT * FROM doctors WHERE specialty='Medicina general')": 1 } ]
I need the result of the query to do an if later
英文:
I'm trying to get the result of an exists query using typescript but I can't get the '1' or '0' of the object that the query is returning.
code.ts
const rslt1 = query(`SELECT EXISTS(SELECT * FROM patients WHERE cc=?)`, [params.ccInput]);
const rslt2 = query(`SELECT EXISTS(SELECT * FROM doctors WHERE specialty=?)`, [params.specialtyInput]);
(async () => {
const frslt1:object = await rslt1
console.log(frslt1, Object.values(frslt1))
console.log(await rslt2)
})()
In the console I just get this:
[{ "EXISTS(SELECT * FROM patients WHERE cc='6465465465')": 0 } ] [ { "EXISTS(SELECT * FROM patients WHERE cc='6465465465')": 0 } ]
[{ "EXISTS(SELECT * FROM doctors WHERE specialty='Medicina general')": 1 } ]
I need the result of the query to do an if later
答案1
得分: 0
我认为你应该尝试将 query
调用直接放入你的异步函数中。
尝试:
(async () => {
const rslt1 = await query(`SELECT EXISTS(SELECT * FROM patients WHERE cc=?)`, [params.ccInput]);
const rslt2 = await query(`SELECT EXISTS(SELECT * FROM doctors WHERE specialty=?)`, [params.specialtyInput]);
const frslt1: object = rslt1
console.log(frslt1, Object.values(frslt1))
console.log(rslt2)
})()
英文:
I think you should try to put the query
call into your async function directly.
Try
(async () => {
const rslt1 = await query(`SELECT EXISTS(SELECT * FROM patients WHERE cc=?)`, [params.ccInput]);
const rslt2 = await query(`SELECT EXISTS(SELECT * FROM doctors WHERE specialty=?)`, [params.specialtyInput]);
const frslt1: object = rslt1
console.log(frslt1, Object.values(frslt1))
console.log(rslt2)
})()
答案2
得分: 0
以下是您要翻译的内容:
code.ts
(async () => {
const rslt1: any = await query(`SELECT EXISTS(SELECT * FROM patients WHERE cc=?)`, [params.ccInput]);
const rslt2: any = await query(`SELECT EXISTS(SELECT * FROM doctors WHERE specialty=?)`, [params.specialtyInput]);
const res1 = Object.values(rslt1[0])[0]
const res2 = Object.values(rslt2[0])[0]
console.log('result1:', res1, 'result2:', res2)
})();
在控制台中我得到这个:
result1: 0 result2: 1
英文:
How it worked for me was this:
code.ts
(async () => {
const rslt1:any = await query(`SELECT EXISTS(SELECT * FROM patients WHERE cc=?)`, [params.ccInput]);
const rslt2:any = await query(`SELECT EXISTS(SELECT * FROM doctors WHERE specialty=?)`, [params.specialtyInput]);
const res1 = Object.values(rslt1[0])[0]
const res2 = Object.values(rslt2[0])[0]
console.log('result1:', res1, 'result2:', res2)
})();
In console I get this:
result1: 0 result2: 1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论