use std::sync::{Arc, Weak};
use futures_util::{lock::Mutex, stream::BoxStream};
use crate::{
SnowflakeError,
auth::session::Session,
driver::{
base::bindings::BindMetadata,
primitives::{cell::ToCellValue, column::Column, row},
},
http::client::SnowflakeHttpClient,
};
pub trait Query<C: SnowflakeHttpClient> {
type Result: QueryResult;
type Describe: DescribeResult;
fn new(query: impl ToString, session: Weak<Mutex<Session<C>>>) -> Self;
fn bind_row(&mut self, params: Vec<impl ToCellValue>);
fn bind_row_named(&mut self, params: Vec<(impl ToString, impl ToCellValue)>);
fn execute(self) -> impl Future<Output = Result<Self::Result, SnowflakeError>>;
fn describe(self) -> impl Future<Output = Result<Self::Describe, SnowflakeError>>;
}
pub trait QueryResult {
fn columns(&self) -> Vec<Arc<Column>>;
fn is_dml(&self) -> bool;
fn is_dql(&self) -> bool;
fn rows_affected(&self) -> i64;
fn rows_updated(&self) -> i64;
fn rows_deleted(&self) -> i64;
fn rows_inserted(&self) -> i64;
fn expected_result_length(&self) -> i64;
fn rows(self) -> BoxStream<'static, Result<row::Row, SnowflakeError>>;
}
pub trait DescribeResult {
fn columns(&self) -> Vec<Arc<Column>>;
fn bind_metadata(&self) -> Option<Vec<BindMetadata>>;
fn bind_count(&self) -> i32;
fn is_dml(&self) -> bool;
fn is_dql(&self) -> bool;
}