2022-05-21 20:00:02 +01:00
|
|
|
# sqlite-utils
|
|
|
|
|
|
|
|
> Command-line tool used to manipulate SQLite databases in a number of different ways.
|
|
|
|
> More information: <https://sqlite-utils.datasette.io/en/stable/cli.html>.
|
|
|
|
|
|
|
|
- Create a database:
|
|
|
|
|
|
|
|
`sqlite-utils create-database {{path/to/database.db}}`
|
|
|
|
|
|
|
|
- Create a table:
|
|
|
|
|
|
|
|
`sqlite-utils create-table {{path/to/database.db}} {{table_name}} {{id integer name text height float photo blob --pk id}}`
|
|
|
|
|
2022-06-12 22:34:55 +01:00
|
|
|
- List tables:
|
|
|
|
|
|
|
|
`sqlite-utils tables {{path/to/database.db}}`
|
|
|
|
|
2022-05-21 20:00:02 +01:00
|
|
|
- Upsert a record:
|
|
|
|
|
|
|
|
`{{echo '[ {"id": 1, "name": "Linus Torvalds"}, {"id": 2, "name": "Steve Wozniak"}, {"id": 3, "name": "Tony Hoare"} ]'}} | sqlite-utils upsert {{path/to/database.db}} {{table_name}} - {{--pk id}}`
|
|
|
|
|
|
|
|
- Select records:
|
|
|
|
|
|
|
|
`sqlite-utils rows {{path/to/database.db}} {{table_name}}`
|
|
|
|
|
|
|
|
- Delete a record:
|
|
|
|
|
|
|
|
`sqlite-utils query {{path/to/database.db}} "{{delete from table_name where name = 'Tony Hoare'}}"`
|
|
|
|
|
|
|
|
- Drop a table:
|
|
|
|
|
|
|
|
`sqlite-utils drop-table {{path/to/database.db}} {{table_name}}`
|
|
|
|
|
2023-12-27 06:41:30 +00:00
|
|
|
- Display help:
|
2022-05-21 20:00:02 +01:00
|
|
|
|
|
|
|
`sqlite-utils -h`
|