Vapor 2.0: Where is SQLite Stored?

I am using Vapor and the built-in SQLite 3 driver: https://github.com/vapor/sqlite

So, I changed "driver": "memory"

to "driver": "sqlite"

to fluent.json and created sqlite.json :

{
    "path": "data.sqlite"
}

      

But even if I use Spotlight search, I cannot find a file named data.sqlite. I also cannot use sqlite-provider

which is popular in many tutorials I have found because it is not compatible with Vapor 2: Failed to create Xcode project: swift-package: error: unsatisfactory

Nevertheless, the data is stored somewhere: I can restart my Mac, start Vapor and see all the data.

I read a lot of similar questions, but none of the authors used Vapor, so these answers didn't work for me. I need to get this location of the data.sqlite file. What am I doing wrong?

PS I am using Xcode 8.3.2, Swift 3.1, Vapor 2.0.1. SQLite3 is installed.

+4


source to share


3 answers


Well, I still don't understand where the Vapor database files are stored, but I found this solution:

Xcode > Product > Scheme > Edit Scheme > Options >  Use Custom Working Directory

      



I installed this to the parent directory of the project and data.sqlite appears there.

However, I still wonder where and under what name they were originally saved, even though Spotlight can't find them.

+2


source


The terminal command find

can be used to search for files that cannot otherwise be found by Spotlight search:

sudo find / -name "VaporSQLite.sqlite" -print

      

In Vapor 2, SQLite is part of Fluent

, so SQLiteProvider

no longer required. Tutorials that use use SQLiteProvider

instead FluentProvider

.

For template api

Vapor 2 is enabled by default Fluent

. For a web

non-Vapor 2 template fluent-provider

you need to add in Package.swift

and then customize in 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 discovery for a SQLite file 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" }

      

Please note that the expected location of the .sqlite is specified in the file Config/sqlite.json

.

cd ..
vapor update
vapor build
vapor run &
sudo find / -name "FindMeSQLite.sqlite" -print

      

Result: "FindMeSQLite.sqlite" is in the 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" found again in path/to/VaporDefaultExample/FindMeSQLite.sqlite

as specified inConfig/sqlite.json

NOTE. If the location of the .sqlite is different from your configuration then find

macOS or Ubuntu should detect that location.

+2


source


This happens when you use XCode to build and run your Vapor project. Xcode uses a local temp directory for every application that is in development. Use Vapor CLI in Terminal

 $ vapor build 
 $ vapor run

      

Then, all of your old databases will be removed and a new .sqlite file will be created in your main directory.

0


source







All Articles