A Swift DSL for building type-safe, extensible, and transformable SQL queries with support for PostgreSQL and MySQL.
SwifQL is a Swift Domain-Specific Language (DSL) for constructing SQL queries in a type-safe and extensible way. It allows developers to write database queries using Swift syntax instead of raw SQL strings, providing compile-time safety and reducing the risk of SQL injection. The library supports PostgreSQL and MySQL and can be used standalone or integrated with Swift web frameworks like Vapor.
Swift developers building server-side applications with databases, particularly those using frameworks like Vapor, Kitura, or Perfect who need a safe and flexible way to construct SQL queries without relying on raw strings.
Developers choose SwifQL for its type-safe query building, extensibility, and seamless integration with Swift ecosystems. It eliminates the fragility of string-based SQL while offering the full power of raw SQL through a Swift-native interface, making it a robust alternative to ORMs for complex query needs.
💎 A Swift DSL for type-safe, extensible, and transformable SQL queries.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses Swift key paths and operators to construct SQL queries, ensuring compile-time safety and eliminating SQL injection risks, as demonstrated in the README's examples like SwifQL.select(\User.email).
Easily extended with custom functions, predicates, and operators to support any SQL dialect or feature, with the README encouraging users to check source files and submit pull requests for new extensions.
Built-in support for PostgreSQL and MySQL, with a flexible dialect system that allows adding other database engines, though it requires manual effort as noted in the README.
Provides builders like SwifQLSelectBuilder that automatically sort clauses, enabling query construction in any order without worrying about SQL syntax sequence.
Includes a comprehensive set of SQL functions such as Fn.count and PgJsonObject, along with operators for advanced query logic like nesting and bracketing.
The README admits that missing functions require users to explore source files and extend SwifQL themselves, which can be time-consuming and error-prone for complex needs.
Installation involves multiple packages and dependencies, especially when using with Vapor and Bridges, leading to a confusing setup process for newcomers.
Only PostgreSQL and MySQL are supported out-of-the-box; adding other databases like SQLite requires implementing new dialects, as highlighted in the README's note on flexibility.
Heavy reliance on Swift key paths, custom operators, and DSL patterns may be challenging for developers not versed in these advanced Swift features.