Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/better api #452

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/redis-with-msg-pack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tracing-subscriber = "0.3.11"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
email-service = { path = "../email-service" }
rmp-serde = "1.3"
redis = "0.25"
redis = "0.27"


[dependencies.tracing]
Expand Down
39 changes: 7 additions & 32 deletions packages/apalis-sql/src/from_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,15 @@ use crate::context::SqlContext;
/// Wrapper for [Request]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SqlRequest<T> {
pub(crate) req: Request<T, SqlContext>,
/// The inner request
pub req: Request<T, SqlContext>,
pub(crate) _priv: (),
}

impl<T> SqlRequest<T> {
/// Creates a new SqlRequest.
pub fn new(req: Request<T, SqlContext>) -> Self {
SqlRequest { req }
}

/// Gets a reference to the request.
pub fn req(&self) -> &T {
&self.req.args
}

/// Gets a mutable reference to the request.
pub fn req_mut(&mut self) -> &mut T {
&mut self.req.args
}

/// Sets the request.
pub fn set_req(&mut self, req: T) {
self.req.args = req;
}

/// Gets a reference to the context.
pub fn context(&self) -> &SqlContext {
&self.req.parts.context
}

/// Gets a mutable reference to the context.
pub fn context_mut(&mut self) -> &mut SqlContext {
&mut self.req.parts.context
}

/// Sets the context.
pub fn set_context(&mut self, context: SqlContext) {
self.req.parts.context = context;
SqlRequest { req, _priv: () }
}
}

Expand Down Expand Up @@ -110,6 +82,7 @@ impl<'r, T: Decode<'r, sqlx::Sqlite> + Type<sqlx::Sqlite>>
parts.context = context;
Ok(SqlRequest {
req: Request::new_with_parts(job, parts),
_priv: (),
})
}
}
Expand Down Expand Up @@ -173,6 +146,7 @@ impl<'r, T: Decode<'r, sqlx::Postgres> + Type<sqlx::Postgres>>
parts.context = context;
Ok(SqlRequest {
req: Request::new_with_parts(job, parts),
_priv: (),
})
}
}
Expand Down Expand Up @@ -235,6 +209,7 @@ impl<'r, T: Decode<'r, sqlx::MySql> + Type<sqlx::MySql>> sqlx::FromRow<'r, sqlx:
parts.context = context;
Ok(SqlRequest {
req: Request::new_with_parts(job, parts),
_priv: (),
})
}
}
Loading