Reputation: 203
I'm using Vapor and a built-in SQLite 3 driver: https://github.com/vapor/sqlite
So i changed "driver": "memory"
to "driver": "sqlite"
in fluent.json and created sqlite.json:
{
"path": "data.sqlite"
}
But even if I use Spotlight search I cannot find any file called data.sqlite. I cannot also use sqlite-provider
which is popular in many tutorials I found because it's not compatible with Vapor 2:
Could not generate Xcode project: swift-package: error: unsatisfiable
But nevertheless the data is stored somewhere: I can reboot my Mac, run Vapor and see all the data.
I have read a lot of similar questions here but none of authors used Vapor, so those answers hasn't help me. I need to get this data.sqlite file location. What am I doing wrong?
P.S I'm using Xcode 8.3.2, Swift 3.1, Vapor 2.0.1. SQLite3 is installed.
Upvotes: 4
Views: 1647
Reputation: 9862
A terminal find
command line can be used to find the "data.sqlite" (or other known database name) file not otherwise locatable by Spotlight Search:
sudo find / -name "data.sqlite" -print
In the Vapor 2, SQLite is a part of Fluent
so SQLiteProvider
is no longer needed. Tutorials which use SQLiteProvider
would instead use FluentProvider
.
For the Vapor 2 default api
template, Fluent
is included. For the Vapor 2 non-default web
template, fluent-provider
needs to be added to Package.swift
and subsequently configured in the code.
For swift package tools-version
3.1.0
dependencies: [
…
.Package(url: "https://github.com/vapor/fluent-provider.git", majorVersion: 1),
For swift package tools-version
4.0.0
dependencies: [
…
.package(url: "https://github.com/vapor/fluent-provider.git", .upToNextMajor(from: "1.3.0")),
My finding for where the SQLite file is generated for Vapor 2 follows...
vapor --version
# Vapor Toolbox: 2.0.3
# Vapor Framework: 2.1.0
vapor new VaporDefaultExample
cd VaporDefaultExample/Config
nano fluent.json # edit to: "driver": "sqlite"
nano sqlite.json # create file. add { "path":"FindMeSQLite.sqlite" }
Note that the expected .sqlite location is specifed in the Config/sqlite.json
file.
cd ..
vapor update
vapor build
vapor run &
sudo find / -name "FindMeSQLite.sqlite" -print
Result: "FindMeSQLite.sqlite" is found at path/to/VaporDefaultExample/FindMeSQLite.sqlite as specified in Config/sqlite.json
# ^C quit the previous vapor run
# then create Xcode project
vapor xcode -y
# run project in Xcode
# then, repeat the find
sudo find / -name "FindMeSQLite.sqlite" -print
Result: "FindMeSQLite.sqlite" is again found at path/to/VaporDefaultExample/FindMeSQLite.sqlite
as specified in Config/sqlite.json
NOTE: if the .sqlite location is different for your configuration, then find
on either macOS or Ubuntu should reveal such location.
Upvotes: 2
Reputation: 743
This happens when you use XCode to build and run your Vapor Project. Xcode uses local temporary directory for every app which is in development stage. Use Vapor's CLI in terminal
$ vapor build
$ vapor run
Then all your old database will be deleted and a new .sqlite file is created in your main directory.
Upvotes: 0
Reputation: 203
Well, I still don't understand where Vapor store database files, but I found this solution:
Xcode > Product > Scheme > Edit Scheme > Options > Use Custom Working Directory
I set this to my project's parent directory and data.sqlite appears there.
However, I still wonder where and under what name they were originally stored if even Spotlight can't find them.
Upvotes: 3