Skip to content

Commit

Permalink
docs: info on using sqlalchemy Session objects
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jan 30, 2024
1 parent c03ed84 commit eb80b83
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,41 @@ split_features = split_by_sql(

- The db parameter can be a connection string to start a new connection.
- Or an existing database connection can be reused.
- To do this, the psycopg2 driver connection needs to be passed:
- To do this, either the psycopg2 connection, or a SQLAlchemy Session
must be passed:

SQLAlchemy example:

```python
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from fmtm_splitter.splitter import split_by_sql

# Creates a SQLAlchemy Session object
engine = create_engine("postgresql://postgres:postgres@localhost/postgres")
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db = SessionLocal()

psycopg2_connection = db.connection()

# Then pass this object as the db param
split_features = split_by_sql(
aoi,
psycopg2_connection,
db,
num_buildings=50,
osm_extract=osm_extracts,
)
```

psycopg2 example:

```python
import psycopg2
from fmtm_splitter.splitter import split_by_sql

db = psycopg2.connect("postgresql://postgres:postgres@localhost/postgres")

split_features = split_by_sql(
aoi,
db,
num_buildings=50,
osm_extract=osm_extracts,
)
Expand Down

0 comments on commit eb80b83

Please sign in to comment.