pub async fn simple_execute(
        &mut self,
        stmts: &str,
    ) -> Result<SimpleExecuteResponse, CoordError> {
        // Convert most floats to a JSON Number. JSON Numbers don't support NaN or
        // Infinity, so those will still be rendered as strings.
        fn float_to_json(f: f64) -> serde_json::Value {
            match serde_json::Number::from_f64(f) {
                Some(n) => serde_json::Value::Number(n),
                None => serde_json::Value::String(f.to_string()),
            }
        }

        fn datum_to_json(datum: &Datum) -> serde_json::Value {
            match datum {
                // Convert some common things to a native JSON value. This doesn't need to be
                // too exhaustive because the SQL-over-HTTP interface is currently not hooked
                // up to arbitrary external user queries.
                Datum::Null | Datum::JsonNull => serde_json::Value::Null,
                Datum::False => serde_json::Value::Bool(false),
                Datum::True => serde_json::Value::Bool(true),
                Datum::Int16(n) => serde_json::Value::Number(serde_json::Number::from(*n)),
                Datum::Int32(n) => serde_json::Value::Number(serde_json::Number::from(*n)),
                Datum::Int64(n) => serde_json::Value::Number(serde_json::Number::from(*n)),
                Datum::Float32(n) => float_to_json(n.into_inner() as f64),
                Datum::Float64(n) => float_to_json(n.into_inner()),
                Datum::Numeric(d) => {
                    // serde_json requires floats to be finite
                    if d.0.is_infinite() {
                        serde_json::Value::String(d.0.to_string())
                    } else {
                        serde_json::Value::Number(
                            serde_json::Number::from_f64(f64::try_from(d.0).unwrap()).unwrap(),
                        )
                    }
                }
                Datum::String(s) => serde_json::Value::String(s.to_string()),
                Datum::List(list) => serde_json::Value::Array(
                    list.iter().map(|entry| datum_to_json(&entry)).collect(),
                ),
                Datum::Map(map) => serde_json::Value::Object(
                    map.iter()
                        .map(|(k, v)| (k.to_owned(), datum_to_json(&v)))
                        .collect(),
                ),
                _ => serde_json::Value::String(datum.to_string()),
            }
        }

        let stmts = sql::parse::parse(&stmts).map_err(|e| CoordError::Unstructured(e.into()))?;
        self.start_transaction(None).await?;
        const EMPTY_PORTAL: &str = "";
        let mut results = vec![];
        for stmt in stmts {
            self.declare(EMPTY_PORTAL.into(), stmt, vec![]).await?;
            let desc = self
                .session()
                .get_portal(EMPTY_PORTAL)
                .map(|portal| portal.desc.clone())
                .expect("unnamed portal should be present");
            if !desc.param_types.is_empty() {
                return Err(CoordError::Unsupported("parameters"));
            }

            let res = self.execute(EMPTY_PORTAL.into()).await?;

            let rows = match res {
                ExecuteResponse::SendingRows(rows) => {
                    let response = rows.await;
                    response
                }
                _ => return Err(CoordError::Unsupported("statements of the executed type")),
            };
            let rows = match rows {
                PeekResponse::Rows(rows) => rows,
                PeekResponse::Error(e) => coord_bail!("{}", e),
                PeekResponse::Canceled => coord_bail!("execution canceled"),
            };
            let mut sql_rows: Vec<Vec<serde_json::Value>> = vec![];
            let col_names = match desc.relation_desc {
                Some(desc) => desc.iter_names().map(|name| name.to_string()).collect(),
                None => vec![],
            };
            let mut datum_vec = repr::DatumVec::new();
            for row in rows {
                let datums = datum_vec.borrow_with(&row);
                sql_rows.push(datums.iter().map(datum_to_json).collect());
            }
            results.push(SimpleResult {
                rows: sql_rows,
                col_names,
            })
        }
        Ok(SimpleExecuteResponse { results })
    }
/// Executes SQL statements using a simple protocol that does not involve
/// portals.
///
/// The standard flow for executing a SQL statement requires parsing the
/// statement, binding it into a portal, and then executing that portal.
/// This function is a wrapper around that complexity with a simpler
/// interface. The provided `stmts` are executed directly, and their results
/// are returned as a vector of rows, where each row is a vector of JSON
/// objects.
Executes SQL statements using a simple protocol that does not involve
portals.

