SIMPLE-AstroDB / SIMPLE-db

BSD 3-Clause "New" or "Revised" License
11 stars 22 forks source link

Make ingest_utils functions more modular? [Discussion] #367

Closed kelle closed 7 months ago

kelle commented 1 year ago

I was thinking that the ingest functions all expect lists of data and then loops over them. These feels clunky. Maybe we want to make a ingest_source function which is called by ingest_sources and is also an option to the user in case they want to the do one at time. (And same for rvs, proper motions, etc.) Thoughts welcome.

dr-rodriguez commented 1 year ago

Yes, I agree with this- we should have much more object oriented modular functions.

SQLAlchemy does already provide classes that could be very useful for this. You could probably do something like:

# import the schema definition for our database
from simple import *

# connect to database as normal
from astrodbkit2.astrodb import Database
db = Database(blah)

# use the schema definition to create a source
source_1 = Sources(source='TWA 123', ra=123, dec=-456)
source_2 = Sources(source='TWA 456', ra=123, dec=-456)

# ingest to database
with db.session as session:
     session.add_all([source_1, source_2])
     session.commit()

See also https://docs.sqlalchemy.org/en/20/orm/quickstart.html#create-objects-and-persist

I haven't used the SQLAlchemy ORM very much so I don't know how well-constructed our tables are, but this should be roughly what one can do.

kelle commented 7 months ago

This is being done in the astrodb_scripts repo.