Skip to content

Instantly share code, notes, and snippets.

@glauber-sampaio
glauber-sampaio / database-query.js
Created January 26, 2021 13:45
Inspired by Supabase way of querying database, using a simple JavaScript method chaining.
// node-postgres
const { Pool } = require('pg')
// Connection String
const config = {
connectionString: (process.env.NODE_ENV === 'production') ? process.env.DATABASE_URL : 'postgres://me:password@localhost:5432/database_name'
}
/*
====================================
var x = someOtherElement.offsetWidth / 3;
for(var i = 0; i < els.length; i += 1){
els[i].style.width = x + 'px';
}
// els is an array of elements
for(var i = 0; i < els.length; i += 1){
var w = someOtherElement.offsetWidth / 3;
els[i].style.width = w + 'px';
}