Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

46 lines
882 B

#!/usr/bin/env node
const { Client } = require("pg")
let client
// Connect
async function connect() {
client = new Client({
host: "localhost",
port: 5432,
database: "test",
user: "postgres",
password: "root",
})
await client.connect()
}
async function insertData() {
const data = [{ id: 1 }, { id: 3 }]
let sql = ""
for (let item of data) {
sql += `INSERT INTO test(id) VALUES(${item.id}); \n`
}
console.log(sql)
await client.query(sql)
}
// Fills up a postgres database
async function run() {
await connect()
// Drops table
await client.query("DROP TABLE IF EXISTS test")
// Creates new table
await client.query(`CREATE TABLE "test" ("id" serial, PRIMARY KEY ("id"))`)
// Insert some data
await insertData()
const res = await client.query("SELECT * from test")
console.log(res.rows)
await client.end()
}
run()