sqllogictest_engines/postgres/
simple.rsuse std::process::Command;
use std::time::Duration;
use async_trait::async_trait;
use sqllogictest::{DBOutput, DefaultColumnType};
use super::{Postgres, Result, Simple};
#[async_trait]
impl sqllogictest::AsyncDB for Postgres<Simple> {
type Error = tokio_postgres::error::Error;
type ColumnType = DefaultColumnType;
async fn run(&mut self, sql: &str) -> Result<DBOutput<Self::ColumnType>> {
let mut output = vec![];
let rows = self.client.simple_query(sql).await?;
let mut cnt = 0;
for row in rows {
let mut row_vec = vec![];
match row {
tokio_postgres::SimpleQueryMessage::Row(row) => {
for i in 0..row.len() {
match row.get(i) {
Some(v) => {
if v.is_empty() {
row_vec.push("(empty)".to_string());
} else {
row_vec.push(v.to_string());
}
}
None => row_vec.push("NULL".to_string()),
}
}
}
tokio_postgres::SimpleQueryMessage::CommandComplete(cnt_) => {
cnt = cnt_;
break;
}
tokio_postgres::SimpleQueryMessage::RowDescription(_) => {
continue;
}
cmd => unreachable!("unsupported cmd: {cmd:?}, please create an issue in risinglightdb/sqllogictest-rs"),
}
output.push(row_vec);
}
if output.is_empty() {
Ok(DBOutput::StatementComplete(cnt))
} else {
Ok(DBOutput::Rows {
types: vec![DefaultColumnType::Any; output[0].len()],
rows: output,
})
}
}
fn engine_name(&self) -> &str {
"postgres"
}
async fn sleep(dur: Duration) {
tokio::time::sleep(dur).await
}
async fn run_command(command: Command) -> std::io::Result<std::process::Output> {
tokio::process::Command::from(command).output().await
}
}