-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
161 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from .exceptions import SQLQueryBuilderBaseException | ||
from .search import SQLQueryBuilder | ||
from .exceptions import QueryBaseException | ||
from .query_builder import build_query | ||
|
||
__all__ = [ | ||
"SQLQueryBuilderBaseException", | ||
"SQLQueryBuilder", | ||
"QueryBaseException", | ||
"build_query", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,54 @@ | ||
class SQLQueryBuilderBaseException(Exception): | ||
from typing import Optional, Tuple, Type | ||
|
||
from luqum.tree import Item | ||
|
||
|
||
class QueryBaseException(Exception): | ||
""" | ||
Base exception for SQLQueryBuilder | ||
""" | ||
|
||
|
||
class UnsupportedGrammarException(SQLQueryBuilderBaseException): | ||
class QueryParseException(QueryBaseException): | ||
""" | ||
Raised when SQLQueryBuilder does not support given Lucene grammar | ||
Raised when Lucene parser is unable to parse a query | ||
""" | ||
|
||
|
||
class FieldNotQueryableException(SQLQueryBuilderBaseException): | ||
class UnsupportedNodeException(QueryBaseException): | ||
def __init__(self, message: str, node: Item): | ||
super().__init__(f"{message} ({node.pos}:{node.pos + node.size - 1})") | ||
|
||
|
||
class UnsupportedNodeTypeException(UnsupportedNodeException): | ||
""" | ||
Raised when field does not exists, so it can't be queried, eg. file.unexistent_field | ||
Raised when query visitor does not support given Lucene grammar | ||
""" | ||
|
||
def __init__(self, node: Item, expected: Optional[Tuple[Type, ...]] = None): | ||
message = f"{node.__class__.__name__} is not supported here" | ||
if expected: | ||
message += f", expected {', '.join(typ.__name__ for typ in expected)}" | ||
super().__init__(message, node) | ||
|
||
class MultipleObjectsQueryException(SQLQueryBuilderBaseException): | ||
|
||
class UnsupportedLikeStatement(UnsupportedNodeException): | ||
def __init__(self, node: Item): | ||
super().__init__("Like statements are not supported here", node) | ||
|
||
|
||
class InvalidValueException(QueryBaseException): | ||
def __init__(self, value: str, expected: str): | ||
super().__init__(f"Invalid value format: {value}, expected {expected}") | ||
|
||
|
||
class FieldNotQueryableException(QueryBaseException): | ||
""" | ||
Raised when multiple object types are queried, | ||
e.g. file.file_name:something AND static.cfg:something2 | ||
Raised when field does not exists, so it can't be queried, eg. file.unexistent_field | ||
""" | ||
|
||
|
||
class ObjectNotFoundException(SQLQueryBuilderBaseException): | ||
class ObjectNotFoundException(QueryBaseException): | ||
""" | ||
Raised when object referenced in query condition can't be found | ||
""" |
Oops, something went wrong.