cycquery.interface.QueryInterfaceΒΆ
- class QueryInterface(database, query)[source]ΒΆ
Bases:
object
An interface dataclass to wrap queries, and run them.
- Parameters:
database (
Database
) β Database object to create ORM, and query data.query (
Union
[Select
,Subquery
,Table
,DBTable
,QueryInterface
]) β The query.
Initialize the QueryInterface object, join and chain operations.
Methods
Clear data container.
Join the query with another table.
Chain operations with the query.
Run the query, and fetch data.
Save the query.
Union the query with another query.
Union all the query with another query.
Attributes
Get data.
- __init__(database, query)[source]ΒΆ
Initialize the QueryInterface object, join and chain operations.
- clear_data()[source]ΒΆ
Clear data container.
Sets the data attribute to None, thus clearing the dataframe contained.
- Return type:
- join(join_table, on=None, on_to_type=None, cond=None, table_cols=None, join_table_cols=None, isouter=False)[source]ΒΆ
Join the query with another table.
- Parameters:
join_table (
Union
[Select
,Subquery
,Table
,DBTable
,QueryInterface
]) β Table to join with.on (
Union
[str
,List
[str
],Tuple
[str
],List
[Tuple
[str
,str
]],None
]) β Column(s) to join on.on_to_type (
Union
[type
,List
[type
],None
]) β Type(s) to cast the column(s) to join on.cond (
Optional
[BinaryExpression
]) β Condition to join on.table_cols (
Union
[str
,List
[str
],None
]) β Columns to select from the original table.join_table_cols (
Union
[str
,List
[str
],None
]) β Columns to select from the joined table.isouter (
Optional
[bool
]) β Whether to perform an outer join.
- Returns:
QueryInterface object with the join operation added.
- Return type:
- ops(ops)[source]ΒΆ
Chain operations with the query.
- Parameters:
ops (
Union
[QueryOp
,Sequential
]) β Operations to perform on the query.- Returns:
QueryInterface object with the operations added.
- Return type:
- run(limit=None, index_col=None, batch_mode=False, batch_size=1000000, dtype_backend='pyarrow')[source]ΒΆ
Run the query, and fetch data.
- Parameters:
limit (
Optional
[int
]) β No. of rows to limit the query return.backend β Backend computing framework to use, pandas or dask or datasets.
index_col (
Optional
[str
]) β Column which becomes the index, and defines the partitioning. Should be a indexed column in the SQL server, and any orderable type.batch_mode (
bool
) β Whether to run the query in batch mode. A generator is returned if True.batch_size (
int
) β Batch size for the query, default 1 million rows.dtype_backend (
str
) β Data type to use for the backend, default pyarrow.
- Returns:
Query result.
- Return type:
pandas.DataFrame or Generator[pandas.DataFrame, None, None]
- union(other)[source]ΒΆ
Union the query with another query.
- Parameters:
other (
QueryInterface
) β The other query to union with.- Returns:
QueryInterface object with the union operation added.
- Return type:
- union_all(other)[source]ΒΆ
Union all the query with another query.
- Parameters:
other (
QueryInterface
) β The other query to union all with.- Returns:
QueryInterface object with the union all operation added.
- Return type: