I'm new to Rust, and I'm having an issue I can't wrap my head around.
My Cargo.toml
looks like this:
[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"
I have the connection like this on the main.rs
:
use rocket_contrib::databases::diesel;
#[database("urls_db")]
struct UrlsDbConn(diesel::SqliteConnection);
The only table I have is one called urls
, as per schema.rs
:
table! {
urls (id) {
id -> Text,
uri -> Text,
}
}
But when I try to cargo run
it I get:
Error: Database configuration failure: 'urls_db'
=> Error: A table named `databases` was not found for this configuration
Any idea why?
The only place I have a databases
(plural) string is on the Cargo.toml
(global.databases.urls_db
), which is how rocket.rs instructs to set it up...
EDIT: fixed typo; EDIT2: the database itself seems fine:
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>
The database config should be in a Rocket.toml
file:
[global.databases]
urls_db = { url = "urls.sqlite" }
The documentation clearly says so:
Then, in Rocket.toml or the equivalent via environment variables, configure the URL for the database in the databases table: