From eb80b832e2d1e40b325df80a919f659f0bdae559 Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Tue, 30 Jan 2024 10:52:48 +0000 Subject: [PATCH] docs: info on using sqlalchemy Session objects --- README.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 745977f..e02cdac 100644 --- a/README.md +++ b/README.md @@ -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, )