astrodbtoolkit / astrodbtoolkit/astrodb_utils

Write helper function to check for values

Open
#35 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
0
Forks
10
PR merge metrics
No merged PRs in 30d

Description

A lot of the ingest scripts contain similar code to look to see if values already exist in the database. (e.g., telescope, instrument, filter, etc.) I think we could use a helper function here. Something like this
```python
def in_database(db, value, table, field):
match = (
db.query(db.table)
.filter(db.table.c.field == value)
.table()
)

if len(match) == 0:
msg = f"Value {value} not found in {table} table."
return false
else
return true
```

I'm not exactly sure how to compose the pointers in the query (`f"db.{table}.c.{field}`?) but I think the answer is in here: https://docs.sqlalchemy.org/en/20/faq/sqlexpressions.html

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.