The standard flow for executing a SQL statement requires parsing the
statement, binding it into a portal, and then executing that portal.
This function is a wrapper around that complexity with a simpler
interface. The provided `stmts` are executed directly, and their results
are returned as a vector of rows, where each row is a vector of JSON
objects.
Executes SQL statements using a simple protocol that does not involve portals . The standard flow for executing a SQL statement requires parsing the statement binding it into a portal and then executing that portal . This function is a wrapper around that complexity with a simpler interface . The provided ` stmts ` are executed directly and their results are returned as a vector of rows where each row is a vector of JSON objects .
pub async fn simple_execute(
        &mut self,
        stmts: &str,
    ) -> Result<SimpleExecuteResponse, CoordError> {
        // Convert most floats to a JSON Number. JSON Numbers don't support NaN or
        // Infinity, so those will still be rendered as strings.
        fn float_to_json(f: f64) -> serde_json::Value {
            match serde_json::Number::from_f64(f) {
                Some(n) => serde_json::Value::Number(n),
                None => serde_json::Value::String(f.to_string()),
            }
        }
        fn datum_to_json(datum: &Datum) -> serde_json::Value {
            match datum {
                // Convert some common things to a native JSON value. This doesn't need to be
                // too exhaustive because the SQL-over-HTTP interface is currently not hooked
                // up to arbitrary external user queries.
                Datum::Null | Datum::JsonNull => serde_json::Value::Null,
                Datum::False => serde_json::Value::Bool(false),
                Datum::True => serde_json::Value::Bool(true),
                Datum::Int16(n) => serde_json::Value::Number(serde_json::Number::from(*n)),
                Datum::Int32(n) => serde_json::Value::Number(serde_json::Number::from(*n)),
                Datum::Int64(n) => serde_json::Value::Number(serde_json::Number::from(*n)),
                Datum::Float32(n) => float_to_json(n.into_inner() as f64),
                Datum::Float64(n) => float_to_json(n.into_inner()),
                Datum::Numeric(d) => {
                    // serde_json requires floats to be finite
                    if d.0.is_infinite() {
                        serde_json::Value::String(d.0.to_string())
                    } else {
                        serde_json::Value::Number(
                            serde_json::Number::from_f64(f64::try_from(d.0).unwrap()).unwrap(),
                        )
                    }
                }
                Datum::String(s) => serde_json::Value::String(s.to_string()),
                Datum::List(list) => serde_json::Value::Array(
                    list.iter().map(|entry| datum_to_json(&entry)).collect(),
                ),
                Datum::Map(map) => serde_json::Value::Object(
                    map.iter()
                        .map(|(k, v)| (k.to_owned(), datum_to_json(&v)))
                        .collect(),
                ),
                _ => serde_json::Value::String(datum.to_string()),
            }
        }
        let stmts = sql::parse::parse(&stmts).map_err(|e| CoordError::Unstructured(e.into()))?;
        self.start_transaction(None).await?;
        const EMPTY_PORTAL: &str = "";
        let mut results = vec![];
        for stmt in stmts {
            self.declare(EMPTY_PORTAL.into(), stmt, vec![]).await?;
            let desc = self
                .session()
                .get_portal(EMPTY_PORTAL)
                .map(|portal| portal.desc.clone())
                .expect("unnamed portal should be present");
            if !desc.param_types.is_empty() {
                return Err(CoordError::Unsupported("parameters"));
            }
            let res = self.execute(EMPTY_PORTAL.into()).await?;
            let rows = match res {
                ExecuteResponse::SendingRows(rows) => {
                    let response = rows.await;
                    response
                }
                _ => return Err(CoordError::Unsupported("statements of the executed type")),
            };
            let rows = match rows {
                PeekResponse::Rows(rows) => rows,
                PeekResponse::Error(e) => coord_bail!("{}", e),
                PeekResponse::Canceled => coord_bail!("execution canceled"),
            };
            let mut sql_rows: Vec<Vec<serde_json::Value>> = vec![];
            let col_names = match desc.relation_desc {
                Some(desc) => desc.iter_names().map(|name| name.to_string()).collect(),
                None => vec![],
            };
            let mut datum_vec = repr::DatumVec::new();
            for row in rows {
                let datums = datum_vec.borrow_with(&row);
                sql_rows.push(datums.iter().map(datum_to_json).collect());
            }
            results.push(SimpleResult {
                rows: sql_rows,
                col_names,
            })
        }
        Ok(SimpleExecuteResponse { results })
    }
