qb_sql!() { /* proc-macro */ }Expand description
Builds a type-safe QuickBooks Online query at compile time.
This macro parses SQL-like syntax and generates a Query<T> struct that can be used to query
the QuickBooks Online API. Field names are automatically validated at compile time and converted
from snake_case to CamelCase to match QuickBooks naming conventions.
§Syntax
qb_sql!(
select [* | field1, field2, ...]
from EntityType
[where condition [and condition ...]]
[order by field [asc|desc] [, field [asc|desc] ...]]
[limit number [offset number]]
)§Supported Operators
=- Equality comparison>,<,>=,<=- Numeric comparisonslike- Pattern matching (use%as wildcard)in- Match against multiple values:field in (val1, val2, ...)orfield in (iterator)
§Examples
Basic query with field selection:
ⓘ
use quick_oxibooks_sql::qb_sql;
use quickbooks_types::Customer;
let query = qb_sql!(
select display_name, balance from Customer
where balance >= 1000.0
order by display_name asc
limit 10
);Using Rust variables in conditions:
ⓘ
let min_balance = 500.0;
let name_pattern = "Acme%";
let query = qb_sql!(
select * from Customer
where balance >= min_balance
and display_name like name_pattern
);Using the in operator with a tuple or iterator:
ⓘ
// With literal values
let query = qb_sql!(
select * from Customer
where id in (1, 2, 3)
);
// With an iterator (single expression)
let ids = vec!["1", "2", "3"];
let query = qb_sql!(
select * from Customer
where id in (ids)
);Executing a query (requires the api feature):
ⓘ
use quick_oxibooks::{Environment, QBContext};
use ureq::Agent;
let client = Agent::new();
let qb = QBContext::new(Environment::SANDBOX, "company_id".into(), "token".into(), &client)?;
let results = query.execute(&qb, &client)?;§Notes
- Field names are automatically converted from
snake_caseto CamelCase (e.g.,display_name→DisplayName) - All field names are validated at compile time against the entity type
- The generated query can be converted to a string with
.query_string()or by displaying it - For the
inoperator, use a tuple for literals or a single iterator expression