PureSQL is a SQLite compiler for Swift. Enabling developers to finally just write plain SQL in a type safe compiled manner.
For Example the following SQL:
-- Located in Migrations/1.sql
CREATE TABLE todo (id INTEGER, name TEXT, isComplete INTEGER AS Bool);
-- Located in Queries/Todo.sql
selectTodos:
SELECT * FROM todo;
Generates:
let todos = try await database.todoQueries.selectTodos.execute()
for todo in todos {
print(todo.id, todo.name, todo.isComplete)
}
You can even do SQL in a macro!
@Database
struct DB {
@Query("SELECT * FROM todo")
var selectTodos: any SelectTodosQuery
static var migrations: [String] {
return ["CREATE TABLE todo (id INTEGER, name TEXT, isComplete INTEGER AS Bool);"]
}
}
You write plain SQL, it validates and generates the code to talk to it. It uses a SPM build tool plugin and is even able to show SQL errors inline in Xcode.
We have some awesome SQLite wrappers in the community, but as I've used projects like sqlx in rust, sqlc for go and sqldelight for kotlin I found myself preferring just the raw SQL rather than going through a wrapper. Since it's just SQL, my knowledge was transferrable between libraries and found myself less productive using SQL builders and ORMs sine you have to learn it's way of doing SQL. I wanted a library like those, that just used plain SQL, but for Swift.
I've been building a side project with it for a little now and it has been a joy to work with so I thought it was a good time to release it to the world!