sqlxのインストール方法


前置き

RustでWEB APIを作成したいと思い、dockerでrust環境構築してhello worldを見ながら環境構築をしていたところ躓いたのでここに記す。

sqlxのインストール方法

dockerを使用してRust + DBの開発環境を整える時に躓いたsqlxのインストールについて書く。

エラー文

1
2
3
4
5
6
7
8
9
10
11
12
13
14
error: one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', 'runtime-tokio-rustls'] must be enabled
#6 349.4 --> /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/sqlx-rt-0.6.2/src/lib.rs:11:1
#6 349.4 |
#6 349.4 11 | / compile_error!(
#6 349.4 12 | | "one of the features ['runtime-actix-native-tls', 'runtime-async-std-native-tls', \
#6 349.4 13 | | 'runtime-tokio-native-tls', 'runtime-actix-rustls', 'runtime-async-std-rustls', \
#6 349.4 14 | | 'runtime-tokio-rustls'] must be enabled"
#6 349.4 15 | | );
#6 349.4 | |_^
#6 349.4
#6 349.4 Compiling hex v0.4.3
#6 349.5 error: could not compile `sqlx-rt` due to previous error
#6 349.5 warning: build failed, waiting for other jobs to finish...
#6 350.2 error: failed to compile `sqlx-cli v0.6.2`, intermediate artifacts can be found at `/tmp/target`

どうやらsqlxがうまくインストールできていないみたい、、、
調べるとここで対処法が書かれている。
どうやらコマンドが違うようである。
以下のように直したら治った。

1
2
3
4
5
# 以前
&& cargo install sqlx-cli --no-default-features --features mysql

# 変更後
 && cargo install sqlx-cli --no-default-features --features native-tls,mysql

参考

https://github.com/launchbadge/sqlx/issues/1678
https://zenn.dev/marimoofficial/articles/cc21bf30b0fefc