I'm looking for an open source @swiftlang library that only implements SQLite syntax construction. I'm not looking for fancy generics or convenience wrappers... I just want something that will construct the raw SQL strings and handle things like escaping and statement bindings.

Anyone know of something?

(to preempt the inevitable replies... neither GRDB nor SQLite.swift have what I want)

@davedelong It's not out yet, but the upcoming StructuredQueries library from @pointfreeco might be what you're looking for? They start showing how they've built it in a video series (linked below), but the gist is that you annotate your model object with an `@Table` macro, and then you can do something like `Contact.where { $0.firstName == "John" }` and call `queryFragment` on it to get the generated SQL statement for it.

Or is that doing more than you want and you're looking for something that would provide a `SQLStatementLiteral` type that would let you do a string literal for the SQL statement, substitute values in with string interpolation, and properly escape them?

https://www.pointfree.co/episodes/ep314-sql-builders-sneak-peek-part-1

Episode #314: SQL Builders: Sneak Peek, Part 1

Last week we released SharingGRDB, an alternative to SwiftData powered by SQLite, but there are a few improvements we could make. Let’s take a look at some problems with the current tools before giving a sneak peek at the solution: a powerful new query building library that leverages many advanced Swift features that we will soon build from scratch.

@grantjbutler @pointfreeco that’s built on top of GRDB. I just want SQLite syntax. I don’t need anything else
@davedelong No, there's no dependency to GRDB in the alpha version I've been playing with. The integration with GRDB is provided by their other library that integrates GRDB with their Sharing library. https://github.com/pointfreeco/sharing-grdb/tree/structure StructuredQueries itself does all the work to generate the SQL query for you.
GitHub - pointfreeco/sharing-grdb: A lightweight replacement for SwiftData and the Query macro.

A lightweight replacement for SwiftData and the Query macro. - pointfreeco/sharing-grdb

GitHub
@grantjbutler hm ok I’ll take a second look. My issue with all the libraries I’ve found so far is their heavy use of generics, which makes it *almost impossible* to do the dynamic-at-runtime schema creation and querying I need to do
@davedelong @grantjbutler Structured Queries uses heavy generics, I believe. It defines it's schema at compile time. You can alter your schema with migrations, but if you need a heavily dynamic schema then it might not be a good fit.
@dandylyons @grantjbutler 👍 thanks for the info. I'm currently going through the SQLite.org docs and just manually typing out everything 😖

@davedelong @grantjbutler Good luck. I am very curious how dynamic your schema really needs to be. A heavily dynamic db schema sounds terrifying to me.

In any case Swift generics have gotten SO much better in the last few years. I think it might be able to handle your dynamism better than you might realize.

@dandylyons @grantjbutler I'm playing around with an ORM-ish package that can generate full schemas from entirely un-annotated struct definitions.

@davedelong @dandylyons @grantjbutler We're not sure it'll be what you're looking for, but the library is live as of this morning: https://github.com/pointfreeco/swift-structured-queries

It's a general purpose type-safe SQL builder that an ORM could certainly use, so if you do end up kicking the tires, please let us know what you think and if we can help in any way!

GitHub - pointfreeco/swift-structured-queries: Truly type-safe SQL

Truly type-safe SQL. Contribute to pointfreeco/swift-structured-queries development by creating an account on GitHub.

GitHub

@pointfreeco @dandylyons @grantjbutler Here's what I'm trying to do: https://mastodon.social/@davedelong/114371921912511612

and yesterday I worked through the syntax diagrams to define them as structs and enums: https://github.com/davedelong/sqlsyntax

GitHub - davedelong/SQLSyntax

Contribute to davedelong/SQLSyntax development by creating an account on GitHub.

GitHub
@davedelong @dandylyons @grantjbutler I believe part of the Vapor toolchain may support this. @LordOfNightmares has been working on some updates for Vapor 5.
@pointfreeco @davedelong @dandylyons @grantjbutler In a general sense, this is what https://github.com/vapor/sql-kit (especially as supplemented by my new https://github.com/vapor-community/sql-kit-extras) is supposed to be for. And yes, the version I'm working on for Fluent 5 most certainly is a major update 🙂.
GitHub - vapor/sql-kit: *️⃣ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL.

*️⃣ Build SQL queries in Swift. Extensible, protocol-based design that supports DQL, DML, and DDL. - vapor/sql-kit

GitHub