x4h1d
x4h1d

Reputation: 6092

Failed to integrate SQLite in Vapor project

I am trying to integrate SQLite into a Vapor project. I have added package for Sqlite Provider in the Package.swift file as:

.Package(url: "https://github.com/vapor/sqlite-provider.git", majorVersion: 1, minor: 1)

and created a sqlite.json file, under config directory, containing

{
    "path": "database_name.sqlite"
}

After that, I ran vapor clean && vapor xcode to integrate sqlite into the project. Everything worked fine, except now the project shows two Swift Compiler Error:

Header '/usr/local/opt/sqlite/include/sqlite3.h' not found

and

Could not build Objective-C module 'CSQliteMac'

Can you help to resolve this issues?

Upvotes: 0

Views: 618

Answers (3)

Anand Suthar
Anand Suthar

Reputation: 3798

It's clearly mysql installation problem, follow below steps to run mysql vapour app.

  1. First un-install installed mysql.
  2. Install brew from here or run below command

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  3. Run below command to install mysql

    brew install mysql
    
  4. Run below command for linking

    brew link mysql
    
  5. Run below command to start mysql server

    mysql.sever start 
    
  6. Run below command for root user

    mysql -uroot
    
  7. Then run below command to SET ROOT user password

    SET PASSWORD = PASSWORD(‘admin’);
    
  8. Create database before run your project, using below command

    create database your_database_name_goes_here;
    
  9. Then run your project, no doubt after this your project will run.

Note1:- Don't forget to add mysql.json in you project as described here.

.

Note2:- Also don't forget to add provider and prepare database table using model class as below.

 try drop.addProvider(VaporMySQL.Provider.self)
 drop.preparations = [ModelClass.self]

I have created a demo project on Github here, you can try.

Upvotes: 0

x4h1d
x4h1d

Reputation: 6092

Thanks to @Fahim, the sqlite3.h wasn't at

/usr/local/opt/sqlite/include/sqlite3.h

the correct location is, in my case, /usr/local/Cellar/sqlite/3.17.0/include/sqlite3.h

Just run the following command in terminal:

brew install sqlite

It will install or update if you have previously installed. At the end of completion, you will see Summary something like:

==> Summary
🍺 /usr/local/Cellar/sqlite/3.17.0: 11 files, 2.9MB

which is giving the sqlite location, /usr/local/Cellar/sqlite/3.17.0.

Now click the first error message, it will take you to the module.modulemap file. Replace the location and build. It will build successfully.

Upvotes: 0

Fahim
Fahim

Reputation: 3556

Here's what you might want to do:

1: First check that the /usr/local/opt/sqlite folder and the includes subfolder inside that folder exist.

2: If the /usr/local/opt/sqlite folder does not exist, you might need to install SQLite. The easiest way to do this would be via Homebrew - if you have it installed. Just run the following command from Terminal:

brew install sqlite

3: If you don't have Homebrew, then you'll have to decide whether you want to install Homebrew or if you want to try installing the SQLite source manually.

Hopefully, this helps :)

Upvotes: 1

Related Questions