Skip to content

Commit 88bd372

Browse files
committed
str, int, bytes aliases for column types, closes #606
1 parent 9286c1b commit 88bd372

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

docs/cli-reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ See :ref:`cli_add_column`.
11571157
::
11581158

11591159
Usage: sqlite-utils add-column [OPTIONS] PATH TABLE COL_NAME
1160-
[[integer|float|blob|text|INTEGER|FLOAT|BLOB|TEXT]]
1160+
[[integer|int|float|text|str|blob|bytes]]
11611161

11621162
Add a column to the specified table
11631163

docs/cli.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,14 @@ You can add a column using the ``add-column`` command:
23102310
23112311
sqlite-utils add-column mydb.db mytable nameofcolumn text
23122312
2313-
The last argument here is the type of the column to be created. You can use one of ``text``, ``integer``, ``float`` or ``blob``. If you leave it off, ``text`` will be used.
2313+
The last argument here is the type of the column to be created. This can be one of:
2314+
2315+
- ``text`` or ``str``
2316+
- ``integer`` or ``int``
2317+
- ``float``
2318+
- ``blob`` or ``bytes``
2319+
2320+
This argument is optional and defaults to ``text``.
23142321

23152322
You can add a column that is a foreign key reference to another table using the ``--fk`` option:
23162323

sqlite_utils/cli.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
maximize_csv_field_size_limit()
6161

6262

63+
class CaseInsensitiveChoice(click.Choice):
64+
def __init__(self, choices):
65+
super().__init__([choice.lower() for choice in choices])
66+
67+
def convert(self, value, param, ctx):
68+
return super().convert(value.lower(), param, ctx)
69+
70+
6371
def output_options(fn):
6472
for decorator in reversed(
6573
(
@@ -412,7 +420,8 @@ def dump(path, load_extension):
412420
@click.argument(
413421
"col_type",
414422
type=click.Choice(
415-
["integer", "float", "blob", "text", "INTEGER", "FLOAT", "BLOB", "TEXT"]
423+
["integer", "int", "float", "text", "str", "blob", "bytes"],
424+
case_sensitive=False,
416425
),
417426
required=False,
418427
)

sqlite_utils/db.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,12 @@ class Default:
197197
"FLOAT": "FLOAT",
198198
"BLOB": "BLOB",
199199
"text": "TEXT",
200+
"str": "TEXT",
200201
"integer": "INTEGER",
202+
"int": "INTEGER",
201203
"float": "FLOAT",
202204
"blob": "BLOB",
205+
"bytes": "BLOB",
203206
}
204207
# If numpy is available, add more types
205208
if np:

tests/test_cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,23 @@ def test_create_index_desc(db_path):
272272
"col_name,col_type,expected_schema",
273273
(
274274
("text", "TEXT", "CREATE TABLE [dogs] (\n [name] TEXT\n, [text] TEXT)"),
275+
("text", "str", "CREATE TABLE [dogs] (\n [name] TEXT\n, [text] TEXT)"),
276+
("text", "STR", "CREATE TABLE [dogs] (\n [name] TEXT\n, [text] TEXT)"),
275277
(
276278
"integer",
277279
"INTEGER",
278280
"CREATE TABLE [dogs] (\n [name] TEXT\n, [integer] INTEGER)",
279281
),
282+
(
283+
"integer",
284+
"int",
285+
"CREATE TABLE [dogs] (\n [name] TEXT\n, [integer] INTEGER)",
286+
),
280287
("float", "FLOAT", "CREATE TABLE [dogs] (\n [name] TEXT\n, [float] FLOAT)"),
281288
("blob", "blob", "CREATE TABLE [dogs] (\n [name] TEXT\n, [blob] BLOB)"),
289+
("blob", "BLOB", "CREATE TABLE [dogs] (\n [name] TEXT\n, [blob] BLOB)"),
290+
("blob", "bytes", "CREATE TABLE [dogs] (\n [name] TEXT\n, [blob] BLOB)"),
291+
("blob", "BYTES", "CREATE TABLE [dogs] (\n [name] TEXT\n, [blob] BLOB)"),
282292
("default", None, "CREATE TABLE [dogs] (\n [name] TEXT\n, [default] TEXT)"),
283293
),
284294
)

0 commit comments

Comments
 (0)