Debian Codegraph @

gavo/rsc/tables.py

raw
1 """
2 Common interface to table implementations.
3 """
4
5 #c Copyright 2008-2025, the GAVO project <[email protected]>
6 #c
7 #c This program is free software, covered by the GNU GPL. See the
8 #c COPYING file in the source distribution.
9
10
11 from gavo.rsc import common
12 from gavo.rsc import dbtable
13 from gavo.rsc import table
14
15
16 def TableForDef(tableDef, suppressIndex=False,
17 parseOptions=common.parseNonValidating, **kwargs):
18 """returns a table instance suitable for holding data described by
19 tableDef.
20
21 This is the main interface to table instancation.
22
23 suppressIndex=True can be used to suppress index generation on
24 in-memory tables with primary keys. Use it when you are sure
25 you will not need the index (e.g., if staging an on-disk table).
26
27 See the `function getParseOptions`_ for what you can pass in as
28 ``parseOptions``; arguments there can also be used here.
29 """
30 if tableDef.onDisk:
31 if tableDef.viewStatement:
32 cls = dbtable.View
33 else:
34 cls = dbtable.DBTable
35 return cls(tableDef, suppressIndex=suppressIndex,
36 validateRows=parseOptions.validateRows,
37 commitAfterMeta=parseOptions.commitAfterMeta,
38 tableUpdates=parseOptions.doTableUpdates, **kwargs)
39 elif tableDef.dupePolicy:
40 return table.UniqueForcedTable(tableDef,
41 validateRows=parseOptions.validateRows, **kwargs)
42 elif tableDef.primary and not suppressIndex:
43 return table.InMemoryIndexedTable(tableDef,
44 validateRows=parseOptions.validateRows, **kwargs)
45 else:
46 return table.InMemoryTable(tableDef, validateRows=parseOptions.validateRows,
47 **kwargs)