Duck – Making DuckDB feel like Swift
A new open-source library called Duck brings the power of the PostgreSQL database engine directly into iOS and macOS applications, replacing SQLite for complex data tasks.
Developers building apps for Apple's mobile and desktop platforms now have access to a powerful new tool for handling complex data. The open-source library Duck wraps the DuckDB 2.0 database engine in Swift, allowing developers to run serious SQL queries directly inside their iOS and macOS applications.
Duck is designed to bridge the gap between simple local storage and server-side database power. It handles filtering, joins, grouping, analytics, prepared statements, transactions, and bulk writes without requiring a separate backend server.
Performance on mobile hardware
The library is built to perform well on the hardware found in modern iPhones and Macs. On an air-cooled iPhone 16 Pro, Duck completed the full TPC-H SF100 analytical workload, which involves processing about 30 GB of data, in 615.1 seconds.
This performance demonstrates that developers can run complex analytical queries on mobile devices without needing to offload the work to a server. The engine is optimized for mobile environments, making it suitable for apps that need to process large datasets locally.
Native Swift integration
Duck is built with Swift's modern features in mind. It supports async/await throughout the API, allowing developers to write non-blocking database code. The library also includes typed results and connection pooling to manage resources efficiently.
The library integrates seamlessly with SwiftUI and UIKit through reactive queries. This means that when data changes in the database, the user interface can update automatically without the developer needing to write manual refresh logic.
Getting started with Duck
Developers can add Duck to their projects using Swift Package Manager. The package is available on GitHub, and installation involves adding the repository URL to the project's dependencies. Once added, developers can import Duck and start using the library immediately.
The library provides a simple way to define database models using Swift structs. These models are Codable and can be used to interact with the database directly. The library handles the underlying SQL generation, allowing developers to focus on their application logic.
Next steps for developers
Duck is now available for developers to integrate into their projects. The library provides a comprehensive set of features for handling complex data on Apple platforms, making it a strong alternative to SQLite for apps that need more than simple object storage.