ONCdb / ONCdbWeb

A Web Application to serve the ONCdb
MIT License
0 stars 0 forks source link

Replace lookup table ids with name #34

Open hover2pi opened 6 years ago

hover2pi commented 6 years ago

Instead of displaying telescope_id=1 for a photometry record, replace it with telescopes.name so that it says telescope_id=HST

hover2pi commented 6 years ago

Perhaps make a set of VIEWS like so:

for table in db.query("select name from sqlite_master where type='table'")['name']:
    colnames = db.query("pragma table_info('{}')".format(table))['name']
    view = "CREATE VIEW {0}_ AS SELECT {1} from {0}".format(table,','.join(colnames))
    for col in ['telescope_id','system_id','mode_id','instrument_id']:
        tab = col.split('_')[0]
        query = "(SELECT name FROM {0}s WHERE id={1}.{2}) as {0}".format(tab,table,col)
        view = view.replace(col,query)
    print(view)

Then query in the normal fashion:

SELECT * FROM photometry_ WHERE band='WISE.W1'