pub fn build(driver: &Driver, db_path: &str) -> Result<Box<dyn Database>, Error>Expand description
It builds a new database driver.
Example for SQLite3:
use torrust_tracker::core::databases;
use torrust_tracker::core::databases::driver::Driver;
let db_driver = Driver::Sqlite3;
let db_path = "./storage/tracker/lib/database/sqlite3.db".to_string();
let database = databases::driver::build(&db_driver, &db_path);Example for MySQL:
use torrust_tracker::core::databases;
use torrust_tracker::core::databases::driver::Driver;
let db_driver = Driver::MySQL;
let db_path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker".to_string();
let database = databases::driver::build(&db_driver, &db_path);Refer to the configuration documentation for more information about the database configuration.
WARNING: The driver instantiation runs database migrations.
§Errors
This function will return an error if unable to connect to the database.
§Panics
This function will panic if unable to create database tables.