pub struct MtgjsonSdk { /* private fields */ }Expand description
The main entry point for the MTGJSON SDK.
Wraps a Connection (which owns the CacheManager and DuckDB database)
and exposes domain-specific query interfaces as lightweight borrowing wrappers.
Created via MtgjsonSdk::builder().
Implementations§
Source§impl MtgjsonSdk
impl MtgjsonSdk
Sourcepub fn builder() -> MtgjsonSdkBuilder
pub fn builder() -> MtgjsonSdkBuilder
Create a new builder for configuring the SDK.
Sourcepub fn cards(&self) -> CardQuery<'_>
pub fn cards(&self) -> CardQuery<'_>
Access the card query interface.
Returns a lightweight wrapper that borrows from the underlying connection and provides methods for querying card data.
Sourcepub fn tokens(&self) -> TokenQuery<'_>
pub fn tokens(&self) -> TokenQuery<'_>
Access the token query interface.
Sourcepub fn prices(&self) -> PriceQuery<'_>
pub fn prices(&self) -> PriceQuery<'_>
Access the price query interface.
Requires the prices_today table to have been loaded into DuckDB.
Sourcepub fn legalities(&self) -> LegalityQuery<'_>
pub fn legalities(&self) -> LegalityQuery<'_>
Access the legality query interface.
Sourcepub fn identifiers(&self) -> IdentifierQuery<'_>
pub fn identifiers(&self) -> IdentifierQuery<'_>
Access the identifier query interface.
Sourcepub fn decks(&self) -> DeckQuery<'_>
pub fn decks(&self) -> DeckQuery<'_>
Access the deck query interface.
Deck data is loaded from DeckList.json via the cache manager.
Sourcepub fn sealed(&self) -> SealedQuery<'_>
pub fn sealed(&self) -> SealedQuery<'_>
Access the sealed product query interface.
Sourcepub fn skus(&self) -> SkuQuery<'_>
pub fn skus(&self) -> SkuQuery<'_>
Access the TCGplayer SKU query interface.
Requires the tcgplayer_skus table to have been loaded into DuckDB.
Sourcepub fn enums(&self) -> EnumQuery<'_>
pub fn enums(&self) -> EnumQuery<'_>
Access the enum/keyword query interface.
Enum data is loaded from JSON files (Keywords.json, CardTypes.json,
EnumValues.json) via the cache manager.
Sourcepub fn booster(&self) -> BoosterSimulator<'_>
pub fn booster(&self) -> BoosterSimulator<'_>
Access the booster pack simulator.
The simulator reads from the set booster parquet tables to generate randomized booster packs matching real-world distribution rules.
Sourcepub fn meta(&self) -> Result<Value>
pub fn meta(&self) -> Result<Value>
Load and return the MTGJSON metadata (version, date, etc.).
Fetches Meta.json from the cache (downloading if necessary) and
returns the parsed JSON object.
Sourcepub fn views(&self) -> Vec<String>
pub fn views(&self) -> Vec<String>
Return the list of currently registered DuckDB view names.
Views are registered lazily on first query, so this list grows as different query interfaces are used.
Sourcepub fn sql(
&self,
query: &str,
params: &[String],
) -> Result<Vec<HashMap<String, Value>>>
pub fn sql( &self, query: &str, params: &[String], ) -> Result<Vec<HashMap<String, Value>>>
Execute a raw SQL query against the DuckDB database.
Provides escape-hatch access for queries not covered by the domain-specific interfaces.
§Arguments
query- SQL string with?positional placeholders.params- Parameter values corresponding to the placeholders.
§Returns
A vector of rows, each represented as a HashMap<String, serde_json::Value>.
Sourcepub fn export_db<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
pub fn export_db<P: AsRef<Path>>(&self, path: P) -> Result<PathBuf>
Export the in-memory DuckDB database to a directory on disk.
Uses DuckDB’s EXPORT DATABASE command to write the database contents
(schema + data) to the given path.
Sourcepub fn refresh(&self) -> Result<bool>
pub fn refresh(&self) -> Result<bool>
Check for a newer MTGJSON version and reset views if stale.
Returns true if the data was stale and views were reset (meaning
subsequent queries will re-download data), or false if already
up to date.
Sourcepub fn close(self)
pub fn close(self)
Consume the SDK and release all resources.
Closes the DuckDB connection and HTTP client. This is called automatically when the SDK is dropped, but can be invoked explicitly for deterministic cleanup.
Sourcepub fn connection(&self) -> &Connection
pub fn connection(&self) -> &Connection
Return a reference to the underlying Connection for advanced usage.
Sourcepub fn connection_mut(&mut self) -> &mut Connection
pub fn connection_mut(&mut self) -> &mut Connection
Return a mutable reference to the underlying Connection.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for MtgjsonSdk
impl !RefUnwindSafe for MtgjsonSdk
impl !Sync for MtgjsonSdk
impl !UnwindSafe for MtgjsonSdk
impl Send for MtgjsonSdk
impl Unpin for MtgjsonSdk
impl UnsafeUnpin for MtgjsonSdk
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.