DataStore Query Building
DataStore provides SQL-style query building methods that compile to optimized SQL queries. All operations are lazy until results are needed.
Query Methods Overview
| Method | SQL Equivalent | Description |
|---|---|---|
select(*cols) | SELECT cols | Select columns |
filter(cond) | WHERE cond | Filter rows |
where(cond) | WHERE cond | Alias for filter |
sort(*cols) | ORDER BY cols | Sort rows |
orderby(*cols) | ORDER BY cols | Alias for sort |
limit(n) | LIMIT n | Limit rows |
offset(n) | OFFSET n | Skip rows |
distinct() | DISTINCT | Remove duplicates |
groupby(*cols) | GROUP BY cols | Group rows |
having(cond) | HAVING cond | Filter groups |
join(right, ...) | JOIN | Join DataStores |
union(other) | UNION | Combine results |
Selection
select
Select specific columns from the DataStore.
Examples:
Filtering
filter / where
Filter rows based on conditions. Both methods are equivalent.
Examples:
Pandas-Style Filtering
Sorting
sort / orderby
Sort rows by one or more columns.
Examples:
Limiting and Pagination
limit
Limit the number of rows returned.
offset
Skip the first n rows.
Examples:
Distinct
distinct
Remove duplicate rows.
Examples:
Grouping
groupby
Group rows by one or more columns. Returns a LazyGroupBy object.
Examples:
having
Filter groups after aggregation.
Examples:
Joining
join
Join two DataStores.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
right | DataStore | required | Right DataStore to join |
on | str/list | None | Column(s) to join on |
how | str | 'inner' | Join type: 'inner', 'left', 'right', 'outer' |
left_on | str/list | None | Left join column(s) |
right_on | str/list | None | Right join column(s) |
Examples:
union
Combine results from two DataStores.
Examples:
Conditional Expressions
when
Create CASE WHEN expressions.
Examples:
Raw SQL
run_sql / sql
Execute raw SQL queries.
Examples:
to_sql
View the generated SQL without executing.
Examples:
Method Chaining
All query methods support fluent chaining:
Aliasing
as_
Set an alias for a column or subquery.
Examples: