Skip to content

Commit

Permalink
Move WriteResult to mod
Browse files Browse the repository at this point in the history
Summary:
Up until this diff the implementation of WriteResult was in the `fbmysql_wrapper`. However the implementation can be used for any mysql implemntation as it is very simple.
Here I extract it to the `mod.rs` file so I can reuse it for the external mysql version later in the stack

Reviewed By: gustavoavena

Differential Revision: D50838010

fbshipit-source-id: 8e9246b116634fbae42c65737482f0ab864650b4
  • Loading branch information
Clara Rull authored and facebook-github-bot committed Nov 2, 2023
1 parent 5b807f7 commit f9f22a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
24 changes: 20 additions & 4 deletions shed/sql/common/mysql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ pub use facebook::TransactionResult;
pub use facebook::TryFromRowField;
#[cfg(fbcode_build)]
pub use facebook::ValueError;
#[cfg(fbcode_build)]
pub use facebook::WriteResult;
pub use mysql_derive::OptTryFromRowField;
pub use mysql_derive::TryFromRowField;
#[cfg(not(fbcode_build))]
Expand All @@ -58,8 +56,6 @@ pub use mysql_stub::TransactionResult;
pub use mysql_stub::TryFromRowField;
#[cfg(not(fbcode_build))]
pub use mysql_stub::ValueError;
#[cfg(not(fbcode_build))]
pub use mysql_stub::WriteResult;

use super::WriteResult as SqlWriteResult;

Expand Down Expand Up @@ -154,6 +150,26 @@ pub enum IsolationLevel {
ReadCommitted,
}

/// Result returned by a write query
pub struct WriteResult(u64, u64);

impl WriteResult {
/// Create result
pub fn new(last_insert_id: u64, rows_affected: u64) -> Self {
WriteResult(last_insert_id, rows_affected)
}

/// Get last inserted id
pub fn last_insert_id(&self) -> u64 {
self.0
}

/// Get number of affected rows
pub fn rows_affected(&self) -> u64 {
self.1
}
}

impl From<WriteResult> for SqlWriteResult {
fn from(result: WriteResult) -> Self {
Self::new(Some(result.last_insert_id()), result.rows_affected())
Expand Down
15 changes: 1 addition & 14 deletions shed/sql/common/mysql/mysql_stub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::fmt::Display;
use thiserror::Error;

use crate::mysql::IsolationLevel;
use crate::mysql::WriteResult;

/// Error for Mysql client
#[derive(Error, Debug)]
Expand Down Expand Up @@ -42,20 +43,6 @@ impl From<ValueError> for MysqlError {
}
}

/// Result returned by a write query
pub struct WriteResult;

impl WriteResult {
/// Get last inserted id
pub fn last_insert_id(&self) -> u64 {
unimplemented!("This is a stub");
}
/// Get number of affected rows
pub fn rows_affected(&self) -> u64 {
unimplemented!("This is a stub");
}
}

/// ODS counters
pub struct ConnectionStats;

Expand Down

0 comments on commit f9f22a5

Please sign in to comment.