query db
for database
Query a database using SQL.
Signature
> query db {flags} (SQL)
Flags
--params, -p {any}
: List of parameters for the SQL statement
Parameters
SQL
: SQL to execute against the database.
Input/output types:
input | output |
---|---|
any | any |
Examples
Execute SQL against a SQLite database
> open foo.db | query db "SELECT * FROM Bar"
Execute a SQL statement with parameters
> stor create -t my_table -c { first: str, second: int }
stor open | query db "INSERT INTO my_table VALUES (?, ?)" -p [hello 123]
Execute a SQL statement with named parameters
> stor create -t my_table -c { first: str, second: int }
stor insert -t my_table -d { first: 'hello', second: '123' }
stor open | query db "SELECT * FROM my_table WHERE second = :search_second" -p { search_second: 123 }
╭───┬───────┬────────╮
│ # │ first │ second │
├───┼───────┼────────┤
│ 0 │ hello │ 123 │
╰───┴───────┴────────╯