Skip to main content

MtgjsonSdk

Struct MtgjsonSdk 

Source
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

Source

pub fn builder() -> MtgjsonSdkBuilder

Create a new builder for configuring the SDK.

Source

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.

Source

pub fn sets(&self) -> SetQuery<'_>

Access the set query interface.

Source

pub fn tokens(&self) -> TokenQuery<'_>

Access the token query interface.

Source

pub fn prices(&self) -> PriceQuery<'_>

Access the price query interface.

Requires the prices_today table to have been loaded into DuckDB.

Source

pub fn legalities(&self) -> LegalityQuery<'_>

Access the legality query interface.

Source

pub fn identifiers(&self) -> IdentifierQuery<'_>

Access the identifier query interface.

Source

pub fn decks(&self) -> DeckQuery<'_>

Access the deck query interface.

Deck data is loaded from DeckList.json via the cache manager.

Source

pub fn sealed(&self) -> SealedQuery<'_>

Access the sealed product query interface.

Source

pub fn skus(&self) -> SkuQuery<'_>

Access the TCGplayer SKU query interface.

Requires the tcgplayer_skus table to have been loaded into DuckDB.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

pub fn connection(&self) -> &Connection

Return a reference to the underlying Connection for advanced usage.

Source

pub fn connection_mut(&mut self) -> &mut Connection

Return a mutable reference to the underlying Connection.

Trait Implementations§

Source§

impl Display for MtgjsonSdk

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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, 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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