|
1 | 1 | # strawberry-sqlalchemy-mapper
|
2 | 2 |
|
3 | 3 |
|
4 |
| - Supplies decorators to automatically instrument strawberry types for provided SQLAlchemy models. |
| 4 | +Strawberry-sqlalchemy-mapper is the simplest way to implement autogenerated strawberry types for columns and relationships in SQLAlchemy models. |
5 | 5 |
|
6 | 6 |
|
7 |
| -Instead of manually listing every column and relationship in a SQLAlchemy model, strawberry-sqlalchemy-mapper |
| 7 | +- Instead of manually listing every column and relationship in a SQLAlchemy model, strawberry-sqlalchemy-mapper |
8 | 8 | lets you decorate a class declaration and it will automatically generate the necessary strawberry fields
|
9 |
| -for all columns and relationships (subject to the limitations below) in the given model. |
| 9 | +for all columns and relationships in the given model. |
10 | 10 |
|
11 |
| -## Usage |
| 11 | +- Native support for most of SQLAlchemy's most common types. |
12 | 12 |
|
| 13 | +- Extensible to arbitrary custom SQLAlchemy types. |
| 14 | + |
| 15 | +- Support for SQLAlchemy 1.x and 2.x |
13 | 16 |
|
14 |
| -Decorate a type with `strawberry_sqlalchemy_mapper.type()` |
15 |
| -to register it as a strawberry type for the given SQLAlchemy model. |
16 |
| -This will automatically add fields for the model's columns, relationships, association proxies, |
17 |
| -and hybrid properties. For example: |
| 17 | + |
| 18 | +## Getting Started |
| 19 | + |
| 20 | +First, define your sqlalchemy model: |
18 | 21 |
|
19 | 22 | ```
|
20 |
| -class Employee(Model): |
| 23 | +# models.py |
| 24 | +from sqlalchemy import Column, Integer, String |
| 25 | +from sqlalchemy.ext.declarative import declarative_base |
| 26 | +
|
| 27 | +Base = declarative_base() |
| 28 | +
|
| 29 | +class Employee(Base): |
| 30 | + __tablename__ = 'employee' |
21 | 31 | id = Column(UUID, primary_key=True)
|
22 | 32 | name = Column(String, nullable=False)
|
| 33 | +``` |
23 | 34 |
|
| 35 | +Next, decorate a type with `strawberry_sqlalchemy_mapper.type()` |
| 36 | +to register it as a strawberry type for the given SQLAlchemy model. |
| 37 | +This will automatically add fields for the model's columns, relationships, association proxies, |
| 38 | +and hybrid properties. For example: |
24 | 39 |
|
| 40 | +``` |
25 | 41 | # in another file
|
26 | 42 | strawberry_sqlalchemy_mapper = StrawberrySQLAlchemyMapper()
|
27 | 43 | @strawberry_sqlalchemy_mapper.type(models.Employee)
|
@@ -60,7 +76,7 @@ Association proxies are expected to be of the form `association_proxy('relations
|
60 | 76 | i.e., both properties are expected to be relationships.
|
61 | 77 |
|
62 | 78 |
|
63 |
| -## Making Changes & Contributing |
| 79 | +## Contributing |
64 | 80 |
|
65 | 81 | This project uses `pre-commit`_, please make sure to install it before making any
|
66 | 82 | changes::
|
|
0 commit comments