Creating a connection

To create a connection, we extract the path to a database. Since we are using the SQLite database, in contrast to the previous examples, we don't expect a URL, but instead a path to a database file. That's why we use the test.db filename instead of a URL:

let path = matches.value_of("database")
.unwrap_or("test.db");
let manager = ConnectionManager::<SqliteConnection>::new(path);
let pool = r2d2::Pool::new(manager)?;

r2d2::Pool requires a ConnectionManager instance to establish connections with a database, and we can provide SqliteConnection as an associated type to use the SQLite database. We provide a path to a database extracted from command-line arguments. Now let's look at how to use a generated DSL to interact with a database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.18.198