Doing DB Stuff in Vapor

Having imported a bunch of tables from an Access database into a Postgres database, I want to transform them so that the information can be used by a Vapor application. Mostly, that app is just going to do exporting again, but you never know; someday someone might actually want to do something more intricate.

The obvious way to do that transformation is inside a Migration (which is a Fluent thing), and I got that all working yesterday. But along the way I discovered something weird: executing a query via `pgDB.simpleQuery(sql).get()` (where pgDB is a `PostgresDatabase`, provided by PostgresNIO) returns an array of `PostgresRow`, which, in turn, is an array-like structure that provides access to the values, wrapped in a class that provides metadata like column name, data type, and so on. But iterating over that row does not return the values in the order in which the query returns them in, say, an interactive SQL client or, you know, any other interface. So even if you turn the row into a random access row, do not subscript into the row by column number. Instead, use the column name.

Because Swift, probably.

Published by pirateguillermo

I play the bagpipes. I program computers. I support my family in their various endeavors, and I enjoy my wonderful life.

Leave a ReplyCancel reply