diesel.rs 和 rocket.rs:不明白为什么要数据库 table
diesel.rs and rocket.rs: don't understand why it wants a databases table
我是 Rust 的新手,我遇到了一个无法解决的问题。
我的 Cargo.toml
看起来像这样:
[dependencies]
rocket = "0.4.6"
rocket_codegen = "0.4.6"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
[dependencies.diesel]
version = "1.0.0"
default-features = false
features = ["sqlite"]
[dependencies.rocket_contrib]
version = "0.4.6"
default-features = false
features = ["diesel_sqlite_pool"]
[global.databases.urls_db]
url = "urls.sqlite"
我在 main.rs
上有这样的连接:
use rocket_contrib::databases::diesel;
#[database("urls_db")]
struct UrlsDbConn(diesel::SqliteConnection);
我唯一的 table 是 urls
,根据 schema.rs
:
table! {
urls (id) {
id -> Text,
uri -> Text,
}
}
但是当我尝试 cargo run
时,我得到:
Error: Database configuration failure: 'urls_db'
=> Error: A table named `databases` was not found for this configuration
知道为什么吗?
我有一个 databases
(复数)字符串的唯一地方是 Cargo.toml
(global.databases.urls_db
),这就是 rocket.rs 指示设置它的方式。 ..
编辑:修正错别字;
EDIT2:数据库本身看起来不错:
main: /Users/carlos/Developer/caarlos0/beckerly/beckerly/urls.sqlite
sqlite> .tables
__diesel_schema_migrations urls
sqlite> select * from urls;
sqlite> insert into urls(id, uri) values ('g', 'https://google.com');
sqlite> select * from urls;
g|https://google.com
sqlite>
数据库配置应该在 Rocket.toml
文件中:
[global.databases]
urls_db = { url = "urls.sqlite" }
文档中说得很清楚:
Then, in Rocket.toml or the equivalent via environment variables, configure the URL for the database in the databases table:
我是 Rust 的新手,我遇到了一个无法解决的问题。
我的 Cargo.toml
看起来像这样:
[dependencies]
rocket = "0.4.6"
rocket_codegen = "0.4.6"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
[dependencies.diesel]
version = "1.0.0"
default-features = false
features = ["sqlite"]
[dependencies.rocket_contrib]
version = "0.4.6"
default-features = false
features = ["diesel_sqlite_pool"]
[global.databases.urls_db]
url = "urls.sqlite"
我在 main.rs
上有这样的连接:
use rocket_contrib::databases::diesel;
#[database("urls_db")]
struct UrlsDbConn(diesel::SqliteConnection);
我唯一的 table 是 urls
,根据 schema.rs
:
table! {
urls (id) {
id -> Text,
uri -> Text,
}
}
但是当我尝试 cargo run
时,我得到:
Error: Database configuration failure: 'urls_db'
=> Error: A table named `databases` was not found for this configuration
知道为什么吗?
我有一个 databases
(复数)字符串的唯一地方是 Cargo.toml
(global.databases.urls_db
),这就是 rocket.rs 指示设置它的方式。 ..
编辑:修正错别字; EDIT2:数据库本身看起来不错:
main: /Users/carlos/Developer/caarlos0/beckerly/beckerly/urls.sqlite
sqlite> .tables
__diesel_schema_migrations urls
sqlite> select * from urls;
sqlite> insert into urls(id, uri) values ('g', 'https://google.com');
sqlite> select * from urls;
g|https://google.com
sqlite>
数据库配置应该在 Rocket.toml
文件中:
[global.databases]
urls_db = { url = "urls.sqlite" }
文档中说得很清楚:
Then, in Rocket.toml or the equivalent via environment variables, configure the URL for the database in the databases table: