Struct QuestDB

Source
pub struct QuestDB { /* private fields */ }
Expand description

Object to connect to a questdb

Implementations§

Source§

impl QuestDB

Source

pub fn new(url: &str) -> Self

Creates a new connection to questdb

§Example
use questdb::QuestDB;
let connection = QuestDB::new("http://192.168.1.37:9000");
Source

pub async fn exec<T: DeserializeOwned>( &self, query: &str, limit: Option<usize>, count: Option<bool>, nm: Option<bool>, ) -> Result<Vec<T>, Error>

Compiles and executes the SQL query supplied

§Arguments
  • query - query text. It can be multi-line, but query separator, such as ; must not be included.
  • limit - This argument is used for paging. Limit can be either in format of X, Y where X is the lower limit and Y is the upper, or just Y. For example, limit=10,20 will return row numbers 10 thru to 20 inclusive. and limit=20 will return first 20 rows, which is equivalent to limit=0,20
  • count - Instructs /exec to count rows and return this value in message header. Default value is false. There is slight performance hit for requesting row count.
  • nm - Skips metadata section of the response when true. When metadata is known and client is paging this flag should typically be set to true to reduce response size. Default value is false and metadata is included in the response.
§Example
use questdb::QuestDB;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct TestData {
    id: i32,
    ts: String,
    temp: f64,
    sensor_id: i32,
}

let connection = QuestDB::new("http://192.168.1.37:9000");
let res = connection.exec::<TestData>("select * from readings", Some(5), None, None)
    .await
    .unwrap();
Source

pub async fn imp( &self, file_path: &'static str, schema: Option<Vec<SchemaMap>>, table_name: &'static str, overwrite: Option<bool>, durable: Option<bool>, atomicity: Option<Atomicity>, ) -> Result<(), Error>

The function imp streams tabular text data directly into a table. It supports CSV, TAB and Pipe (|) delimited inputs and optional headers. There are no restrictions on data size. Data type and structure is detected automatically and usually without additional configuration. However in some cases additional configuration can be provided to augment automatic detection results.

§Arguments
  • file_path - Path to the file that is going to be imported
  • schema - List of columns and their types. This will overwrite the default unless the table is already created.
  • table_name - Name of the table where the data will be saved
  • overwrite - Default value is false. Set it to true to have existing table deleted before appending data.
  • durable - When request is durable QuestDB will flush relevant disk cache before responding. Default value is false
  • atomicity - Available values are strict and relaxed. Default value is relaxed. When atomicity is relaxed data rows that cannot be appended to table are discarded, thus allowing partial uploads. In strict mode upload fails as soon as any data error is encountered and all previously appended rows are rolled back.
§Example
let connection = QuestDB::new("http://192.168.1.37:9000");
let schema = new_schema!(("movieId", Schema::String), ("imdbId", Schema::Int));

let res = connection.imp("./test.csv", Some(schema), "nu_table123", None, None, None)
    .await
    .unwrap();
Source

pub async fn exp( &self, query: &str, limit: Option<usize>, output_file: &mut File, ) -> Result<(), Error>

Exports the result of the query to a CSV file

§Arguments
  • query - query text. It can be multi-line, but query separator, such as ; must not be included.
  • limit - This argument is used for paging. Limit can be either in format of X, Y where X is the lower limit and Y is the upper, or just Y. For example, limit=10,20 will return row numbers 10 thru to 20 inclusive. and limit=20 will return first 20 rows, which is equivalent to limit=0,20
§Example
use questdb::QuestDB;
use std::fs::File;

let connection = QuestDB::new("http://192.168.1.37:9000");

let mut output_file = File::create("output.csv").unwrap();
let res = match connection.exp("select * from nu_table", Some(5), &mut output_file)
    .await
    .unwrap();

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T