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

[DEV-6105] sqlalchemy2 #37

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ on:

jobs:
tests:
name: "Python ${{ matrix.python-version }}"
name: "Python ${{ matrix.python-version }} SQLAlchemy2 ${{ matrix.sqlalchemy2 }}"
if: "!contains(github.event.head_commit.message, 'Bump version') || github.event_name != 'push'"
runs-on: ubuntu-22.04

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

sqlalchemy2: [true, false]
services:
mysql:
image: mysql:5.7
Expand Down Expand Up @@ -46,6 +46,9 @@ jobs:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: "scripts/install"
- name: "Install SQLAlchemy 2"
if: ${{ matrix.sqlalchemy2 }}
run: pip install sqlalchemy==2.0.5
- name: "Run linting checks"
run: "scripts/check"
- name: "Build package & docs"
Expand All @@ -59,7 +62,6 @@ jobs:
mysql+aiomysql://username:password@localhost:3306/testsuite,
mysql+asyncmy://username:password@localhost:3306/testsuite,
postgresql://username:password@localhost:5432/testsuite,
postgresql+aiopg://username:[email protected]:5432/testsuite,
postgresql+asyncpg://username:password@localhost:5432/testsuite
run: "scripts/test"
bump_version:
Expand All @@ -84,4 +86,4 @@ jobs:
commit_name: Groundskeeper Willie
commit_email: [email protected]
login: gkwillie
token: ${{ secrets.GKWILLIE_TOKEN }}
token: ${{ secrets.GKWILLIE_TOKEN }}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ Default driver support is provided using one of [asyncpg][asyncpg], [aiomysql][a

You can also use other database drivers supported by `morcilla`:

```shel
$ pip install morcilla[postgresql+aiopg]
```shell
$ pip install morcilla[mysql+asyncmy]
```

Expand Down
3 changes: 1 addition & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Default driver support is provided using one of [asyncpg][asyncpg], [aiomysql][a

You can also use other database drivers supported by `databases`:

```shel
$ pip install databases[postgresql+aiopg]
```shell
$ pip install databases[mysql+asyncmy]
```

Expand Down
281 changes: 0 additions & 281 deletions morcilla/backends/aiopg.py

This file was deleted.

11 changes: 3 additions & 8 deletions morcilla/backends/asyncpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import asyncpg
from sqlalchemy import text
from sqlalchemy.dialects.postgresql import hstore, pypostgresql
from sqlalchemy.dialects.postgresql import psycopg2
from sqlalchemy.dialects.postgresql.hstore import hstore
from sqlalchemy.engine.interfaces import Dialect
from sqlalchemy.sql import ClauseElement
from sqlalchemy.sql.ddl import DDLElement
Expand Down Expand Up @@ -88,16 +89,10 @@ def __init__(
self._pool = None

def _get_dialect(self) -> Dialect:
dialect = pypostgresql.dialect(paramstyle="pyformat")

dialect = psycopg2.dialect()
dialect.implicit_returning = True
dialect.supports_native_enum = True
dialect.supports_smallserial = True # 9.2+
dialect._backslash_escapes = False
dialect.supports_sane_multi_rowcount = True # psycopg 2.0.9+
dialect._has_native_hstore = True
dialect.supports_native_decimal = True

return dialect

def _get_connection_kwargs(self) -> dict:
Expand Down
3 changes: 3 additions & 0 deletions morcilla/backends/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def __getitem__(self, key: typing.Any) -> typing.Any:
return getattr(self, key)
return super().__getitem__(key)

def keys(self) -> typing.Iterable[str]:
return self._parent.keys


class SQLiteConnection(ConnectionBackend):
def __init__(
Expand Down
2 changes: 0 additions & 2 deletions morcilla/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import contextlib
import contextvars as contextvars
import functools
import logging
import typing
Expand Down Expand Up @@ -43,7 +42,6 @@
class Database:
SUPPORTED_BACKENDS = {
"postgresql": "morcilla.backends.asyncpg:PostgresBackend",
"postgresql+aiopg": "morcilla.backends.aiopg:AiopgBackend",
"mysql": "morcilla.backends.mysql:MySQLBackend",
"mysql+asyncmy": "morcilla.backends.asyncmy:AsyncMyBackend",
"sqlite": "morcilla.backends.sqlite:SQLiteBackend",
Expand Down
Loading