Skip to main content

Database

Struct Database 

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

DuckDB-backed storage for ticks and bars.

Implementations§

Source§

impl Database

Source

pub fn open(path: &Path) -> Result<Self>

Open (or create) a DuckDB database at the given path.

Source

pub fn open_in_memory() -> Result<Self>

Open an in-memory database (for testing).

Source

pub fn insert_ticks(&self, ticks: &[Tick]) -> Result<usize>

Bulk insert ticks using INSERT OR IGNORE for dedup. Returns the number of rows actually inserted.

Source

pub fn insert_bars(&self, bars: &[Bar]) -> Result<usize>

Bulk insert bars using INSERT OR IGNORE for dedup. Returns the number of rows actually inserted.

Source

pub fn delete_ticks( &self, exchange: &str, symbol: &str, from: Option<NaiveDateTime>, to: Option<NaiveDateTime>, ) -> Result<usize>

Delete ticks matching exchange+symbol, optionally within a date range.

Source

pub fn delete_bars( &self, exchange: &str, symbol: &str, timeframe: &str, from: Option<NaiveDateTime>, to: Option<NaiveDateTime>, ) -> Result<usize>

Delete bars matching exchange+symbol+timeframe, optionally within a date range.

Source

pub fn delete_symbol( &self, exchange: &str, symbol: &str, ) -> Result<(usize, usize)>

Delete ALL data (ticks + bars) for an exchange+symbol pair.

Source

pub fn delete_exchange(&self, exchange: &str) -> Result<(usize, usize)>

Delete ALL data for an entire exchange.

Source

pub fn stats( &self, exchange: Option<&str>, symbol: Option<&str>, ) -> Result<Vec<StatRow>>

Get summary statistics, optionally filtered by exchange and/or symbol.

Source

pub fn query_ticks(&self, opts: &QueryOpts) -> Result<(Vec<Tick>, u64)>

Query ticks with filtering and pagination.

Source

pub fn query_bars(&self, opts: &BarQueryOpts) -> Result<(Vec<Bar>, u64)>

Query bars with filtering and pagination.

Source

pub fn file_size(&self) -> Option<u64>

Get database file size in bytes (None for in-memory).

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, 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.