Skip to content

Commit

Permalink
Merge pull request #126 from tsugumi-sys/feature/adding-polygon-sqlst…
Browse files Browse the repository at this point in the history
…ores

Stores: Addigng polygon financials data of sqlstores
  • Loading branch information
tsugumi-sys authored Jun 11, 2024
2 parents ebd4c81 + fb30158 commit 97632fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions stocklake/polygonapi/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def save(
csv_file_path = os.path.join(tempdir, "financials_data.csv")
save_data_to_csv([d.dict() for d in data], csv_file_path)
repository.save_artifact(csv_file_path)
elif store_type == StoreType.POSTGRESQL:
sqlstore = PolygonFinancialsDataSQLAlchemyStore(self.sqlalchemy_session)
sqlstore.delete()
sqlstore.create(
[schemas.PolygonFinancialsDataCreate(**d.dict()) for d in data]
)
else:
raise NotImplementedError

Expand Down
11 changes: 11 additions & 0 deletions tests/polygonapi/test_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ def test_polygon_financials_store_local_artifact(
assert os.path.exists(os.path.join(SAVE_ARTIFACTS_DIR, "financials_data.csv"))


def test_polygon_financials_store_postgresql(
SessionLocal, # noqa: F811
polygon_financials_data,
):
store = PolygonFinancialsDataStore(SessionLocal)
store.save(StoreType.POSTGRESQL, polygon_financials_data)
with SessionLocal() as session, session.begin():
res = session.query(models.PolygonFinancialsData).all()
assert len(res) == 1


def test_PolygonFinancialsDataSQLAlchemyStore_create(
polygon_financials_data,
SessionLocal, # noqa: F811
Expand Down

0 comments on commit 97632fa

Please sign in to comment.