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

@ -232,9 +232,12 @@ You can add a new column to a table using the ``.add_column(col_name, col_type)`
db["dogs"].add_column("weight", float)
db["dogs"].add_column("dob", datetime.date)
db["dogs"].add_column("image", "BLOB")
db["dogs"].add_column("website") # str by default
You can specify the ``col_type`` argument either using a SQLite type as a string, or by directly passing a Python type e.g. ``str`` or ``float``.
The ``col_type`` is optional - if you omit it the type of ``TEXT`` will be used.
SQLite types you can specify are ``"TEXT"``, ``"INTEGER"``, ``"FLOAT"`` or ``"BLOB"``.
If you pass a Python type, it will be mapped to SQLite types as shown here::