maestral.database.query

SQL query definitions that facilitate writing object-oriented code to generate SQL queries.

Module Contents

class maestral.database.query.Query[source]

Base type for query

abstract clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]

order_by(expr)[source]
Parameters:

expr (str)

Return type:

OrderedQuery

class maestral.database.query.OrderedQuery(query, order_expr)[source]

Bases: Query

Ordered query

Parameters:
base_query[source]
order_expr[source]
clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]

class maestral.database.query.PathTreeQuery(column, path)[source]

Bases: Query

Query for an entire subtree at the given path.

Parameters:
column[source]
file_blob[source]
dir_blob[source]
clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]

class maestral.database.query.MatchQuery(column, value)[source]

Bases: Query

Query to match an exact value.

Parameters:
column[source]
value[source]
clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]

class maestral.database.query.AllQuery[source]

Bases: Query

Query to match everything.

clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]

class maestral.database.query.CollectionQuery(*subqueries)[source]

Bases: Query

An abstract query class that aggregates other queries. Can be indexed like a list to access the sub-queries.

Parameters:

subqueries (Query) – Subqueries to aggregate.

subqueries[source]
clause_with_joiner(joiner)[source]

Return a clause created by joining together the clauses of all subqueries with the string joiner (padded by spaces).

Parameters:

joiner (str)

Return type:

tuple[str, Sequence[Any]]

abstract clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]

class maestral.database.query.AndQuery(*subqueries)[source]

Bases: CollectionQuery

A conjunction of a list of other queries.

Parameters:

subqueries (Query)

clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]

class maestral.database.query.OrQuery(*subqueries)[source]

Bases: CollectionQuery

A conjunction of a list of other queries.

Parameters:

subqueries (Query)

clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]

class maestral.database.query.NotQuery(subquery)[source]

Bases: Query

A query that matches the negation of its subquery, as a shortcut for performing not(subquery) without using regular expressions.

Parameters:

subquery (Query) – Query to negate.

subquery[source]
clause()[source]

Generate the corresponding SQL clause.

Returns:

SQL clause and arguments to substitute.

Return type:

tuple[str, Sequence[Any]]