use pgwire::error::{ErrorInfo, PgWireError};
use nodedb_types::{DatabaseId, Lsn};
use crate::bridge::envelope::{Response, Status};
use crate::types::RequestId;
pub(super) fn synthetic_ok_response(request_id: RequestId, watermark_lsn: Lsn) -> Response {
Response {
request_id,
status: Status::Ok,
attempt: 1,
partial: false,
payload: Vec::<u8>::new().into(),
watermark_lsn,
error_code: None,
read_set_valid: None,
read_version_lsn: crate::types::Lsn::ZERO,
write_set: Vec::new(),
}
}
pub(super) fn strip_db_prefix(db_id: DatabaseId, qualified: &str) -> &str {
if db_id == DatabaseId::DEFAULT {
return qualified;
}
let prefix = format!("{}/", db_id.as_u64());
qualified.strip_prefix(prefix.as_str()).unwrap_or(qualified)
}
pub(super) fn write_err(msg: &str) -> PgWireError {
PgWireError::UserError(Box::new(ErrorInfo::new(
"ERROR".to_owned(),
"XX000".to_owned(),
msg.to_owned(),
)))
}