← 返回命令列表

Linux command

sqlite-utils 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Import JSON into SQLite

sqlite-utils insert [database.db] [table] [data.json]

Import CSV into SQLite

sqlite-utils insert [database.db] [table] [data.csv] --csv

Query with SQL

sqlite-utils [database.db] "[SELECT * FROM table]"

Query and output as JSON

sqlite-utils [database.db] "[SELECT * FROM table]" --json

List tables

sqlite-utils tables [database.db]

Show schema

sqlite-utils schema [database.db]

Create FTS search index

sqlite-utils enable-fts [database.db] [table] [column1] [column2]

Export table to JSON

sqlite-utils rows [database.db] [table] > [data.json]

Upsert data

sqlite-utils upsert [database.db] [table] [data.json] --pk [id]

Process data from stdin

cat [data.json] | sqlite-utils memory - "[SELECT * FROM stdin]"

说明

sqlite-utils provides a CLI and Python library for working with SQLite databases. It simplifies common tasks: importing data, running queries, and managing schema. Data import handles JSON, CSV, TSV, and newline-delimited JSON. Types are inferred automatically. Primary keys and foreign keys can be specified. Existing tables are updated or replaced as configured. Querying supports SQL with multiple output formats. The memory subcommand runs queries against in-memory databases, useful for quick data processing without persistent files. Full-text search (FTS) enables fast text searching. Enable-fts creates virtual tables for specified columns. Search queries use SQLite's FTS5 syntax for relevance ranking. Table management includes creation, alteration, and inspection. Schema command shows CREATE statements. Columns can be added without recreating tables. The tool integrates well with Unix pipelines. Data flows in from curl or other tools, gets processed, and outputs to further commands.

参数

insert _DB_ _TABLE_ _FILE_
Insert data from JSON, CSV, or stdin.
rows _DB_ _TABLE_
Output rows as JSON.
tables _DB_
List tables.
schema _DB_
Show database schema.
query _DB_ _SQL_
Run SQL query.
upsert _DB_ _TABLE_ _FILE_
Insert or update data (requires --pk).
memory _SQL_
Run SQL against in-memory database (reads from files or stdin).
enable-fts _DB_ _TABLE_ _COLUMNS_
Enable full-text search.
search _DB_ _TABLE_ _QUERY_
Full-text search.
create-table _DB_ _TABLE_ _COLUMNS_
Create table with columns.
drop-table _DB_ _TABLE_
Drop table.
add-column _DB_ _TABLE_ _COL_ _TYPE_
Add column to table.
indexes _DB_ _TABLE_
List indexes.
--csv
Input is CSV.
--tsv
Input is TSV.
--nl
Input is newline-delimited JSON.
--pk _COLUMN_
Primary key column.
--json
Output as JSON.
--table
Output as table.
-c, --csv
Output as CSV.
--flatten
Flatten nested JSON objects into columns.
--batch-size _N_
Number of rows per insert batch.

FAQ

What is the sqlite-utils command used for?

sqlite-utils provides a CLI and Python library for working with SQLite databases. It simplifies common tasks: importing data, running queries, and managing schema. Data import handles JSON, CSV, TSV, and newline-delimited JSON. Types are inferred automatically. Primary keys and foreign keys can be specified. Existing tables are updated or replaced as configured. Querying supports SQL with multiple output formats. The memory subcommand runs queries against in-memory databases, useful for quick data processing without persistent files. Full-text search (FTS) enables fast text searching. Enable-fts creates virtual tables for specified columns. Search queries use SQLite's FTS5 syntax for relevance ranking. Table management includes creation, alteration, and inspection. Schema command shows CREATE statements. Columns can be added without recreating tables. The tool integrates well with Unix pipelines. Data flows in from curl or other tools, gets processed, and outputs to further commands.

How do I run a basic sqlite-utils example?

Run `sqlite-utils insert [database.db] [table] [data.json]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does insert _DB_ _TABLE_ _FILE_ do in sqlite-utils?

Insert data from JSON, CSV, or stdin.