Project

General

Profile

« Previous | Next » 

Revision 2935

sql.py: add_col(): Support additional run_query() kw_args. add_row_num(): Use new add_col().

View differences:

sql.py
1005 1005
        cols = cols[1:]
1006 1006
    for col in cols: add_index(db, col, table)
1007 1007

  
1008
def add_col(db, table, col):
1008
def add_col(db, table, col, **kw_args):
1009 1009
    assert isinstance(col, sql_gen.TypedCol)
1010
    run_query(db, 'ALTER TABLE '+table.to_str(db)+' ADD COLUMN '+col.to_str(db))
1010
    run_query(db, 'ALTER TABLE '+table.to_str(db)+' ADD COLUMN '+col.to_str(db),
1011
        **kw_args)
1011 1012

  
1013
row_num_typed_col = sql_gen.TypedCol(row_num_col, 'serial', nullable=False,
1014
    constraints='PRIMARY KEY')
1015

  
1012 1016
def add_row_num(db, table):
1013 1017
    '''Adds a row number column to a table. Its name is in row_num_col. It will
1014 1018
    be the primary key.'''
1015
    table = sql_gen.as_Table(table).to_str(db)
1016
    run_query(db, 'ALTER TABLE '+table+' ADD COLUMN '+row_num_col
1017
        +' serial NOT NULL PRIMARY KEY', log_level=3)
1019
    add_col(db, table, row_num_typed_col, log_level=3)
1018 1020

  
1019 1021
def drop_table(db, table):
1020 1022
    table = sql_gen.as_Table(table)

Also available in: Unified diff