#query #order #limit-order #unpack #range #cw-storage-plus #contracts

sg-index-query

A package that holds common functionality for dealing with cw-storage-plus indices

2 releases

0.1.1 Jul 26, 2023
0.1.0 Jul 26, 2023

#6 in #limit-order

Download history 6/week @ 2024-02-19 32/week @ 2024-02-26 7/week @ 2024-03-04 21/week @ 2024-03-11 7/week @ 2024-03-18 15/week @ 2024-03-25 47/week @ 2024-04-01 8/week @ 2024-04-08 9/week @ 2024-04-15

80 downloads per month
Used in 2 crates

Apache-2.0

10KB
124 lines

sg-index-query

sg-index-query is a Rust crate providing a QueryOptions struct for use in CosmWasm smart contracts. It allows you to specify query parameters such as limit, order, and the min max of range queries.

Features

  • QueryOptions struct for specifying query parameters such as limit, order, and range.
  • unpack function for converting QueryOptions into QueryOptionsInternal, which is used for range queries in cw_storage_plus.

Usage

First, add the following to your Cargo.toml:

[dependencies]
sg-index-query = "0.1.0"

Then, you can use the QueryOptions struct in your code:

use sg_index_query::QueryOptions;

let query_options = QueryOptions::<String>::default();

You can specify query parameters like so:

use sg_index_query::{QueryOptions, QueryBound};

let query_options = QueryOptions {
    descending: Some(true),
    limit: Some(20),
    min: Some(QueryBound::Inclusive("test".to_string())),
    max: Some(QueryBound::Exclusive("test2".to_string())),
};

Then, you can unpack the QueryOptions into QueryOptionsInternal:

let query_options_internal = query_options.unpack(&|offset: &String| offset.to_string(), None, None);

Dependencies

~3.5–5.5MB
~117K SLoC