-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add async support starting with
aiopg
(#22)
- Loading branch information
1 parent
7fae9e6
commit 6eaa4dc
Showing
77 changed files
with
2,442 additions
and
559 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
File renamed without changes.
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,60 @@ | ||
|
||
`execute_async` can execute a command one or multiple times and return the number of affected rows. This method is usually used | ||
to execute insert, update or delete operations. | ||
|
||
## Parameters | ||
| name | type | description | optional | default | | ||
|-------|----------------------------|-----------------------------------|--------------|---------| | ||
| sql | `str` | the sql query str to execute | :thumbsdown: | | | ||
| param | `ListParamType, ParamType` | params to substitute in the query | :thumbsup: | `None` | | ||
|
||
## Example - Execute Insert | ||
### Single | ||
Execute the INSERT statement a single time. | ||
|
||
```python | ||
{!docs/../docs_src/async_methods/execute/insert_single.py!} | ||
``` | ||
(*This script is complete, it should run "as is"*) | ||
|
||
### Multiple | ||
Execute the INSERT statement multiple times, one for each object in the param list. | ||
|
||
```python | ||
{!docs/../docs_src/async_methods/execute/insert_multiple.py!} | ||
``` | ||
(*This script is complete, it should run "as is"*) | ||
|
||
## Example - Execute Update | ||
### Single | ||
Execute the UPDATE statement a single time. | ||
|
||
```python | ||
{!docs/../docs_src/async_methods/execute/update_single.py!} | ||
``` | ||
(*This script is complete, it should run "as is"*) | ||
|
||
### Multiple | ||
Execute the UPDATE statement multiple times, one for each object in the param list. | ||
|
||
```python | ||
{!docs/../docs_src/async_methods/execute/update_multiple.py!} | ||
``` | ||
(*This script is complete, it should run "as is"*) | ||
|
||
## Example - Execute Delete | ||
### Single | ||
Execute the DELETE statement a single time. | ||
|
||
```python | ||
{!docs/../docs_src/async_methods/execute/delete_single.py!} | ||
``` | ||
(*This script is complete, it should run "as is"*) | ||
|
||
### Multiple | ||
Execute the DELETE statement multiple times, one for each object in the param list. | ||
|
||
```python | ||
{!docs/../docs_src/async_methods/execute/delete_multiple.py!} | ||
``` | ||
(*This script is complete, it should run "as is"*) |
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,18 @@ | ||
|
||
`execute_scalar_async` executes the query, and returns the first column of the first row in the result set returned by | ||
the query. The additional columns or rows are ignored. | ||
|
||
|
||
## Parameters | ||
| name | type | description | optional | default | | ||
|-------|-------------|-----------------------------------|--------------|---------| | ||
| sql | `str` | the sql query str to execute | :thumbsdown: | | | ||
| param | `ParamType` | params to substitute in the query | :thumbsup: | `None` | | ||
|
||
## Example | ||
Get the name of the first task owner in the database. | ||
|
||
```python | ||
{!docs/../docs_src/async_methods/execute_scalar/example.py!} | ||
``` | ||
(*This script is complete, it should run "as is"*) |
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,35 @@ | ||
|
||
`query_async` can execute a query and serialize the results to a model. | ||
|
||
## Parameters | ||
| name | type | description | optional | default | | ||
|----------|-------------|-----------------------------------------------------------------------------------------------|--------------|---------| | ||
| sql | `str` | the sql query str to execute | :thumbsdown: | | | ||
| param | `ParamType` | params to substitute in the query | :thumbsup: | `None` | | ||
| model | `Any` | the callable to serialize the model; callable must be able to accept column names as kwargs. | :thumbsup: | `dict` | | ||
| buffered | `bool` | whether to buffer reading the results of the query | :thumbsup: | `True` | | ||
|
||
## Example - Serialize to a dataclass | ||
The raw sql query can be executed using the `query_async` method and map the results to a list of dataclasses. | ||
```python | ||
{!docs/../docs_src/async_methods/query/basic_query.py!} | ||
``` | ||
(*This script is complete, it should run "as is"*) | ||
|
||
### Example - Serialize a one to one relationship | ||
You can get creative with what you pass in to the model kwarg of `query` | ||
```python | ||
{!docs/../docs_src/async_methods/query/one_to_one_query.py!} | ||
``` | ||
(This script is complete, it should run "as is") | ||
|
||
|
||
### Example - Buffering queries | ||
By default, `query` fetches all results and stores them in a list (buffered). By setting `buffered=False`, you can | ||
instead have `query` act as a generator function, fetching one record from the result set at a time. This may be useful | ||
if querying a large amount of data that would not fit into memory, but note that this keeps both the connection and | ||
cursor open while you're retrieving results. | ||
```python | ||
{!docs/../docs_src/async_methods/query/query_unbuffered.py!} | ||
``` | ||
(This script is complete, it should run "as is") |
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,19 @@ | ||
|
||
`query_first_async` can execute a query and map the first result. | ||
|
||
## Parameters | ||
| name | type | description | optional | default | | ||
|-------|-------------|-----------------------------------------------------------------------------------------------|--------------|---------| | ||
| sql | `str` | the sql query str to execute | :thumbsdown: | | | ||
| param | `ParamType` | params to substitute in the query | :thumbsup: | `None` | | ||
| model | `Any` | the callable to serialize the model; callable must be able to accept column names as kwargs. | :thumbsup: | `dict` | | ||
|
||
## First, Single and Default | ||
{!docs/.first_single_default.md!} | ||
|
||
## Example | ||
Execute a query and map the first result to a dataclass. | ||
```python | ||
{!docs/../docs_src/async_methods/query_first/example.py!} | ||
``` | ||
(This script is complete, it should run "as is") |
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,22 @@ | ||
|
||
`query_first_or_default_async` can execute a query and serialize the first result, or return a default value if the result | ||
set contains no records. | ||
|
||
## Parameters | ||
| name | type | description | optional | default | | ||
|---------|-------------|-----------------------------------------------------------------------------------------------|--------------|---------| | ||
| sql | `str` | the sql query str to execute | :thumbsdown: | | | ||
| default | `Any` | any object to return if the result set is empty | :thumbsdown: | | ||
| param | `ParamType` | params to substitute in the query | :thumbsup: | `None` | | ||
| model | `Any` | the callable to serialize the model; callable must be able to accept column names as kwargs. | :thumbsup: | `dict` | | ||
|
||
|
||
## First, Single and Default | ||
{!docs/.first_single_default.md!} | ||
|
||
## Example | ||
Execute a query and map the first result to a dataclass. | ||
```python | ||
{!docs/../docs_src/async_methods/query_first_or_default/example.py!} | ||
``` | ||
(This script is complete, it should run "as is") |
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,17 @@ | ||
|
||
`query_multiple_async` can execute multiple queries with the same cursor and serialize the results. This method | ||
will throw a `ValueError` if you don't supply the same number of queries and models. | ||
|
||
## Parameters | ||
| name | type | description | optional | default | | ||
|-------|-------------|-----------------------------------------------------------------------------------------------|--------------|---------| | ||
| sql | `str` | the sql query str to execute | :thumbsdown: | | | ||
| param | `ParamType` | params to substitute in the query | :thumbsup: | `None` | | ||
| model | `Any` | the callable to serialize the model; callable must be able to accept column names as kwargs. | :thumbsup: | `dict` | | ||
|
||
## Example | ||
Query two tables and return the serialized results. | ||
```python | ||
{!docs/../docs_src/async_methods/query_multiple/example.py!} | ||
``` | ||
(This script is complete, it should run "as is") |
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 @@ | ||
|
||
`query_single_async` can execute a query and serialize the first result. It throws an exception if there is not exactly one | ||
record in the result set. | ||
|
||
## Parameters | ||
| name | type | description | optional | default | | ||
|-------|-------------|-----------------------------------------------------------------------------------------------|--------------|---------| | ||
| sql | `str` | the sql query str to execute | :thumbsdown: | | | ||
| param | `ParamType` | params to substitute in the query | :thumbsup: | `None` | | ||
| model | `Any` | the callable to serialize the model; callable must be able to accept column names as kwargs. | :thumbsup: | `dict` | | ||
|
||
## First, Single and Default | ||
{!docs/.first_single_default.md!} | ||
|
||
## Example | ||
Execute a query and map the first result to a dataclass. | ||
```python | ||
{!docs/../docs_src/async_methods/query_single/example.py!} | ||
``` | ||
(This script is complete, it should run "as is") |
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,22 @@ | ||
|
||
`query_single_or_default_async` can execute a query and serialize the first result, or return a default value if the result | ||
set is empty; this method throws an exception if there is more than one element in the result set. | ||
|
||
## Parameters | ||
| name | type | description | optional | default | | ||
|---------|-------------|-----------------------------------------------------------------------------------------------|--------------|---------| | ||
| sql | `str` | the sql query str to execute | :thumbsdown: | | | ||
| default | `Any` | any object to return if the result set is empty | :thumbsdown: | | ||
| param | `ParamType` | params to substitute in the query | :thumbsup: | `None` | | ||
| model | `Any` | the callable to serialize the model; callable must be able to accept column names as kwargs. | :thumbsup: | `dict` | | ||
|
||
|
||
## First, Single and Default | ||
{!docs/.first_single_default.md!} | ||
|
||
## Example | ||
Execute a query and map the result to a dataclass. | ||
```python | ||
{!docs/../docs_src/async_methods/query_single_or_default/example.py!} | ||
``` | ||
(This script is complete, it should run "as is") |
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.