Skip to content

Commit

Permalink
Merge pull request #179 from Daverball/feat/sqlalchemy20
Browse files Browse the repository at this point in the history
Adds support for SQLAlchemy 2.0 `Mapped` annotations
  • Loading branch information
Daverball authored Dec 7, 2023
2 parents 9855cda + d7a40c7 commit 700cd24
Show file tree
Hide file tree
Showing 9 changed files with 534 additions and 40 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,38 @@ Enabling dependency support will also enable FastAPI and Pydantic support.
type-checking-fastapi-dependency-support-enabled = true # default false
```

### SQLAlchemy 2.0+ support

If you're using SQLAlchemy 2.0+, you can enable support.
This will treat any `Mapped[...]` types as needed at runtime.
It will also specially treat the enclosed type, since it may or may not
need to be available at runtime depending on whether or not the enclosed
type is a model or not, since models can have circular dependencies.

- **name**: `type-checking-sqlalchemy-enabled`
- **type**: `bool`
```ini
type-checking-sqlalchemy-enabled = true # default false
```

### SQLAlchemy 2.0+ support mapped dotted names

Since it's possible to create subclasses of `sqlalchemy.orm.Mapped` that
define some custom behavior for the mapped attribute, but otherwise still
behave like any other mapped attribute, i.e. the same runtime restrictions
apply it's possible to provide additional dotted names that should be treated
like subclasses of `Mapped`. By default we check for `sqlalchemy.orm.Mapped`,
`sqlalchemy.orm.DynamicMapped` and `sqlalchemy.orm.WriteOnlyMapped`.

If there's more than one import path for the same `Mapped` subclass, then you
need to specify each of them as a separate dotted name.

- **name**: `type-checking-sqlalchemy-mapped-dotted-names`
- **type**: `list`
```ini
type-checking-sqlalchemy-mapped-dotted-names = a.MyMapped, a.b.MyMapped # default []
```

### Cattrs support

If you're using the plugin in a project which uses `cattrs`,
Expand Down
Loading

0 comments on commit 700cd24

Please sign in to comment.