async function query(sql, params) {
const res = await fetch('https://bq-cors.vercel.app/api/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: sql, params })
})
if (res.ok) {
let queryResult = await res.json()
return queryResult
} else {
const contentType = res.headers.get('content-type')
if (contentType && contentType.indexOf('application/json') !== -1) {
const error = await res.json()
throw Error(error.message)
} else {
throw Error(await res.text())
}
}
}