Created
February 3, 2020 09:41
-
-
Save pavlenko-volodymyr/a70e6f5a0522fe33ecb336e9c8f311f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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