Nushell and DuckDB
Nushell1 is an amazing shell that brings structure to terminal. Nevertheless, sometime it would be usefull to have the raw power of SQL directly into the terminal. To acheive this, the below scripts allows use duckdb2 as query engine on nushell tables.
# Query Nushell data using DuckDB SQL
#
# Parameters:
# query: string - A DuckDB SQL query that operates on the "data" table
#
# Input: Any Nushell structured data (tables, records, lists)
# Output: The query results as Nushell structured data
def nu-duck [query] {
let full_query = $"
CREATE TABLE data as
SELECT *
FROM read_json\('/dev/stdin', timestampformat='%Y-%m-%d %H:%M:%S.%n %z'\);
COPY \( ( $query ) \) TO '/dev/stdout' \(FORMAT json, array true\)"
$in | to json | duckdb -c $full_query | from json
}