Hi there y'all this is my first post on these forums, but not my first time visiting. I've been learning Swift over the past 6+ months and spending a lot of time on the swift.org reference docs, Apple's Swift lang/Foundation docs, Stack Overflow, and here (and the Vapor Discord of all places). So thanks to everyone who answers questions here – I've already benefitted a lot from your contributions!
For my first foray into Swift, I'm actually diving into the nascent server-side Swift space – it has allowed me to focus on learning the language without also learning too many frameworks (e.g. SwiftUI) at the same time. I'm far enough along in the journey to start running builds of my project on a server, and my first step there was to reach for a Linux server. After some poking around with install Swift on Linux (which wasn't so straightforward) I settled on using the official Docker images for my build environment (as this will also work nicely for CI/CD), and then attempted a build.
The only dependencies in my project are Foundation, SQLite3, and Vapor (for the HTTP Server). Swift build appears to fetch all the dependencies for Vapor, then immediately fail on SQLite3 with the error:
No such module `SQLite3`
Is this a known issue? Is there a workaround that doesn't involve a third-party SQLite library? Perhaps something like building my own SQLite from sources in
Package.swift (i.e. the SQLite Amalgamation; example: GitHub - sbooth/CSQLite: SQLite packaged for the Swift Package Manager)?
Is SQLite3 somehow related to Foundation? And is Foundation not recommended for cross-platform (i.e. Linux) projects?
Welcome to server-side Swift!
No. SQLite3 is missing because it is not part of the standard Swift SDK. On Apple's platforms SQLite3 is present as part of the SDK, but on Linux it is not: you need to bridge it in using the Swift Package Manager. Using the package you linked is likely fine.
If you don't have a good reason to avoid it, you should feel free to use it. The closer you stay to currency data types the better success you'll have. Foundation on Linux is in a state of flux right now, so this is a rapidly evolving space.
Thanks for the quick reply and welcome!
Is there a reference for how to do this? I presume this involves ensuring that the
libsqlite3-dev package is installed, and then ___? Sorry if I'm missing some obvious reference docs on how to do this.
Oh, I missed that you said this:
So either use that package, or follow a similar approach. Got it.
If you're already using Vapor I'd recommend sqlite-nio, which vendors amalgamated SQLite sources, so you won't need to install SQLite separately, and also provides low-level Swifty wrapper types and functions for it.
And for an even higher level interface, if you are already using Vapor you can use the Fluent SQLite Driver and configure it per the Vapor docs.
I'm running into the same problem here with a new Vapor install.
I have all the fluent and swift-nio packages that come with the default Vapor installation out of the box. They all appear to be downloaded after starting a build. However I'm receiving the
No such module SQLite3`` error.
This is on a Ubuntu server. I'm wondering is there some extra step needed beyond these Swift dependencies?
It compiles fine on my local Mac machine as a Vapor server, or command line app.
Quick note - I did find a simple fix here, might help someone else.
I was able to swap out "import SQLite3" for "import CSQLite" and "import SQLiteNIO".
And then the usual SQLite 3 commands work, with a "sqlite_nio_" prefix on them. For example: