LuminousMonkey

I don't like ORM

I'm not a database guru, and I don't have an extensive knowledge of SQL, and that's why I don't like ORM. I don't like ORM because it's an abstraction developers use because they don't want to go near SQL for various reasons. But! That doesn't mean you shouldn't be using ORM in some cases, for example, if you're writing a Rails application, or Django, and you're not doing (or going to eventually do) anything outside the typical scope of these frameworks.

The problem is, that these frameworks abstract away advanced features that a database offers (because they have give the same interface over a wide range of databases) and tend to end up treating the database on the lowest common denominator.

So, I write using all the features of the database I've selected, because I'm not planning on moving between databases. It'll be pain to move to say Oracle, but really, how often does that actually happen? In the particular example I'm going to get into, I'm using PostgreSQL 9.5, because I need PostGIS. PostGIS is an extensive available to PostgreSQL that gives a bunch of GIS datatypes and functions, and is a good thing if you're dealing with, say, GPS data.

Anyway, anyone who uses a database should know SQL, much like anyone who writes code should also know C. Even if you don't actually write software in it, you should know C, because it lets you understand what is going on under the covers.

I'm short on time now, but, I will present two SQL queries, one takes a few seconds to run, the other is two magnitudes faster (for obvious reasons) and I believe demonstrates why you need to know SQL rather than relying on an ORM (not that an ORM made the slower query, but in my experience, correct me if I'm wrong, ORMs tend to do this as they can't read your mind):

First, the slower query:

SELECT ST_Centroid(UNNEST(ST_Clusterwithin(location::geometry, 0.001))) AS grouped_location
  FROM gps_readings
 WHERE unit_id = 6
   AND speed < 10

Now the one that is two magnitudes faster:

SELECT ST_Centroid(UNNEST(ST_Clusterwithin(location::geometry, 0.01))) AS grouped_location
  FROM
    (SELECT DISTINCT location
       FROM gps_readings
      WHERE unit_id = 3
        AND speed = 0) clus_loc_filter;

The Man Who Sold The World

I have a problem, I'm developing an application that uses a database (that's not the problem, databases are great, people should stop using them as stupid key/value stores), the problem I have is that I want to get continuous integration set up pretty early into the project. The earlier I get it organised, the better habits will flow from that (or that's the plan at least), and also the quicker it will be in the long run since it will help with the path to continuous deployment.

The problem I have, is that my CI server (TeamCity) is running under a virtual machine. Ok, that's not the problem exactly, but the problem is I want to have the state of my database in a known good state. Also, we need to make sure that it's documented how to build the system. For local development, I'm using Vagrant, but, since the CI server is running in a virtual machine itself, then Vagrant isn't really suitable. (Yes, you could run a VM in a VM, but lets just not.)

So, I either have to get a physical server running Linux (either migrate TeamCity to it, or have an agent run on it), or, figure out how to get a virtual machine that I can bring up and down via scripting. Luckily for me, it looks like someone already has:

https://dor.ky/using-vmware-vsphereesxi-as-a-provider-for-vagrant/

The basic idea is to create a template on your ESX server, then use a plugin for bringing a machine up and down based on that template. This seems like something that could work. The reason I need to bring up a whole database is because I'm not using some sort of ORM to abstract away the database. There are a few reasons for this:

  1. I would lose the use of triggers, which are important for maintaining data integrity, also they save the round-trips you can get with ORM.
  2. I can use the database authentication system, there's no point rolling my own when the database can do it better and faster.
  3. I don't need to switch databases, and designing the system for that means you end up coding the for lowest common denominator.

I have read some other blogs commenting both sides of the ORM debate, and I should write a post on it in the future about it, motivation willing. Anyway, I haven't got the build system up and running just yet, but I'm hoping that I've made some progress by Friday so should be able to do a quick post on how that's working out.

Trigger on Habits

Damn it all, I missed another blog post again, I'll have to do two today. I missed out because I don't really have a good consistent trigger to get the habit of posting started. This is a problem if my routine changes, this happened yesterday and Monday. It's something I'll have to work on, maybe making it something I do first thing in the morning when I get into work, or into Uni.

Whoops

Whoops, a little late today, to be fair to myself, I was a little distracted. First, wasted a few hours sorting out our VMWare servers at work. Then, I decided I would call up the department of transport to find out why I hadn't got my refund for my car rego. You see, I had handed in my licence plates over a month ago, and thought I would chase them up. Well, it seems they lost them and have no record to receiving them.

This means that I had to fill out that they were lost, and I can't get the credit backdated from the date of my accident.

So, not only am I out of pocket for the refund that I miss, I've also missed out on the hours that I had to spend to sort the problem out. To add insult to injury, this is all their fault, I have to pay for their mistake. Being a government department, I can't take my business elsewhere, there's no recourse. They don't pay for their mistakes, one has to wonder how much has been wasted of other people's money.

If you run a business, don't make your customers pay for your mistakes.

Quick Post

This is just a quick post, so I can keep my trend of a blog post a day. It's currently 9:47am and I'm about to go to a circus with the family, so I don't think I can get a good post in before lunch.

However, I've been wanted to write a post on a few things, that maybe I will get around to doing:

  • The crappy state of Greentree.
  • Small business in general.
  • Running a small business is hard.
  • Habits.

We'll see how I go.