@polyglot-sql/sdk 0.5.2 → 0.5.4

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
@@ -347,9 +347,9 @@ Walk, search, and transform parsed AST nodes.
347
347
 
348
348
  ```typescript
349
349
  import {
350
- parse, Dialect, walk, transform, findAll, findFirst, findByType,
350
+ parse, Dialect, col, walk, transform, findAll, findFirst, findByType,
351
351
  getColumns, getColumnNames, getTableNames, renameColumns, renameTables,
352
- addWhere, removeWhere, setLimit, setDistinct, qualifyColumns,
352
+ addWhere, removeWhere, setLimit, setOffset, setOrderBy, setDistinct, qualifyColumns,
353
353
  getAggregateFunctions, hasSubqueries, nodeCount,
354
354
  } from '@polyglot-sql/sdk';
355
355
 
@@ -382,6 +382,8 @@ const qualified = qualifyColumns(ast, 'users');
382
382
 
383
383
  // Modify query structure
384
384
  const withLimit = setLimit(ast, 100);
385
+ const withOffset = setOffset(withLimit, 10);
386
+ const ordered = setOrderBy(withOffset, col('a').toJSON());
385
387
  const distinct = setDistinct(ast, true);
386
388
  const noWhere = removeWhere(ast);
387
389
  ```
@@ -608,30 +610,75 @@ lineage graph. `relations` contains sources visible in the analyzed scope;
608
610
  `baseTables` contains deduplicated physical dependencies across nested CTEs,
609
611
  derived tables, subqueries, and set-operation branches. With a schema,
610
612
  parseable detailed type strings such as `DECIMAL(10,2)` are preserved in
611
- projection `typeHint` values.
613
+ projection `typeHint` values. `cteFacts` reports top-level CTE definitions,
614
+ `starProjections` records original star projections and schema-expanded
615
+ columns, and each projection includes conservative `nullability`: `'non_null'`,
616
+ `'nullable'`, or `'unknown'`.
617
+ For physical relation facts, `name` remains the qualified display name while
618
+ `catalog`, `schema`, and `table` expose parsed identifier parts.
612
619
 
613
620
  ```typescript
614
621
  import { analyzeQuery, Dialect } from '@polyglot-sql/sdk';
615
622
 
616
- const result = analyzeQuery('SELECT SUM(o.amount) AS total FROM orders AS o', {
617
- dialect: Dialect.Generic,
618
- schema: {
619
- tables: [
620
- { name: 'orders', columns: [{ name: 'amount', type: 'DECIMAL(10,2)' }] },
621
- ],
623
+ const result = analyzeQuery(
624
+ 'WITH base AS (SELECT id, amount FROM orders) SELECT * FROM base',
625
+ {
626
+ dialect: Dialect.Generic,
627
+ schema: {
628
+ tables: [
629
+ {
630
+ name: 'orders',
631
+ columns: [
632
+ { name: 'id', type: 'INT', nullable: false },
633
+ { name: 'amount', type: 'DECIMAL(10,2)', nullable: true },
634
+ ],
635
+ },
636
+ ],
637
+ },
622
638
  },
623
- });
639
+ );
624
640
 
625
641
  if (result.success) {
626
- console.log(result.analysis.projections[0].transformKind); // 'aggregation'
627
- console.log(result.analysis.projections[0].typeHint); // 'DECIMAL(10, 2)'
628
- console.log(result.analysis.baseTables[0].name); // 'orders'
629
- console.log(result.analysis.baseTables[0].alias); // 'o'
642
+ console.log(result.analysis.cteFacts[0].bodySql); // 'SELECT id, amount FROM orders'
643
+ console.log(result.analysis.starProjections[0].expandedColumns); // ['id', 'amount']
644
+ console.log(result.analysis.projections[0].nullability); // 'non_null'
645
+ console.log(result.analysis.baseTables[0].name); // 'orders'
646
+ console.log(result.analysis.baseTables[0].table); // 'orders'
630
647
  }
631
648
 
632
649
  const duckdbSummary = analyzeQuery('SELECT 1', Dialect.DuckDB);
633
650
  ```
634
651
 
652
+ `ValidationSchema` objects use this shape:
653
+
654
+ ```typescript
655
+ const schema = {
656
+ strict: true,
657
+ tables: [
658
+ {
659
+ name: 'orders',
660
+ schema: 'analytics',
661
+ aliases: ['o'],
662
+ primaryKey: ['id'],
663
+ uniqueKeys: [['external_id']],
664
+ foreignKeys: [
665
+ {
666
+ columns: ['customer_id'],
667
+ references: { table: 'customers', columns: ['id'] },
668
+ },
669
+ ],
670
+ columns: [
671
+ { name: 'id', type: 'INT', nullable: false, primaryKey: true },
672
+ { name: 'amount', type: 'DECIMAL(10,2)', nullable: true },
673
+ ],
674
+ },
675
+ ],
676
+ };
677
+ ```
678
+
679
+ Use the `type` key for column types. `dataType` / `data_type` are not accepted
680
+ aliases in this payload.
681
+
635
682
  ## OpenLineage Output
636
683
 
637
684
  Generate OpenLineage-compatible JSON payloads from SQL analysis. The SDK only
@@ -838,6 +885,7 @@ const formattedSafe = pg.formatWithOptions('SELECT a,b FROM t', Dialect.Generic,
838
885
  | `removeSelectColumns(node, predicate)` | Remove columns from SELECT |
839
886
  | `setLimit(node, limit)` | Set LIMIT clause |
840
887
  | `setOffset(node, offset)` | Set OFFSET clause |
888
+ | `setOrderBy(node, orderBy)` | Set ORDER BY clause |
841
889
  | `removeLimitOffset(node)` | Remove LIMIT and OFFSET |
842
890
  | `setDistinct(node, distinct?)` | Set SELECT DISTINCT |
843
891
  | `clone(node)` | Deep clone AST |