Skip to content

Instantly share code, notes, and snippets.

@pavlenko-volodymyr
Created February 3, 2020 09:41
Show Gist options
  • Select an option

  • Save pavlenko-volodymyr/a70e6f5a0522fe33ecb336e9c8f311f7 to your computer and use it in GitHub Desktop.

Select an option

Save pavlenko-volodymyr/a70e6f5a0522fe33ecb336e9c8f311f7 to your computer and use it in GitHub Desktop.
const http = require('http')
const { Pool } = require('pg')
const pool = new Pool({
user: '',
database: 'bigint',
password: '',
})
const server = http.createServer(async (req, res) => {
let amount = 0n
// let's emulate some work
for (let i = 0; i < 100; i++) {
if (i % 2 === 0) {
amount += 10000n
}
if (i / 4 === 0) {
amount /= 2n
}
if (i + 1 - 5 === 0) {
amount *= 20000n
}
}
amount *= 10000n
const result = await pool.query(
'INSERT INTO transactions(sender, receiver, amount) VALUES($1, $2, $3) RETURNING *',
['John', 'Sam', amount]
)
const id = result.rows[0].id
res.statusCode = 201;
res.setHeader('Content-Type', 'application/json');
res.end(`{"id": ${id}}`);
});
server.listen(5050, () => {
console.log('Listening to port 5050');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment