Revision 2414
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
632 | 632 |
def truncate(db, table, schema='public'): |
633 | 633 |
return run_query(db, 'TRUNCATE '+qual_name(db, schema, table)+' CASCADE') |
634 | 634 |
|
635 |
##### Database structure queries |
|
636 |
|
|
637 |
def table_cols(db, table, recover=None): |
|
638 |
return list(col_names(select(db, table, limit=0, order_by=None, |
|
639 |
recover=recover))) |
|
640 |
|
|
641 | 635 |
def mk_flatten_mapping(db, into, cols, preserve=[], as_items=False): |
642 | 636 |
'''Creates a mapping from original column names (which may have collisions) |
643 | 637 |
to names that will be distinct among the given tables. |
... | ... | |
677 | 671 |
into=into) |
678 | 672 |
return dict(items) |
679 | 673 |
|
674 |
##### Database structure queries |
|
675 |
|
|
676 |
def table_cols(db, table, recover=None): |
|
677 |
return list(col_names(select(db, table, limit=0, order_by=None, |
|
678 |
recover=recover))) |
|
679 |
|
|
680 | 680 |
def pkey(db, table, recover=None): |
681 | 681 |
'''Assumed to be first column in table''' |
682 | 682 |
return table_cols(db, table, recover)[0] |
Also available in: Unified diff
sql.py: Moved mk_flatten_mapping(), flatten() to Basic queries section since they don't involve database structure info