Elixir, Ecto, Subqueries, GROUP BY

Since I’m very familiar with SQL, if I have to do something a bit more complicated with Ecto I start with the SQL and then work towards figuring out how to translate it to Ecto. It’s good to keep in mind that if the going gets too rough with the translation you are always left with the “out” of just executing raw SQL. You can map the result set into a schema and from the perspective of a programmer using the API it looks just the same.

Read More

Elixir, AWS, Parsing Describe DB Instances

This is code that I wrote to parse the ex_aws_rds describe_db_instances call. There is no parser in this module currently so parsing the XML is left as an exercise for anyone using this. Since I had to use the library in order to get RDS instance lists I figured I’d post what I used in case someone else wants to convert the XML to something easier to manipulate in Elixir.

Read More

Elixir/Phoenix - shared templates

In using server-side rendering for Phoenix web apps there are two approaches that I’ve used for dealing with removing duplication from templates that need to render the same information. The first is within a single view and the other is across views.

Read More

Elixir/Ecto - update_all with join

When I first began using Ecto it was only to directly issue SQL since the PostgreSQL database that I was working on was so far outside the norm (tables stored in different schemas, different naming conventions on primary keys, character fields being used to store foreign keys that pointed at multiple tables). The second project that I worked on was a database that I controlled so I got to use the more general features of the Ecto query language. The way queries are constructed is - for the most part - easy to grasp but there are definitely some cases that are harder to understand and that could benefit from more examples. The Ecto update_all is one of those.

Read More

Monitor Postgres pgbouncer

Pgbouncer is widely used with Postgres to provide connection pooling. Its an easy-to-use and easy-to-install piece of software. The general idea is to specify n number of connections allowed to pgbouncer and m connections allowed to Postgres itself where m is much less than n. A typical configuration is to set pgbouncer to transaction mode. This allows pgbouncer to multiplex the “real” connections to Postgres as transactions are committed or rolled back.

Read More