| 1 |
""" |
| 2 |
Handling table metadata in the dc.(table|column)meta tables. |
| 3 |
|
| 4 |
This has been a mediocre plan, and it's almost unused these days except |
| 5 |
to locate RDs for tables. Hence, we should tear this entire thing down |
| 6 |
and have the table->RD mapping stowed somewhere else. |
| 7 |
|
| 8 |
Or at least give up on the extra connection and have the clients use |
| 9 |
base.getTableDefForTable(connection, tableName) directly. |
| 10 |
""" |
| 11 |
|
| 12 |
#c Copyright 2008-2025, the GAVO project <[email protected]> |
| 13 |
#c |
| 14 |
#c This program is free software, covered by the GNU GPL. See the |
| 15 |
#c COPYING file in the source distribution. |
| 16 |
|
| 17 |
|
| 18 |
from gavo import base |
| 19 |
|
| 20 |
|
| 21 |
class MetaTableHandler: |
| 22 |
"""an interface to DaCHS meta tables. |
| 23 |
|
| 24 |
This used to be a fairly complex interface to all sorts for DC-related |
| 25 |
metadata. These day, the only thing it does is figure out where |
| 26 |
table definitions reside and which are available for ADQL. This thing |
| 27 |
has been a bad idea all around. |
| 28 |
|
| 29 |
Though you can construct MetaTableHandlers of your own, you should |
| 30 |
use base.caches.getMTH(None) when reading. |
| 31 |
""" |
| 32 |
def __init__(self): |
| 33 |
self.rd = base.caches.getRD("__system__/dc_tables") |
| 34 |
|
| 35 |
def getTableDefForTable(self, tableName): |
| 36 |
"""returns a TableDef for tableName. |
| 37 |
|
| 38 |
As it is not a priori clear which RD a given table lives in, |
| 39 |
this goes through dc.tablemeta to figure this out. The |
| 40 |
object comes from the actual RD, though, so this might very well |
| 41 |
trigger database action and RD loading. |
| 42 |
""" |
| 43 |
with base.getTableConn() as conn: |
| 44 |
return base.getTableDefForTable(conn, tableName) |
| 45 |
|
| 46 |
def getTAPTables(self): |
| 47 |
"""returns a list of all names of tables accessible through TAP in |
| 48 |
this data center. |
| 49 |
""" |
| 50 |
with base.getTableConn() as conn: |
| 51 |
return [r["tablename"] for r in |
| 52 |
conn.queryToDicts( |
| 53 |
"select tablename from dc.tablemeta where adql")] |
| 54 |
|
| 55 |
|
| 56 |
def _getMetaTable(ignored): |
| 57 |
return MetaTableHandler() |
| 58 |
|
| 59 |
base.caches.makeCache("getMTH", _getMetaTable) |