pub struct QuestDB { /* private fields */ }
Expand description
Object to connect to a questdb
Implementations§
Source§impl QuestDB
impl QuestDB
Sourcepub fn new(url: &str) -> Self
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");
Sourcepub async fn exec<T: DeserializeOwned>(
&self,
query: &str,
limit: Option<usize>,
count: Option<bool>,
nm: Option<bool>,
) -> Result<Vec<T>, Error>
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,20count
- 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();
Sourcepub 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>
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 importedschema
- 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 savedoverwrite
- 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 falseatomicity
- 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();
Sourcepub async fn exp(
&self,
query: &str,
limit: Option<usize>,
output_file: &mut File,
) -> Result<(), Error>
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§
impl Freeze for QuestDB
impl !RefUnwindSafe for QuestDB
impl Send for QuestDB
impl Sync for QuestDB
impl Unpin for QuestDB
impl !UnwindSafe for QuestDB
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more