Description
Add a --schema flag that prints the CREATE TABLE statement that sql-pipe inferred from the input data, without executing a query.
cat data.csv | sql-pipe --schema
# CREATE TABLE "t" (
# "id" INTEGER,
# "name" TEXT,
# "amount" REAL,
# "date" TEXT
# );
# With file arguments:
sql-pipe orders.csv customers.csv --schema
# CREATE TABLE "orders" (...)
# CREATE TABLE "customers" (...)
Motivation
Users frequently need to understand what sql-pipe "sees" from their data. Currently --columns --verbose shows types, but DDL output is more precise and allows users to understand affinity, see the exact schema, and even copy it into a persistent database. Especially useful for debugging type inference issues (e.g., why a column was detected as TEXT instead of INTEGER).
Acceptance Criteria
Implementation Notes
- Add
SchemaArgs to src/args.zig following the pattern of ColumnsArgs/ValidateArgs
- The existing
getTableColumns function in src/sqlite.zig (line 277) already knows how to query PRAGMA table_info
- The DDL query is trivially added:
SELECT sql FROM sqlite_master WHERE type='table' AND name='<table>'
Description
Add a
--schemaflag that prints theCREATE TABLEstatement that sql-pipe inferred from the input data, without executing a query.Motivation
Users frequently need to understand what sql-pipe "sees" from their data. Currently
--columns --verboseshows types, but DDL output is more precise and allows users to understand affinity, see the exact schema, and even copy it into a persistent database. Especially useful for debugging type inference issues (e.g., why a column was detected as TEXT instead of INTEGER).Acceptance Criteria
--schemaflag is parsed inargs.zigSELECT sql FROM sqlite_master WHERE type='table'and print each row--schemais mutually exclusive with--columns,--validate,--sample,--stats,--explain, and a query argumentImplementation Notes
SchemaArgstosrc/args.zigfollowing the pattern ofColumnsArgs/ValidateArgsgetTableColumnsfunction insrc/sqlite.zig(line 277) already knows how to queryPRAGMA table_infoSELECT sql FROM sqlite_master WHERE type='table' AND name='<table>'