https://questdb.io logo
Title
j

Jan W

04/13/2023, 4:57 PM
Hey! I am having issues when trying to query the database from js in the browser like so: (i receive empty string)
const HOST = "<http://localhost:9000>"

            async function run() {
              try {
                const query = "SELECT el_wiatrowe, timestamp FROM 'pse_grid' WHERE timestamp BETWEEN '2023-01-01 00:00:00' AND '2023-04-13 00:00:00' LIMIT 1000000;"

                const response = await fetch(`${HOST}/exec?query=${encodeURIComponent(query)}`, {mode:"no-cors"})
                const json = await response.text()

                console.log(json)
              } catch (error) {
                console.log(error)
              }
            }
however when I do the same query in python it's fine:
sql_query = f"SELECT {str(data_string)}, timestamp FROM 'pse_grid' WHERE timestamp BETWEEN '{start_questdb_timestamp}' AND '{end_questdb_timestamp}' LIMIT {limit};"

        ############################# REQUEST

        response = requests.get(
        database+'/exec', #exp for csv
        params={'query': sql_query,}).json()
thanks for your help!
i have also a script tag:
const fetch = require("node-fetch")
instead of this:
<script src="<https://unpkg.com/node-fetch>"></script>
here is the relevant page in the docs https://questdb.io/docs/develop/query-data/
a

Alex Pelagenko

04/13/2023, 5:43 PM
can you log http response code?
j

Jan W

04/13/2023, 5:56 PM
they seem ok
a

Alex Pelagenko

04/13/2023, 6:19 PM
Sorry, not expert in JS to help you any further, I guess it is something with async fetch
j

Jan W

04/13/2023, 8:14 PM
i printed the response and it has status 0 for some reason