[英]Failed to integrate SQLite in Vapor project
I am trying to integrate SQLite into a Vapor project. 我正在尝试将SQLite集成到Vapor项目中。 I have added package for
Sqlite Provider
in the Package.swift
file as: 我在
Package.swift
文件中为Sqlite Provider
添加了软件包:
.Package(url: "https://github.com/vapor/sqlite-provider.git", majorVersion: 1, minor: 1)
and created a sqlite.json
file, under config directory, containing 并在config目录下创建了一个
sqlite.json
文件,其中包含
{
"path": "database_name.sqlite"
}
After that, I ran vapor clean && vapor xcode
to integrate sqlite into the project. 之后,我运行了
vapor clean && vapor xcode
将sqlite集成到该项目中。 Everything worked fine, except now the project shows two Swift Compiler Error : 一切正常,除了现在项目显示两个Swift编译器错误 :
Header '/usr/local/opt/sqlite/include/sqlite3.h' not found
找不到标题'/usr/local/opt/sqlite/include/sqlite3.h'
and 和
Could not build Objective-C module 'CSQliteMac'
无法建立Objective-C模组'CSQliteMac'
Can you help to resolve this issues? 您可以帮助解决此问题吗?
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. 1:首先检查
/usr/local/opt/sqlite
文件夹以及该文件夹内的includes
子文件夹。
2: If the /usr/local/opt/sqlite
folder does not exist, you might need to install SQLite. 2:如果
/usr/local/opt/sqlite
文件夹不存在,则可能需要安装SQLite。 The easiest way to do this would be via Homebrew - if you have it installed. 最简单的方法是通过Homebrew-如果已安装。 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. 3:如果没有Homebrew,则必须决定是要安装Homebrew还是要尝试手动安装SQLite源。
Hopefully, this helps :) 希望这会有所帮助:)
Thanks to @Fahim , the sqlite3.h
wasn't at 感谢@Fahim ,
sqlite3.h
不在
/usr/local/opt/sqlite/include/sqlite3.h
the correct location is, in my case, /usr/local/Cellar/sqlite/3.17.0/include/sqlite3.h
在我的情况下,正确的位置是
/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🍺/usr/local/Cellar/sqlite/3.17.0:11个文件,2.9MB
which is giving the sqlite
location, /usr/local/Cellar/sqlite/3.17.0
. 这给出了
sqlite
位置/usr/local/Cellar/sqlite/3.17.0
。
Now click the first error message, it will take you to the module.modulemap
file. 现在,单击第一条错误消息,它将带您到
module.modulemap
文件。 Replace the location and build. 替换位置并构建。 It will build successfully.
它将成功构建。
It's clearly mysql installation problem, follow below steps to run mysql vapour app. 显然是mysql安装问题,请按照以下步骤运行mysql vapor app。
Install brew from here or run below command 从此处安装brew或运行以下命令
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Run below command to install mysql 运行以下命令以安装mysql
brew install mysql
Run below command for linking 运行以下命令进行链接
brew link mysql
Run below command to start mysql server 运行以下命令以启动mysql服务器
mysql.sever start
Run below command for root user 以root用户身份运行以下命令
mysql -uroot
Then run below command to SET ROOT user password 然后运行以下命令来设置ROOT用户密码
SET PASSWORD = PASSWORD('admin');
Create database before run your project, using below command 使用以下命令在运行项目之前创建数据库
create database your_database_name_goes_here;
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 .
注1: -不要忘了在你的项目描述添加mysql.json 这里 。
. 。
Note2:- Also don't forget to add provider and prepare database table using model class as below.
注意2:-同样不要忘记添加提供者并使用如下模型类准备数据库表。
try drop.addProvider(VaporMySQL.Provider.self)
drop.preparations = [ModelClass.self]
I have created a demo project on Github here , you can try. 我在这里在Github上创建了一个演示项目,您可以尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.