-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize field conversion to database format (#1840)
* Remove unnecessary code from to_db_value * Remove TO_DB_OVERRIDE * Add sqlite converters * Cache timezone related settings * Get rid of column_map
- Loading branch information
Showing
9 changed files
with
52 additions
and
132 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
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,24 +1,9 @@ | ||
from typing import Any, Optional, Type, Union | ||
from typing import Any | ||
|
||
from tortoise import Model, fields | ||
from tortoise.backends.odbc.executor import ODBCExecutor | ||
from tortoise.exceptions import UnSupportedError | ||
from tortoise.fields import BooleanField | ||
|
||
|
||
def to_db_bool( | ||
self: BooleanField, value: Optional[Union[bool, int]], instance: Union[Type[Model], Model] | ||
) -> Optional[int]: | ||
self.validate(value) | ||
if value is None: | ||
return None | ||
return int(bool(value)) | ||
|
||
|
||
class MSSQLExecutor(ODBCExecutor): | ||
TO_DB_OVERRIDE = { | ||
fields.BooleanField: to_db_bool, | ||
} | ||
|
||
async def execute_explain(self, sql: str) -> Any: | ||
raise UnSupportedError("MSSQL does not support explain") |
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.