Connecting the dots: Vapor and SwiftData

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!

2 Likes

Word of warning, SwiftData is only available on Apple operating systems, if you try to deploy a vapor app on a Linux machine you might have a problem.

These are currently supported OSs
OS 17.0+ Beta
iPadOS 17.0+ Beta
macOS 14.0+ Beta
Mac Catalyst 17.0+ Beta
tvOS 17.0+ Beta
watchOS 10.0+ Beta
visionOS 1.0+ Beta

3 Likes

Also, SwiftData is not a layer that talks to other databases like Postgres. It's a persistence framework with its own database.

3 Likes

What exactly are you trying to achieve here?

Do you want to use Swift Data in iOS and then be able to use that data from a Vapor App? I'm not sure what I mean by 'in the context of SwiftData'

Thank you @filiplazov and @jonathanpenn for advise.

@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.

Yeah Vapor with Postgres (or another DB) is the way to go.

You might be able to use SwiftData for a local copy of the data in your app but that's out of scope of my knowledge I'm afraid!

3 Likes

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.

But actually it is just SQLite

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.