Skip to content

Commit 1a418a6

Browse files
Add database session to the example
Coming from https://docs.graphene-python.org/projects/sqlalchemy/en/latest/tutorial/ as a python noob I failed to run their example but could fix this example by adding the database session.
1 parent 0544f81 commit 1a418a6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ class Query(graphene.ObjectType):
5858
schema = graphene.Schema(query=Query)
5959
```
6060

61+
We need a database session first:
62+
63+
```python
64+
from sqlalchemy import (create_engine)
65+
from sqlalchemy.orm import (scoped_session, sessionmaker)
66+
67+
engine = create_engine('sqlite:///database.sqlite3', convert_unicode=True)
68+
db_session = scoped_session(sessionmaker(autocommit=False,
69+
autoflush=False,
70+
bind=engine))
71+
```
72+
6173
Then you can simply query the schema:
6274

6375
```python

0 commit comments

Comments
 (0)