@polyglot-sql/sdk 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,6 +51,25 @@ const { sql } = generate(ast, Dialect.PostgreSQL);
51
51
  console.log(sql[0]); // SELECT 1 + 2
52
52
  ```
53
53
 
54
+ ### Data Types
55
+
56
+ Parse and render standalone SQL data type fragments without wrapping them in a
57
+ statement.
58
+
59
+ ```typescript
60
+ import {
61
+ parseDataType,
62
+ generateDataType,
63
+ Dialect,
64
+ } from '@polyglot-sql/sdk';
65
+
66
+ const parsed = parseDataType('DECIMAL(10, 2)', Dialect.DuckDB);
67
+ if (parsed.success) {
68
+ const rendered = generateDataType(parsed.dataType, Dialect.PostgreSQL);
69
+ console.log(rendered.sql); // DECIMAL(10, 2)
70
+ }
71
+ ```
72
+
54
73
  ### Format
55
74
 
56
75
  ```typescript
@@ -582,6 +601,29 @@ columns are marked as `table`, CTEs as `cte`, derived queries as
582
601
  `derived_table`, and virtual sources such as BigQuery `UNNEST(...) AS alias`
583
602
  are marked as `virtual`.
584
603
 
604
+ ## Compact Query Analysis
605
+
606
+ Use `analyzeQuery` when you need summary facts instead of the full AST or full
607
+ lineage graph:
608
+
609
+ ```typescript
610
+ import { analyzeQuery, Dialect } from '@polyglot-sql/sdk';
611
+
612
+ const result = analyzeQuery('SELECT CAST(total AS TEXT) AS total_text FROM orders', {
613
+ dialect: Dialect.Generic,
614
+ schema: {
615
+ tables: [
616
+ { name: 'orders', columns: [{ name: 'total', type: 'INT' }] },
617
+ ],
618
+ },
619
+ });
620
+
621
+ if (result.success) {
622
+ console.log(result.analysis.projections[0].transformKind); // 'cast'
623
+ console.log(result.analysis.relations[0].name); // 'orders'
624
+ }
625
+ ```
626
+
585
627
  ## OpenLineage Output
586
628
 
587
629
  Generate OpenLineage-compatible JSON payloads from SQL analysis. The SDK only
@@ -668,6 +710,7 @@ import { Polyglot, Dialect } from '@polyglot-sql/sdk';
668
710
  const pg = Polyglot.getInstance();
669
711
  const result = pg.transpile('SELECT 1', Dialect.MySQL, Dialect.PostgreSQL);
670
712
  const formatted = pg.format('SELECT a,b FROM t');
713
+ const dataType = pg.parseDataType('VARCHAR(255)', Dialect.DuckDB);
671
714
  const formattedSafe = pg.formatWithOptions('SELECT a,b FROM t', Dialect.Generic, {
672
715
  maxInputBytes: 2 * 1024 * 1024,
673
716
  maxSetOpChain: 128,
@@ -683,6 +726,8 @@ const formattedSafe = pg.formatWithOptions('SELECT a,b FROM t', Dialect.Generic,
683
726
  | `transpile(sql, read, write, options?)` | Transpile SQL between dialects |
684
727
  | `parse(sql, dialect?)` | Parse SQL into AST |
685
728
  | `generate(ast, dialect?)` | Generate SQL from AST |
729
+ | `parseDataType(sql, dialect?)` | Parse one standalone SQL data type |
730
+ | `generateDataType(dataType, dialect?)` | Generate SQL from a parsed data type |
686
731
  | `format(sql, dialect?)` | Pretty-print SQL |
687
732
  | `formatWithOptions(sql, dialect?, options?)` | Pretty-print SQL with guard overrides |
688
733
  | `tokenize(sql, dialect?)` | Tokenize SQL into a token stream with source spans |
@@ -698,6 +743,7 @@ const formattedSafe = pg.formatWithOptions('SELECT a,b FROM t', Dialect.Generic,
698
743
  | `lineage(column, sql, dialect?, trimSelects?)` | Trace column lineage through a query |
699
744
  | `lineageWithSchema(column, sql, schema, dialect?, trimSelects?)` | Trace lineage with schema-based qualification |
700
745
  | `getSourceTables(column, sql, dialect?)` | Get source tables for a column |
746
+ | `analyzeQuery(sql, options?)` | Return compact projection, relation, CTE, set-operation, and upstream-reference facts |
701
747
  | `openLineageColumnLineage(sql, options)` | Build an OpenLineage columnLineage facet and datasets |
702
748
  | `openLineageJobEvent(sql, options)` | Build an OpenLineage JobEvent payload |
703
749
  | `openLineageRunEvent(sql, options)` | Build an OpenLineage RunEvent payload |