Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added support for asyncpg as an optional engine #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hzlmn
Copy link
Contributor

@hzlmn hzlmn commented Apr 20, 2019

What do these changes do?

Closes #27

Are there changes in behavior for the user?

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> (e.g. 588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the PR
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: Fix issue with non-ascii contents in doctest text files.

{%- if cookiecutter.use_postgres == 'y' %}
from {{ cookiecutter.project_name }}.migrations import metadata
from {{ cookiecutter.project_name }}.users.tables import users
from {{cookiecutter.project_name}}.utils.common import PATH, get_config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the whole project uses {{ cookiecutter.project_name }} with indent, so don't change that, please.
In jinja2 documentation also use indents

{% for user in users %}
  <li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry autoformatting, my bad.

import asyncpg
return await asyncpg.connect(**test_config['postgres'])
{%- endif %}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that for compatibiliti with tests u should use asyncpgsa and just rewrite sa_engine some like that:

from sqlalchemy import create_engine

...

return await create_engine(dsn, echo=True, module=asyncpgsa)

what do u think?

@@ -1,8 +1,8 @@
{%- if cookiecutter.use_postgres == 'y' %}
{%- if cookiecutter.use_postgres == 'aiopg' %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types are important, so u need create types for asyncpg


from {{ cookiecutter.project_name }}.users.tables import users
__all__ = ['select_user_by_id', 'select_user_by_id_query']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -1,15 +1,16 @@
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from {{ cookiecutter.project_name }}.migrations import metadata
from {{ cookiecutter.project_name }}.users.enums import UserGender
from {{cookiecutter.project_name}}.migrations import metadata
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indents



gender_enum = postgresql.ENUM(UserGender)

dialect = postgresql.dialect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part need only for asyncpg, so use if statement

{%- endif %}


@pytest.fixture
async def client(aiohttp_client{% if cookiecutter.use_postgres == 'y' %}, tables{% endif %}):
async def client(aiohttp_client {% if cookiecutter.use_postgres != 'n' %} , tables{% endif %}):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did u add indent here? this code generate

async def client(aiohttp_client  , tables): 
   ...

right?

@CLAassistant

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Adding pg_engine flag
3 participants