Skip to content

Commit 68502e2

Browse files
committed
Initial revision.
1 parent 481db84 commit 68502e2

File tree

12 files changed

+1164
-251
lines changed

12 files changed

+1164
-251
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ repos:
2727
# --remove-all-unused-imports,
2828
# --remove-unused-variables,
2929
# ]
30+
- repo: https://github.com/hadialqattan/pycln
31+
rev: v1.0.3
32+
hooks:
33+
- id: pycln
34+
args: [--config=setup.cfg]
3035

3136
- repo: https://github.com/pycqa/isort
3237
rev: 5.10.1

Pipfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
strawberry-sqlalchemy-mapper = {editable = true, path = "."}
8+
9+
[dev-packages]
10+
11+
[requires]
12+
python_version = "3.8"

Pipfile.lock

Lines changed: 206 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# strawberry-sqlalchemy-mapper
2+
3+
4+
Supplies decorators to automatically instrument strawberry types for provided SQLAlchemy models.
5+
6+
7+
Instead of manually listing every column and relationship in a SQLAlchemy model, strawberry-sqlalchemy-mapper
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.
10+
11+
## Usage
12+
13+
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:
18+
19+
```
20+
class Employee(Model):
21+
id = Column(UUID, primary_key=True)
22+
name = Column(String, nullable=False)
23+
24+
25+
# in another file
26+
strawberry_sqlalchemy_mapper = StrawberrySQLAlchemyMapper()
27+
@strawberry_sqlalchemy_mapper.type(models.Employee)
28+
class Employee:
29+
pass
30+
```
31+
32+
## Limitations
33+
34+
Natively supports the following SQLAlchemy types:
35+
36+
```
37+
Integer: int,
38+
Float: float,
39+
BigInteger: int,
40+
Numeric: Decimal,
41+
DateTime: datetime,
42+
Date: date,
43+
Time: time,
44+
String: str,
45+
Text: str,
46+
Boolean: bool,
47+
Unicode: str,
48+
UnicodeText: str,
49+
SmallInteger: int,
50+
SQLAlchemyUUID: uuid.UUID,
51+
VARCHAR: str,
52+
ARRAY[T]: List[T] # PostgreSQL array
53+
Enum: (the Python enum it is mapped to, which should be @strawberry.enum-decorated)
54+
```
55+
56+
Additional types can be supported by passing `extra_sqlalchemy_type_to_strawberry_type_map`,
57+
although support for `TypeDecorator` types is untested.
58+
59+
Association proxies are expected to be of the form `association_proxy('relationship1', 'relationship2')`,
60+
i.e., both properties are expected to be relationships.
61+
62+
63+
## Making Changes & Contributing
64+
65+
This project uses `pre-commit`_, please make sure to install it before making any
66+
changes::
67+
68+
pip install pre-commit
69+
cd strawberry-sqlalchemy-mapper
70+
pre-commit install
71+
72+
It is a good idea to update the hooks to the latest version::
73+
74+
pre-commit autoupdate
75+
76+
Don't forget to tell your contributors to also install and use pre-commit.

README.rst

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)