simonw / sqlite-utils

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

Documented the use of `delete_where` #630

Closed learning4life closed 5 days ago

learning4life commented 2 weeks ago

Documented the use of delete_where, as shown in https://github.com/simonw/sqlite-utils/issues/159


📚 Documentation preview 📚: https://sqlite-utils--630.org.readthedocs.build/en/630/

learning4life commented 2 weeks ago

The example below shows why this doc update is needed using sqlite-utils v3.36:

Running the code in bash using docker

[root@b5441fc4c92e DockerSqliteUtils]# sqlite-utils insert global.db power_plants 'global_power_plant_database.csv' --csv
  [###################################-]   99%  00:00:00
[root@b5441fc4c92e DockerSqliteUtils]# python3
Python 3.9.19 (main, May 20 2024, 05:19:58) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite_utils
>>> db = sqlite_utils.Database("global.db")
>>> db["power_plants"].count_where("country > ?", [1])
33643
>>> db["power_plants"].delete_where()
<Table power_plants (country, country_long, name, gppd_idnr, capacity_mw, latitude, longitude, primary_fuel, other_fuel1, other_fuel2, other_fuel3, commissioning_year, owner, source, url, geolocation_source, wepp_id, year_of_capacity_data, generation_gwh_2013, generation_gwh_2014, generation_gwh_2015, generation_gwh_2016, generation_gwh_2017, generation_data_source, estimated_generation_gwh)>
>>> db["power_plants"].count_where("country > ?", [1])
0
>>> exit()
[root@b5441fc4c92e DockerSqliteUtils]# python3
Python 3.9.19 (main, May 20 2024, 05:19:58) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite_utils
>>> db = sqlite_utils.Database("global.db")
>>> db["power_plants"].count_where("country > ?", [1])
33643
simonw commented 5 days ago

Thanks, I'll land this change but I'd like to fix this at source later on.