-
-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from tortoise/feature/prepared_statements
Insert cleanup
- Loading branch information
Showing
17 changed files
with
264 additions
and
235 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,5 +1,5 @@ | ||
[settings] | ||
line_length=100 | ||
multi_line_output=0 | ||
known_third_party= | ||
known_third_party=aiosqlite,ciso8601 | ||
not_skip=__init__.py |
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,4 +1,4 @@ | ||
pypika>=0.15.6,<1.0 | ||
ciso8601>=2.0 | ||
aiocontextvars==0.1.2;python_version<"3.7" | ||
aiosqlite>=0.6.0 | ||
aiosqlite>=0.7.0 |
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,23 +1,13 @@ | ||
from typing import List | ||
|
||
from pypika import Table | ||
|
||
from tortoise.backends.base.executor import BaseExecutor | ||
|
||
|
||
class AsyncpgExecutor(BaseExecutor): | ||
async def execute_insert(self, instance): | ||
self.connection = await self.db.get_single_connection() | ||
regular_columns = self._prepare_insert_columns() | ||
columns, values = self._prepare_insert_values( | ||
instance=instance, | ||
regular_columns=regular_columns, | ||
) | ||
|
||
query = ( | ||
def _prepare_insert_statement(self, columns: List[str]) -> str: | ||
return str( | ||
self.connection.query_class.into(Table(self.model._meta.table)).columns(*columns) | ||
.insert(*values).returning('id') | ||
) | ||
result = await self.connection.execute_query(str(query)) | ||
instance.id = result[0][0] | ||
await self.db.release_single_connection(self.connection) | ||
self.connection = None | ||
return instance | ||
.insert('???').returning('id') | ||
).replace("'???'", ','.join(['$%d' % (i + 1, ) for i in range(len(columns))])) |
Oops, something went wrong.