-
-
Notifications
You must be signed in to change notification settings - Fork 394
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
19 changed files
with
640 additions
and
160 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
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
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,18 +1,25 @@ | ||
from typing import List | ||
from typing import List, Any | ||
|
||
from pypika import Parameter, Table | ||
|
||
from tortoise import Model | ||
from tortoise.backends.base.executor import BaseExecutor | ||
|
||
|
||
class AsyncpgExecutor(BaseExecutor): | ||
|
||
EXPLAIN_PREFIX = "EXPLAIN (FORMAT JSON, VERBOSE)" | ||
|
||
def _prepare_insert_statement(self, columns: List[str]) -> str: | ||
return str( | ||
query = ( | ||
self.db.query_class.into(Table(self.model._meta.table)) | ||
.columns(*columns) | ||
.insert(*[Parameter("$%d" % (i + 1,)) for i in range(len(columns))]) | ||
.returning("id") | ||
) | ||
generated_fields = self.model._meta.generated_db_fields | ||
if generated_fields and self.db.fetch_inserted: | ||
query = query.returning(*generated_fields) | ||
return str(query) | ||
|
||
async def _process_insert_result(self, instance: Model, results: Any): | ||
if self.model._meta.generated_db_fields and self.db.fetch_inserted: | ||
instance.set_field_values(dict(results)) |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import Optional, Union | ||
from uuid import UUID | ||
|
||
from tortoise.fields import JSONField as GenericJSONField, UUIDField as GenericUUIDField | ||
|
||
|
||
class JSONField(GenericJSONField): | ||
def to_db_value(self, value: Optional[Union[dict, list]], instance): | ||
return value | ||
|
||
def to_python_value(self, value: Optional[Union[str, dict, list]]): | ||
return value | ||
|
||
|
||
class UUIDField(GenericUUIDField): | ||
def to_db_value(self, value: Optional[UUID], instance): | ||
return value | ||
|
||
def to_python_value(self, value: Optional[UUID]): | ||
return value |
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
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
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
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
Oops, something went wrong.