Querying

Query Base Class

class quickbase_client.QuickbaseQuery(where, options=None, group_by=None, sort_by=None, select=None)

A base object for all of the data for a query.

Note

Current alias of QuickbaseQuery for backwards compatibility.

Parameters
  • where (Optional[str]) – The where string, e.g. "{7.EX.'18'}"

  • options (dict) – Additional options to pass to the Quickbase runQuery endpoint.

  • group_by (list[dict]) – The groupBy for the Quickbase runQuery endpoint.

  • sort_by (list[dict]) – The sortBy for the Quickbase runQuery endpoint.

  • select (list[int]) – The list of field ID’s to return. Note that Quickbase by default (i.e. if this parameter is left as None) only returns the “default” fields for the table.


AST Query Building Methods

This module includes functions which create QuickbaseQuery objects.

These can be assembled in an AST-like fashion to build a complex query using higher-level english-readable functions rather than going through the query language (note you can always create a QuickbaseQuery and provide the where string to use that).

Example:

schema = MyTable.schema
my_query = and_(
    eq_(schema.date_opened, schema.date_created),
    on_or_before_(schema.date_closed, date(2020, 11, 16))
)
print(my_query.where) # ({'9'.EX.'_FID_1'}AND{'10'.OBF.'11-16-2020'})

All of the methods (except the two conjunction ones), take a QuickbaseField and a value as a parameter. If you pass a QuickbaseField for the value, it will compare to the actual field (see above). But note if you pass an attribute of a QuickbaseTable class it would be the value in memory of that attribute. If you want to compare to the actual field, use the schema property of the table or quickbase_client.QuickbaseTable.get_field_info().

Note all of these methods are named with a trailing _ to maintain consistency and never clash with a python keyword or anything.

quickbase_client.query.ast.or_(*clauses)

Conjunction to join 2 or more logical OR’s.

quickbase_client.query.ast.and_(*clauses)

Conjunction to join 2 or more logical AND’s.

quickbase_client.query.ast.contains_(field, val)

Contains (CT).

quickbase_client.query.ast.not_contains_(field, val)

Not Contains (XCT).

quickbase_client.query.ast.has_(field, val)

Has (HAS).

quickbase_client.query.ast.not_has_(field, val)

Not Has (XHAS).

quickbase_client.query.ast.eq_(field, val)

Equal/Exactly (EX).

quickbase_client.query.ast.not_eq_(field, val)

Not Equal (XEX).

quickbase_client.query.ast.starts_with_(field, val)

Starts With (SW).

quickbase_client.query.ast.not_starts_width_(field, val)

Not Starts With (XSW).

quickbase_client.query.ast.before_(field, val)

Before (BF).

quickbase_client.query.ast.on_or_before_(field, val)

On or Before (OBF).

quickbase_client.query.ast.after_(field, val)

After (AF).

quickbase_client.query.ast.on_or_after_(field, val)

On or After (OAF).

quickbase_client.query.ast.during_(field, val)

During (IR).

quickbase_client.query.ast.not_during_(field, val)

Not During (XIR).

quickbase_client.query.ast.lt_(field, val)

Less than (LT).

quickbase_client.query.ast.lte_(field, val)

Less than or Equal (LTE).

quickbase_client.query.ast.gt_(field, val)

Greater than (GT).

quickbase_client.query.ast.gte_(field, val)

Greater than or Equal (GTE).