add-column col_type now optional, defaults to str

This commit is contained in:
Simon Willison 2019-02-24 14:24:00 -08:00
commit 3cab079d3e
6 changed files with 18 additions and 8 deletions

View file

@ -148,6 +148,7 @@ def optimize(path, no_vacuum):
type=click.Choice(
["integer", "float", "blob", "text", "INTEGER", "FLOAT", "BLOB", "TEXT"]
),
required=False,
)
def add_column(path, table, col_name, col_type):
"Add a column to the specified table"

View file

@ -276,7 +276,9 @@ class Table:
self.db.conn.execute(sql)
return self
def add_column(self, col_name, col_type):
def add_column(self, col_name, col_type=None):
if col_type is None:
col_type = str
sql = "ALTER TABLE [{table}] ADD COLUMN [{col_name}] {col_type};".format(
table=self.name, col_name=col_name, col_type=COLUMN_TYPE_MAPPING[col_type]
)