diff --git a/docs/class_reference.md b/docs/class_reference.md index c992d8e..6eb2353 100644 --- a/docs/class_reference.md +++ b/docs/class_reference.md @@ -835,10 +835,10 @@ is equivalent to: Returns the whole query as a SQL string. -#### conditions_as_sql() +#### conditions_as_sql(prewhere=True) -Returns the contents of the query's `WHERE` clause as a string. +Returns the contents of the query's `WHERE` or `PREWHERE` clause as a string. #### count() @@ -943,10 +943,10 @@ This method is not supported on `AggregateQuerySet`. Returns the whole query as a SQL string. -#### conditions_as_sql() +#### conditions_as_sql(prewhere=True) -Returns the contents of the query's `WHERE` clause as a string. +Returns the contents of the query's `WHERE` or `PREWHERE` clause as a string. #### count() diff --git a/docs/querysets.md b/docs/querysets.md index 965950e..2329000 100644 --- a/docs/querysets.md +++ b/docs/querysets.md @@ -17,19 +17,19 @@ The `filter` and `exclude` methods are used for filtering the matching instances >>> qs = Person.objects_in(database) >>> qs = qs.filter(first_name__startswith='V').exclude(birthday__lt='2000-01-01') - >>> qs.conditions_as_sql(qs._where) + >>> qs.conditions_as_sql() u"first_name LIKE 'V%' AND NOT (birthday < '2000-01-01')" It is possible to specify several fields to filter or exclude by: >>> qs = Person.objects_in(database).filter(last_name='Smith', height__gt=1.75) - >>> qs.conditions_as_sql(qs._where) + >>> qs.conditions_as_sql() u"last_name = 'Smith' AND height > 1.75" For filters with compound conditions you can use `Q` objects inside `filter` with overloaded operators `&` (AND), `|` (OR) and `~` (NOT): >>> qs = Person.objects_in(database).filter((Q(first_name='Ciaran', last_name='Carver') | Q(height_lte=1.8)) & ~Q(first_name='David')) - >>> qs.conditions_as_sql(qs._where) + >>> qs.conditions_as_sql() u"((first_name = 'Ciaran' AND last_name = 'Carver') OR height <= 1.8) AND (NOT (first_name = 'David'))" By default conditions from `filter` and `exclude` methods are add to `WHERE` clause. @@ -37,7 +37,7 @@ For better aggregation performance you can add them to `PREWHERE` section using >>> qs = Person.objects_in(database) >>> qs = qs.filter(first_name__startswith='V', prewhere=True) - >>> qs.conditions_as_sql(qs._prewhere) + >>> qs.conditions_as_sql(prewhere=True) u"first_name LIKE 'V%'" There are different operators that can be used, by passing `__=` (two underscores separate the field name from the operator). In case no operator is given, `eq` is used by default. Below are all the supported operators. diff --git a/docs/ref.md b/docs/ref.md index a298d04..e750d18 100644 --- a/docs/ref.md +++ b/docs/ref.md @@ -482,9 +482,9 @@ infi.clickhouse_orm.query #### QuerySet(model_cls, database) -#### conditions_as_sql() +#### conditions_as_sql(prewhere=True) -Return the contents of the queryset's WHERE clause. +Return the contents of the queryset's WHERE or `PREWHERE` clause. #### count()