pub async fn simple_execute ( & mut self , stmts : & str , ) -> Result < SimpleExecuteResponse , CoordError > { // Convert most floats to a JSON Number. JSON Numbers don't support NaN or // Infinity, so those will still be rendered as strings. fn float_to_json ( f : f64 ) -> serde_json :: Value { match serde_json :: Number :: from_f64 ( f ) { Some ( n ) => serde_json :: Value :: Number ( n ) , None => serde_json :: Value :: String ( f . to_string ( ) ) , } } fn datum_to_json ( datum : & Datum ) -> serde_json :: Value { match datum { // Convert some common things to a native JSON value. This doesn't need to be // too exhaustive because the SQL-over-HTTP interface is currently not hooked // up to arbitrary external user queries. Datum :: Null | Datum :: JsonNull => serde_json :: Value :: Null , Datum :: False => serde_json :: Value :: Bool ( false ) , Datum :: True => serde_json :: Value :: Bool ( true ) , Datum :: Int16 ( n ) => serde_json :: Value :: Number ( serde_json :: Number :: from ( * n ) ) , Datum :: Int32 ( n ) => serde_json :: Value :: Number ( serde_json :: Number :: from ( * n ) ) , Datum :: Int64 ( n ) => serde_json :: Value :: Number ( serde_json :: Number :: from ( * n ) ) , Datum :: Float32 ( n ) => float_to_json ( n . into_inner ( ) as f64 ) , Datum :: Float64 ( n ) => float_to_json ( n . into_inner ( ) ) , Datum :: Numeric ( d ) => { // serde_json requires floats to be finite if d . 0 . is_infinite ( ) { serde_json :: Value :: String ( d . 0 . to_string ( ) ) } else { serde_json :: Value :: Number ( serde_json :: Number :: from_f64 ( f64 :: try_from ( d . 0 ) . unwrap ( ) ) . unwrap ( ) , ) } } Datum :: String ( s ) => serde_json :: Value :: String ( s . to_string ( ) ) , Datum :: List ( list ) => serde_json :: Value :: Array ( list . iter ( ) . map ( | entry | datum_to_json ( & entry ) ) . collect ( ) , ) , Datum :: Map ( map ) => serde_json :: Value :: Object ( map . iter ( ) . map ( | ( k , v ) | ( k . to_owned ( ) , datum_to_json ( & v ) ) ) . collect ( ) , ) , _ => serde_json :: Value :: String ( datum . to_string ( ) ) , } } let stmts = sql :: parse :: parse ( & stmts ) . map_err ( | e | CoordError :: Unstructured ( e . into ( ) ) ) ? ; self . start_transaction ( None ) . await ? ; const EMPTY_PORTAL : & str = " " ; let mut results = vec ! [ ] ; for stmt in stmts { self . declare ( EMPTY_PORTAL . into ( ) , stmt , vec ! [ ] ) . await ? ; let desc = self . session ( ) . get_portal ( EMPTY_PORTAL ) . map ( | portal | portal . desc . clone ( ) ) . expect ( " " ) ; if ! desc . param_types . is_empty ( ) { return Err ( CoordError :: Unsupported ( " " ) ) ; } let res = self . execute ( EMPTY_PORTAL . into ( ) ) . await ? ; let rows = match res { ExecuteResponse :: SendingRows ( rows ) => { let response = rows . await ; response } _ => return Err ( CoordError :: Unsupported ( " " ) ) , } ; let rows = match rows { PeekResponse :: Rows ( rows ) => rows , PeekResponse :: Error ( e ) => coord_bail ! ( " " e ) , PeekResponse :: Canceled => coord_bail ! ( " " ) , } ; let mut sql_rows : Vec < Vec < serde_json :: Value > > = vec ! [ ] ; let col_names = match desc . relation_desc { Some ( desc ) => desc . iter_names ( ) . map ( | name | name . to_string ( ) ) . collect ( ) , None => vec ! [ ] , } ; let mut datum_vec = repr :: DatumVec :: new ( ) ; for row in rows { let datums = datum_vec . borrow_with ( & row ) ; sql_rows . push ( datums . iter ( ) . map ( datum_to_json ) . collect ( ) ) ; } results . push ( SimpleResult { rows : sql_rows , col_names , } ) } Ok ( SimpleExecuteResponse { results } ) }
Executes SQL statements using a simple protocol that does not involve
portals.
Executes SQL statements using a simple protocol that does not involve portals .
&mut self
stmts
&str
&mut self
stmts
&str