vapor-community / sqlite-provider

SQLite3 provider for Vapor
MIT License
10 stars 8 forks source link

How to use external sqlite file to store data in Vapor 3 project #14

Open blabz-rahulmandalkar opened 6 years ago

blabz-rahulmandalkar commented 6 years ago

Hello , I have installed sqlite3 in my mac using homebrew. I have created one Hello.sqlite file using '$sqlite3 Hello.sqlite' so i want to use it in my vapor3 project to store/fetch data.I specified the path of that file in configure.swift file like

let sqlite:SQLiteDatabase sqlite = try SQLiteDatabase(storage: .file(path: "/Users/bridgelabz/Documents/Vapor3/Hello/HelloDB.sqlite")) /// Register the configured SQLite database to the database config. var databases = DatabasesConfig() databases.add(database: sqlite, as: .sqlite) services.register(databases) and it's migration is also done successfully. After that I inserted records into 'Todo' (SQLiteModel) table using DB Browser Tool that is also done successfully. But problem is that when i am trying to fetch data from 'Todo' it's showing empty. So i am not able to understand which step i missed.please help me out ... Following is file contents : 1) Package.swift ` let package = Package( name: "Hello",

dependencies: [
    // 💧 A server-side Swift web framework.
    .package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),

    // 🔵 Swift ORM (queries, models, relations, etc) built on SQLite 3.
    .package(url: "https://github.com/vapor/fluent-sqlite.git", from: "3.0.0-rc.2")
],

targets: [
    .target(name: "App", dependencies: ["FluentSQLite", "Vapor"]),
    .target(name: "Run", dependencies: ["App"]),
    .testTarget(name: "AppTests", dependencies: ["App"])
]

) 2) Boot.swift import Vapor /// Called after your application has initialized.

    public func boot(_ app: Application) throws {
        // your code here
    }

`