pub async fn migration_api(datamodel: &str) -> CoreResult<Arc<dyn api::GenericApi>> {
    let config = parse_configuration(datamodel)?;
    let features = features::from_config(&config);

    let source = config
        .datasources
        .first()
        .map(|source| match source.provider.as_slice() {
            [_] => Ok(source),
            [] => Err(CoreError::Generic(anyhow!("There is no provider in the datasource."))),
            _ => Err(CoreError::user_facing(DeprecatedProviderArray)),
        })
        .unwrap_or_else(|| Err(CoreError::Generic(anyhow!("There is no datasource in the schema."))))?;

    let connector = match &source.active_provider {
        #[cfg(feature = "sql")]
        provider if POSTGRES_SOURCE_NAME == provider => {
            let database_str = &source.url().value;

            let mut u = url::Url::parse(database_str).map_err(|err| {
                let details = user_facing_errors::quaint::invalid_url_description(
                    database_str,
                    &format!("Error parsing connection string: {}", err),
                );

                ConnectorError::from(KnownError::new(InvalidDatabaseString { details }))
            })?;

            let params: Vec<(String, String)> = u.query_pairs().map(|(k, v)| (k.to_string(), v.to_string())).collect();

            u.query_pairs_mut().clear();

            for (k, v) in params.into_iter() {
                if k == "statement_cache_size" {
                    u.query_pairs_mut().append_pair("statement_cache_size", "0");
                } else {
                    u.query_pairs_mut().append_pair(&k, &v);
                }
            }

            if !u.query_pairs().any(|(k, _)| k == "statement_cache_size") {
                u.query_pairs_mut().append_pair("statement_cache_size", "0");
            }

            SqlMigrationConnector::new(u.as_str(), features).await?
        }
        #[cfg(feature = "sql")]
        provider if [MYSQL_SOURCE_NAME, SQLITE_SOURCE_NAME, MSSQL_SOURCE_NAME].contains(&provider.as_str()) => {
            SqlMigrationConnector::new(&source.url().value, features).await?
        }
        x => unimplemented!("Connector {} is not supported yet", x),
    };

    let api = api::MigrationApi::new(connector);

    Ok(Arc::new(api))
}
/// Top-level constructor for the migration engine API.
Top-level constructor for the migration engine API.
Top - level constructor for the migration engine API .
pub async fn migration_api(datamodel: &str) -> CoreResult<Arc<dyn api::GenericApi>> {
    let config = parse_configuration(datamodel)?;
    let features = features::from_config(&config);
    let source = config
        .datasources
        .first()
        .map(|source| match source.provider.as_slice() {
            [_] => Ok(source),
            [] => Err(CoreError::Generic(anyhow!("There is no provider in the datasource."))),
            _ => Err(CoreError::user_facing(DeprecatedProviderArray)),
        })
        .unwrap_or_else(|| Err(CoreError::Generic(anyhow!("There is no datasource in the schema."))))?;
    let connector = match &source.active_provider {
        #[cfg(feature = "sql")]
        provider if POSTGRES_SOURCE_NAME == provider => {
            let database_str = &source.url().value;
            let mut u = url::Url::parse(database_str).map_err(|err| {
                let details = user_facing_errors::quaint::invalid_url_description(
                    database_str,
                    &format!("Error parsing connection string: {}", err),
                );
                ConnectorError::from(KnownError::new(InvalidDatabaseString { details }))
            })?;
            let params: Vec<(String, String)> = u.query_pairs().map(|(k, v)| (k.to_string(), v.to_string())).collect();
            u.query_pairs_mut().clear();
            for (k, v) in params.into_iter() {
                if k == "statement_cache_size" {
                    u.query_pairs_mut().append_pair("statement_cache_size", "0");
                } else {
                    u.query_pairs_mut().append_pair(&k, &v);
                }
            }
            if !u.query_pairs().any(|(k, _)| k == "statement_cache_size") {
                u.query_pairs_mut().append_pair("statement_cache_size", "0");
            }
            SqlMigrationConnector::new(u.as_str(), features).await?
        }
        #[cfg(feature = "sql")]
        provider if [MYSQL_SOURCE_NAME, SQLITE_SOURCE_NAME, MSSQL_SOURCE_NAME].contains(&provider.as_str()) => {
            SqlMigrationConnector::new(&source.url().value, features).await?
        }
        x => unimplemented!("Connector {} is not supported yet", x),
    };
    let api = api::MigrationApi::new(connector);
    Ok(Arc::new(api))
}
pub async fn migration_api ( datamodel : & str ) -> CoreResult < Arc < dyn api :: GenericApi > > { let config = parse_configuration ( datamodel ) ? ; let features = features :: from_config ( & config ) ; let source = config . datasources . first ( ) . map ( | source | match source . provider . as_slice ( ) { [ _ ] => Ok ( source ) , [ ] => Err ( CoreError :: Generic ( anyhow ! ( " " ) ) ) , _ => Err ( CoreError :: user_facing ( DeprecatedProviderArray ) ) , } ) . unwrap_or_else ( | | Err ( CoreError :: Generic ( anyhow ! ( " " ) ) ) ) ? ; let connector = match & source . active_provider { # [ cfg ( feature " " ) ] provider if POSTGRES_SOURCE_NAME == provider => { let database_str = & source . url ( ) . value ; let mut u = url :: Url :: parse ( database_str ) . map_err ( | err | { let details = user_facing_errors :: quaint :: invalid_url_description ( database_str , & format ! ( " " err ) , ) ; ConnectorError :: from ( KnownError :: new ( InvalidDatabaseString { details } ) ) } ) ? ; let params : Vec < ( String , String ) > = u . query_pairs ( ) . map ( | ( k , v ) | ( k . to_string ( ) , v . to_string ( ) ) ) . collect ( ) ; u . query_pairs_mut ( ) . clear ( ) ; for ( k , v ) in params . into_iter ( ) { if k == " " { u . query_pairs_mut ( ) . append_pair ( " " , " " ) ; } else { u . query_pairs_mut ( ) . append_pair ( & k , & v ) ; } } if ! u . query_pairs ( ) . any ( | ( k , _ ) | k == " " ) { u . query_pairs_mut ( ) . append_pair ( " " , " " ) ; } SqlMigrationConnector :: new ( u . as_str ( ) , features ) . await ? } # [ cfg ( feature " " ) ] provider if [ MYSQL_SOURCE_NAME , SQLITE_SOURCE_NAME , MSSQL_SOURCE_NAME ] . contains ( & provider . as_str ( ) ) => { SqlMigrationConnector :: new ( & source . url ( ) . value , features ) . await ? } x => unimplemented ! ( " " x ) , } ; let api = api :: MigrationApi :: new ( connector ) ; Ok ( Arc :: new ( api ) ) }
Top-level constructor for the migration engine API.
Top - level constructor for the migration engine API .
datamodel
&str
datamodel
&str