Make FluentSQLite usable on iOS
twof opened this issue Β· 13 comments
The two most popular options for persistence on iOS (Realm and Core Data), both rely heavily on Objective-C, however, SQLite is available. I think there is a good opportunity to not only have a Swift based persistence layer on iOS, but also promote code sharing between Vapor servers and iOS clients.
Concept:
// Shared models package, imported by both client and server
class User: Codable {
let id: Int?
let name: String
let age: Int
}
// Client
extension User: SQLiteModel, Migration {}
// Server
extension User: PostgresModel, Migration {}
I haven't heavily investigated what is keeping users from utilizing FluentSQLite in their iOS apps, but the first thing that comes to mind is the Console package's use of Process()
Would also need to support CocoaPods and Carthage unless we want to hold this off until WWDC and make a bet that SPM will finally be integrated into Xcode
Technically it's possible to use SPM with iOS apps if we wanted to for testing, but it's really hacky and I'd definitely advise against it in production
https://www.ralfebert.de/ios-examples/xcode/ios-dependency-management-with-swift-package-manager/
Got a macOS Cocoa app running with FluentSQLite using that method
Good news! Process
was the only thing preventing this package from being compiled for iOS. It's used in one method in Console and extended in Core, and neither that method nor that extension are used in this package. After wrapping those two in #if os(OSX)
, the package compiles just fine. Trying to figure out how to import it into an iOS project now.
Well, thatβs simple ... convert this and all subsequent projects (might not be necessary) and make them each an xcode project ... adding that I think will be the biggest challenge to get through the NIO guys and Tanner ... ;) unless weβll get lucky this WWDC
Forked, built using iOS 11.3, and imported the framework to a test project using the instructions here
https://stackoverflow.com/a/40990828/3908168
Cleaned and built, but I'm getting error: missing required module 'CNIOAtomics'
. Is there anything special about that file?
Its a swift wrapper around a c library so that one might be tricky, you might have to do some header/modulemap magic to get that to work
@twof I didn't see those in my build. Maybe the NIO guys would know more.
Would also need to support CocoaPods and Carthage unless we want to hold this off until WWDC and make a bet that SPM will finally be integrated into Xcode
looks like they did it πππ
I've been able to use it in an iOS project, and it just works! (Well, there was one slight edit I needed to make)
cc @tanner0101
Does anyone have the steps of getting this to work on iOS? Is there official support for it now? I looked in the swift package and the platform only specifies Mac_os ?
Any ideas @broadwaylamb @twof ?
Thanks!
Does anyone have the steps of getting this to work on iOS? Is there official support for it now? I looked in the swift package and the platform only specifies Mac_os ?
Any ideas @broadwaylamb @twof ?
Thanks!
I managed to add https://github.com/vapor/fluent-sqlite-driver.git
as a package dependency to a new iOS single-view application project and import FluentSQLite
. The build was successful, but after that I'm not sure what to do.
I tried SQLiteDatabase()
but I'm guessing we need some way to connect to the database in order for it to work.
I think a lead to the right direction on making FluentSQLite work on iOS would be much appreciated.
@alobaili @ismyhc Check out this example: https://github.com/twof/iOSFluentExample/blob/master/iOSFluentApp/iOSFluentApp/ContentView.swift
The syntax might be slightly out of date because I created this demo while everything was still in beta, but the principles should still be correct.