use std::collections::HashMap;
use serde::Serialize;
#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ExecRequest {
pub sql_text: String,
pub async_exec: bool,
pub sequence_id: u64,
pub is_internal: bool,
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub describe_only: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub bindings: Option<HashMap<String, BindParam>>,
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub parameters: HashMap<String, serde_json::Value>,
}
#[derive(Serialize, Debug, Clone)]
pub struct BindParam {
#[serde(rename = "type")]
pub type_: &'static str,
pub value: serde_json::Value,
}
#[derive(Debug, Clone)]
pub struct Bind(pub(crate) BindParam);
impl Bind {
pub fn text(s: impl Into<String>) -> Self {
Self(BindParam {
type_: "TEXT",
value: serde_json::Value::String(s.into()),
})
}
pub fn fixed(n: i64) -> Self {
Self(BindParam {
type_: "FIXED",
value: serde_json::Value::String(n.to_string()),
})
}
pub fn real(f: f64) -> Self {
Self(BindParam {
type_: "REAL",
value: serde_json::Value::String(f.to_string()),
})
}
pub fn boolean(b: bool) -> Self {
Self(BindParam {
type_: "BOOLEAN",
value: serde_json::Value::String(b.to_string()),
})
}
pub fn null(type_: &'static str) -> Self {
Self(BindParam {
type_,
value: serde_json::Value::Null,
})
}
}
impl From<&str> for Bind {
fn from(s: &str) -> Self {
Bind::text(s)
}
}
impl From<String> for Bind {
fn from(s: String) -> Self {
Bind::text(s)
}
}
impl From<i32> for Bind {
fn from(n: i32) -> Self {
Bind::fixed(i64::from(n))
}
}
impl From<i64> for Bind {
fn from(n: i64) -> Self {
Bind::fixed(n)
}
}
impl From<u32> for Bind {
fn from(n: u32) -> Self {
Bind::fixed(i64::from(n))
}
}
impl From<f32> for Bind {
fn from(f: f32) -> Self {
Bind::real(f64::from(f))
}
}
impl From<f64> for Bind {
fn from(f: f64) -> Self {
Bind::real(f)
}
}
impl From<bool> for Bind {
fn from(b: bool) -> Self {
Bind::boolean(b)
}
}
#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct AbortRequest {
pub request_id: String,
}
#[derive(Serialize, Debug)]
pub struct LoginRequest<T> {
pub data: T,
}
pub type PasswordLoginRequest = LoginRequest<PasswordRequestData>;
#[cfg(feature = "cert-auth")]
pub type CertLoginRequest = LoginRequest<CertRequestData>;
#[cfg(feature = "browser-auth")]
pub type BrowserLoginRequest = LoginRequest<BrowserRequestData>;
#[derive(Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct LoginRequestCommon {
pub client_app_id: String,
pub client_app_version: String,
pub svn_revision: String,
pub account_name: String,
pub login_name: String,
pub session_parameters: SessionParameters,
pub client_environment: ClientEnvironment,
}
#[derive(Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct SessionParameters {
pub client_validate_default_parameters: bool,
}
#[derive(Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct ClientEnvironment {
pub application: String,
pub os: String,
pub os_version: String,
pub ocsp_mode: String,
}
#[derive(Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct PasswordRequestData {
#[serde(flatten)]
pub login_request_common: LoginRequestCommon,
pub password: String,
}
#[derive(Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct CertRequestData {
#[serde(flatten)]
pub login_request_common: LoginRequestCommon,
pub authenticator: String,
pub token: String,
}
#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RenewSessionRequest {
pub old_session_token: String,
pub request_type: String,
}
#[cfg(feature = "browser-auth")]
#[derive(Serialize, Debug)]
pub struct AuthenticatorRequest {
pub data: AuthenticatorRequestData,
}
#[cfg(feature = "browser-auth")]
#[derive(Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct AuthenticatorRequestData {
pub client_app_id: String,
pub client_app_version: String,
pub svn_revision: String,
pub account_name: String,
pub login_name: String,
pub authenticator: String,
pub browser_mode_redirect_port: String,
pub proof_key: String,
pub client_environment: AuthenticatorClientEnvironment,
}
#[cfg(feature = "browser-auth")]
#[derive(Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct AuthenticatorClientEnvironment {
pub application: String,
pub os: String,
pub os_version: String,
}
#[cfg(feature = "browser-auth")]
#[derive(Serialize, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct BrowserRequestData {
#[serde(flatten)]
pub login_request_common: LoginRequestCommon,
pub authenticator: String,
pub token: String,
pub proof_key: String,
}