Skip to content

Commit

Permalink
hotfix filter function with postgres
Browse files Browse the repository at this point in the history
- postgres allow only boolean value with where syntax
  • Loading branch information
hqsz committed Mar 24, 2020
1 parent 5d58232 commit 8ad8e19
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tortoise/backends/asyncpg/executor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import uuid
from typing import List, Optional
from typing import Any, List, Optional

import asyncpg
from pypika import Parameter
from pypika.terms import Term, ValueWrapper

from tortoise import Model
from tortoise.backends.base.executor import BaseExecutor
from tortoise.filters import is_in, not_in


def postgres_is_in(field: Term, value: Any) -> Term:
if value:
return field.isin(value)
return ValueWrapper(False)


def post_gres_not_in(field: Term, value: Any) -> Term:
if value:
return field.notin(value) | field.isnull()
return ValueWrapper(True)


class AsyncpgExecutor(BaseExecutor):
FILTER_FUNC_OVERRIDE = {
is_in: postgres_is_in,
not_in: post_gres_not_in,
}
EXPLAIN_PREFIX = "EXPLAIN (FORMAT JSON, VERBOSE)"
DB_NATIVE = BaseExecutor.DB_NATIVE | {bool, uuid.UUID}

Expand Down

0 comments on commit 8ad8e19

Please sign in to comment.