simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.67k stars 111 forks source link

column_names #497

Closed chapmanjacobd closed 2 years ago

chapmanjacobd commented 2 years ago

It would be nice to have a column_names. Similar to table_names.

Or if you could get one or all of the following syntax to work for both Database and Table that might be even better:

Style 1

Style 2

maybe the table ones actually work but I'm too lazy to check. I just know that I have to do:

[c.name for c in db['table1'].columns]

Edit: This is possible with columns_dict. I have actually used that before but I forgot about it. Feel free to close, but I do think accessing this data could be more consistent and intuitive.

simonw commented 2 years ago

Yeah, table.columns and table.columns_dict are meant to handle this: https://sqlite-utils.datasette.io/en/stable/python-api.html#columns