pub fn column_defs(create_sql: &str) -> Option<Vec<(String, String)>>Expand description
Best-effort extraction of (column_name, declared_type) for each column
declared in a CREATE TABLE statement, without a SQL-parser dependency.
Algorithm (deliberately conservative — wrong names are worse than no names):
- Take the outermost parenthesized list (first
(to its matching), tracking nesting and skipping over'…',"…",`…`, and[…]so a comma or paren inside a string/identifier/CHECK(...)never splits). - Split that list on top-level commas (depth 0).
- For each part, read the first identifier — handling
"quoted",`backtick`,[bracketed], and bare names. Skip a part whose first word is a table-level constraint keyword (CONSTRAINT,PRIMARY,UNIQUE,CHECK,FOREIGN,KEY) — those declare constraints, not columns. - The remaining tokens of the part (up to the next top-level comma) form the declared type; an empty remainder is no declared type.
Returns None when no parenthesized list is found or no column survives —
the low-confidence signal the caller turns into a c0..cN fallback.