diff --git a/resources/turso/Cargo.toml b/resources/turso/Cargo.toml index 1d66be1f2..45685f77d 100644 --- a/resources/turso/Cargo.toml +++ b/resources/turso/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shuttle-turso" -version = "0.42.0" +version = "0.42.1" edition = "2021" license = "Apache-2.0" description = "Plugin to obtain a client connected to a Turso database" diff --git a/resources/turso/src/lib.rs b/resources/turso/src/lib.rs index 0b93b5c40..1159ec9bd 100644 --- a/resources/turso/src/lib.rs +++ b/resources/turso/src/lib.rs @@ -18,7 +18,7 @@ pub struct Turso { pub struct TursoOutput { conn_url: Url, token: Option, - environment: Environment, + remote: bool, } impl Turso { @@ -58,7 +58,7 @@ impl Turso { async fn output_from_addr( &self, addr: &str, - environment: Environment, + remote: bool, ) -> Result { Ok(TursoOutput { conn_url: Url::parse(addr).map_err(Error::UrlParseError)?, @@ -67,7 +67,7 @@ impl Turso { } else { Some(self.token.clone()) }, - environment, + remote, }) } } @@ -89,12 +89,12 @@ impl ResourceInputBuilder for Turso { "addr must start with either libsql:// or https://", ))); } - self.output_from_addr(&self.addr, md.env).await + self.output_from_addr(&self.addr, true).await } } Environment::Local => { match self.local_addr { - Some(ref local_addr) => self.output_from_addr(local_addr, md.env).await, + Some(ref local_addr) => self.output_from_addr(local_addr, true).await, None => { // Default to a local db of the name of the service. let db_file = std::env::current_dir() // Should be root of the project's workspace @@ -110,7 +110,7 @@ impl ResourceInputBuilder for Turso { conn_url: Url::parse(&conn_url).map_err(Error::UrlParseError)?, // Nullify the token since we're using a file as database. token: None, - environment: md.env, + remote: false, }) } } @@ -122,16 +122,17 @@ impl ResourceInputBuilder for Turso { #[async_trait] impl IntoResource for TursoOutput { async fn into_resource(self) -> Result { - let database = match self.environment { - Environment::Deployment => Database::open_remote( + let database = if self.remote { + Database::open_remote( self.conn_url.to_string(), self.token .clone() .ok_or(ShuttleError::Custom(CustomError::msg( "missing token for remote database", )))?, - ), - Environment::Local => Database::open(self.conn_url.to_string()), + ) + } else { + Database::open(self.conn_url.to_string()) }; database .map_err(|err| ShuttleError::Custom(err.into()))? @@ -159,7 +160,7 @@ mod test { TursoOutput { conn_url: Url::parse(local_addr).unwrap(), token: None, - environment: Environment::Local, + remote: true, } ) } @@ -196,7 +197,7 @@ mod test { TursoOutput { conn_url: Url::parse(&addr).unwrap(), token: Some("token".to_string()), - environment: Environment::Deployment, + remote: true, } ) }