Project

General

Profile

« Previous | Next » 

Revision 3083

sql.py: Moved add_indexes() to Indexes subsection

View differences:

lib/sql.py
1120 1120
    
1121 1121
    return expr
1122 1122

  
1123
already_indexed = object() # tells add_indexes() the pkey has already been added
1124

  
1125
def add_indexes(db, table, has_pkey=True):
1126
    '''Adds an index on all columns in a table.
1127
    @param has_pkey bool|already_indexed Whether a pkey instead of a regular
1128
        index should be added on the first column.
1129
        * If already_indexed, the pkey is assumed to have already been added
1130
    '''
1131
    cols = table_cols(db, table)
1132
    if has_pkey:
1133
        if has_pkey is not already_indexed: add_pkey(db, table)
1134
        cols = cols[1:]
1135
    for col in cols: add_index(db, col, table)
1136

  
1123 1137
#### Tables
1124 1138

  
1125 1139
### Maintenance
......
1172 1186
    if isinstance(col_indexes, list): col_indexes[0] = add_indexes_ # defer
1173 1187
    elif col_indexes: add_indexes_() # add now
1174 1188

  
1175
already_indexed = object() # tells add_indexes() the pkey has already been added
1176

  
1177
def add_indexes(db, table, has_pkey=True):
1178
    '''Adds an index on all columns in a table.
1179
    @param has_pkey bool|already_indexed Whether a pkey instead of a regular
1180
        index should be added on the first column.
1181
        * If already_indexed, the pkey is assumed to have already been added
1182
    '''
1183
    cols = table_cols(db, table)
1184
    if has_pkey:
1185
        if has_pkey is not already_indexed: add_pkey(db, table)
1186
        cols = cols[1:]
1187
    for col in cols: add_index(db, col, table)
1188

  
1189 1189
### Data
1190 1190

  
1191 1191
def truncate(db, table, schema='public', **kw_args):

Also available in: Unified diff