mirror of https://github.com/Budibase/budibase.git
9 changed files with 187 additions and 1573 deletions
File diff suppressed because it is too large
@ -0,0 +1,46 @@ |
|||
#!/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() |
|||
File diff suppressed because it is too large
Loading…
Reference in new issue