For work with external databases, there are many packages available (Vapour, Fluent, Postgres etc.).
There are also excellent tutorials, showing how to use Vapor in SwiftUI/Core Data apps.
The upcoming SwiftData simplifies data binding and persistence management for internal and cloud storage. I haven't found documentation or a tutorial that shows how to use Vapor with an external database like Postgres in the context of SwiftData.
I am struggling connecting the dots between a SwiftUI/SwiftData app and a Vapor server with external database.
This is a Swift beginner question. Any guidance would be appreciated.
Thanks!
@0xTim : I plan to port a school management system from its current platform to Swift. Clients are on macOS. iOS clients may follow later.
Data cannot be stored in iCloud. This is why I am looking for a possibility to work with a database on a local server.
Haven't worked with SwiftData yet I am exploring my options. Couldn't find anything beyond on-device and iCloud storage for SwiftData but wasn't sure if I had fully understood all options.
With the information I got here it looks like a Vapor/Fluent server with a Postgres database is the way to go.
SwiftData would be for local storage and potentially iCloud. Sounds like you’ll need something else. If you’re familiar with CoreData, SwiftData sits on top of it.
Set up a Vapor server with Postgres, define endpoints, handle HTTP requests in SwiftUI/SwiftData app, and manage data serialization using Codable. You should consider security and error handling.
SwiftData in iOS 18 introduces the CustomDataStore. Say I have a Vapor REST API and am using Fluent to manage a Postgres db, where all user data is stored in that db. Is there a way to use SwiftData to cache the user's data locally via the CustomDataStore? Will there be a Vapor/Fluent/Postgres 'driver'/customDataStore for SwiftData? Is this something I must do or the Vapor folks? This seems like the obvious use case for a CustomDataStore but I haven't seen much about it, except for here with Realm.
This is probably something you need to do. It probably is possible to build it as a package assuming the CustomDataStore endpoints are consistent but you should be able to build a controller with the endpoints required that returns the data in the correct format.
It's not impossible that it could become part of Fluent (or more likely a separate package) but it's probably the kind of thing the Vapor community can build whilst the Vapor team focus on Vapor and Fluent 5