Back to Questdb

Nodejs.Exec.Insert.Partial

documentation/partials/_nodejs.exec.insert.partial.mdx

latest829 B
Original Source

The node-fetch package can be installed using npm i node-fetch.

javascript
const fetch = require("node-fetch")

const HOST = "http://127.0.0.1:9000"

async function createTable() {
  try {
    const query = "CREATE TABLE IF NOT EXISTS trades (name STRING, value INT)"

    const response = await fetch(
      `${HOST}/exec?query=${encodeURIComponent(query)}`,
    )
    const json = await response.json()

    console.log(json)
  } catch (error) {
    console.log(error)
  }
}

async function insertData() {
  try {
    const query = "INSERT INTO trades VALUES('abc', 123456)"

    const response = await fetch(
      `${HOST}/exec?query=${encodeURIComponent(query)}`,
    )
    const json = await response.json()

    console.log(json)
  } catch (error) {
    console.log(error)
  }
}

createTable().then(insertData)