Skip to content

Instantly share code, notes, and snippets.

View geshan's full-sized avatar

Geshan Manandhar geshan

View GitHub Profile
@geshan
geshan / Markdium-PLSQL.sql
Created March 10, 2021 21:52
Markdium-Node.js MySQL Transaction: a step-by-step tutorial with a real-life example
INSERT INTO `product` (`id`, `name`, `sku`, `price`, `quantity`) VALUES
(1, 'Toilet paper 10 pack', 'TP0001', 750, 1),
(2, 'Rice 1 Kg', 'RI0002', 140, 500),
(3, 'Pasta 500 g', 'PA0003', 260, 500),
(4, 'Chicken Breast 1 Kg', 'CB0004', 1200, 500),
(5, 'Hand Sanitizer', 'HS0005', 300, 500);
@geshan
geshan / Markdium-PLSQL.sql
Created March 10, 2021 21:52
Markdium-Node.js MySQL Transaction: a step-by-step tutorial with a real-life example
CREATE TABLE `product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`sku` char(6) COLLATE utf8_unicode_ci NOT NULL,
`price` int(11) NOT NULL COMMENT 'in cents',
`quantity` int(11) NOT NULL,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE INDEX `sku` (`sku` ASC) VISIBLE
@geshan
geshan / Markdium-JavaScript.js
Created March 10, 2021 21:52
Markdium-Node.js MySQL Transaction: a step-by-step tutorial with a real-life example
const mysql = require('mysql2/promise');
const config = require('./config');
async function createOrder() {
const items = ['RI0002', 'CB0004']
const connection = await mysql.createConnection(config.db);
await connection.execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
console.log('Finished setting the isolation level to read committed');
//set wait timeout and lock wait timeout as per need.
await connection.beginTransaction();
@geshan
geshan / Markdium-JavaScript.js
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
const express = require('express');
const app = express();
const logger = require('npmlog');
const port = 3005;
//more docs here - https://github.com/npm/npmlog#basic-usage
app.get('/', (req, res) => {
res.send('Hello World! - npmlog logged');
});
@geshan
geshan / Markdium-Shell.bash
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
Example app listening at http://localhost:3004
Loglevel is simple
@geshan
geshan / Markdium-JavaScript.js
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
const express = require('express');
const app = express();
const pino = require('express-pino-logger')();
const port = 3003;
//more options here - https://github.com/pinojs/express-pino-logger#example
app.use(pino)
app.get('/', (req, res) => {
res.send('Hello World! - Pino logged');
@geshan
geshan / Markdium-Shell.bash
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
Example app listening at http://localhost:3003
{"level":30,"time":1611695678813,"pid":32768,"hostname":"abcd","req":{"id":1,"method":"GET","url":"/api/test","headers":{"host":"localhost:3003","connection":"keep-alive","sec-ch-ua":"\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"","sec-ch-ua-mobile":"?0","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9","sec-fetch-site":"none","sec-fetch-mode":"navigate","sec-fetch-user":"?1","sec-fetch-dest":"document","accept-encoding":"gzip, deflate, br","accept-language":"en-GB,en-US;q=0.9,en;q=0.8","cookie":"_ga=GA1.1.1863215728.1591927460; PPA_ID=gkq1qhp7htr141pkojpmqcqt95; webfx-tree-cookie-persistence=wfxt-4; io=TxK-RQvnHb14VONKAAAC","if-none-match":"W/\"19-JzA5ewGlTSyvFTwS4fIYMkA
@geshan
geshan / Markdium-JavaScript.js
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
const winston = require('winston');
const expressWinston = require('express-winston');
const express = require('express');
const app = express();
const port = 3001;
//more options here - https://github.com/bithavoc/express-winston#request-logging
app.use(expressWinston.logger({
transports: [
new winston.transports.Console()
@geshan
geshan / Markdium-Shell.bash
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
Example app listening at http://localhost:3001
{"meta":{},"level":"\u001b[32minfo\u001b[39m","message":"GET /api/test 304 2ms"}
{"meta":{},"level":"\u001b[32minfo\u001b[39m","message":"GET /favicon.ico 404 2ms"}
{"meta":{},"level":"\u001b[32minfo\u001b[39m","message":"GET /favicon.ico 404 1ms"}
@geshan
geshan / Markdium-Shell.bash
Created March 10, 2021 22:07
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
Example app listening at http://localhost:3002
{"name":"logger","hostname":"abcd","pid":32691,"req_id":"0b2d2977-376e-4742-86b0-57feec630188","level":30,"remote-address":"::1","ip":"::1","method":"GET","url":"/api/test","referer":"-","user-agent":{"family":"Chrome","major":"87","minor":"0","patch":"4280","device":{"family":"Other","major":"0","minor":"0","patch":"0"},"os":{"family":"Mac OS X","major":"10","minor":"14","patch":"6"}},"http-version":"1.1","response-time":14.628108,"response-hrtime":[0,14628108],"status-code":304,"req-headers":{"host":"localhost:3002","connection":"keep-alive","sec-ch-ua":"\"Google Chrome\";v=\"87\", \" Not;A Brand\";v=\"99\", \"Chromium\";v=\"87\"","sec-ch-ua-mobile":"?0","upgrade-insecure-requests":"1","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0