Skip to main content

init_db

Function init_db 

Source
pub async fn init_db<'q>(
    db: &SqlitePool,
    name: &str,
    ddls: impl IntoIterator<Item = Query<'q, Sqlite, SqliteArguments<'q>>>,
    version_migrations: Vec<Query<'q, Sqlite, SqliteArguments<'q>>>,
) -> Result<()>
Expand description

This function initializes the database by checking whether it needs to be created or upgraded. The ddls are the DDL(Data Definition Language) statements to create the tables in the database and their initial required content. The schema_version will be set inside the database if it is newly created. Otherwise, the version is read from the database and returned. This value should be checked against the expected version to determine if the database needs to be upgraded. It is up to the caller to close the database if an error is returned by this function.