The Wonderful and Dangerous to_json from Postgres

PostgreSQL is an amazing RDBMS. Not only is has it been ACID compliant since 2001, it supports many data types and functions, putting it on par with Document Store systems like MongoDB. Postgres supports a wide range of JSON formats and methods to store, search, and transform JSON object data. For instance, the to_json and related function json_agg allow you to collect a row into a JSON object. Handy for when you have nested data and want PG to return an object with nested values.

Amazon S3 Browser upload

Amazon S3 Browser upload

It’s 2018 and file upload is still an involved process

I’ll admit, this process is not straight forward, but once set up, it works like a charm. What’s the goal? We want the client (browser) to upload a file directly to S3 and then store the uploaded information in our server/database.

Starting a New Large Project

Here I want to talk about what a team should do when they start a new project. I’ve had the privilege to architect a large project and to come into several existing projects that have a fair amount of girth. These just a few thoughts about things that need to be established sooner rather than later. Create a glossary (terms that everyone can agree on) This is good for new comers to the project, getting their head around jargon.

Cool Tips When Using Knex with Postgres

Cool Tips When Using Knex with Postgres
I’ve been using Knex for a long time, closing in on two years. Just to clarify, Knex is NOT an ORM (Object Relation Model). ORM’s try to model your database into neat and logic classes, but I agree with Laurie Voss, and ORM is an anti-pattern. I’ve used Sequelize, Doctrine ORM, and others. Every. Single. Time. ORM’s will let you down and keep you from leveraging your database to its fullest potential.

Gitlab Docker in Docker with Postgres

Gitlab Docker in Docker with Postgres

I’m embarrassed this took me longer than expected, but here is a .gitlab-ci.yml that will fire up Docker in Docker (so you can can build and run containers) and run Postgres to use in your contract tests.

Apps I use and may be useful to you too

Apps I use and may be useful to you too
A run down on the apps I use regularly and why. Caution, Mac specific drivel ahead. Vim Do I even need to explain? It’s pretty common place for proud Vim users to show off their .vimrc, but I’ve come to find copy/paste from someone else’s .vimrc is not really a good idea. A developer’s .vimrc is a personal matter, crafted over time with love and affection, it suits them and their needs.

Stupid Postgres Tricks

I was curious, how many day’s old am I? I suppose I could solve this in many different programming languages, but thought “PG has really good date managment features, let me try that”. So here it is.

Delete All Tables in a Postgres database

This doesn’t happen every day, but once in a while you may find yourself needing to remove all the tables/functions/views from a PostgreSQL database. The key is you don’t want to delete the database itself. Maybe you are on a hosted solution where you don’t really have access to drop/restore a database. For example, I’m using Heroku’s Postgres service and dropping the database is not an option. Here is a simple command that will remove all the tables and restore to new.

Database Field Naming Notes

Let’s look at a few ways we can name our database fields. This is mostly subjective, with some personal opinion mixed in for added velocity. Naming tables To me, this is straight forward. All table names should be lower snake_case e.g. account_names or account_email_options. Table names should be plural e.g. accounts, people, emails, settings, etc. This slightly breaks down for words where the plural is the singular, for example series.

PostgreSQL Performance Notes

Databases are magic from my perspective. They take in queries, find all the information you tasked it to find, and POOF. In the blink of an eye, there it is, all packaged up nice and neat. Or it blows up in your face, but that never happens, right? Let’s take a look at some steps we can take when things are not not returned in the blink of and eye.