Categories
Development Technology

Swift SQLite With GRDB

Integrating SQLite and Swift with the excellent GRDB.

Any app like ExerPlan needs a good data model and data store, and given my SQL skills and the fact that SQLite is part of iOS there was only ever one choice for me.

I work with Microsoft SQL Server in my day job and I am very comfortable with writing SQL code to handle inserts, updates, and deletes. I come into contact with lots of different systems at work, and as such I witness many crimes against data. These range from column names making as much sense as Brexit, to seemingly well-designed schemas that lack the database constraints to enforce that design. I wanted to ensure that I created a database that didn’t suffer from these problems.

Swift and SQLite don’t necessarily play well together because it’s not as though SQLite is part of the Swift standard library. But Swift is open source and so maybe there’d be an open source solution for me?

Enter GRDB a “SQLite databases toolkit with a focus on application development”.

I’ve looked at a few such toolkits for SQLite and Swift, but GRDB is by far my favourite. The main reason is that SQL code is front and centre in GRDB if you want it to be, and with my background I very much do. GRDB has some really nice abstractions away from SQL if you want to use them, but as the docs say “your SQL skills are welcome”.

I’ll address how I’m using GRDB more fully in a later post, but for now it’s enough to say that GRDB and Swift play very nicely together. I’ve now got a solid base to work with, and GRDB feels as much like Swift as the standard library.

Select “Happy” As MyFeelingAboutGRDBAndSwift

One reply on “Swift SQLite With GRDB”