sqlingo 0.8.0
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/CHANGELOG.md +242 -0
- package/COPYRIGHT_NOTICE +31 -0
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/README.npm.md +189 -0
- package/README.repo.md +132 -0
- package/dist/chunk-3OVM5ZRR.js +2 -0
- package/dist/chunk-3OVM5ZRR.js.map +1 -0
- package/dist/chunk-457OPBHX.js +2 -0
- package/dist/chunk-457OPBHX.js.map +1 -0
- package/dist/chunk-47UFIVIO.cjs +2 -0
- package/dist/chunk-47UFIVIO.cjs.map +1 -0
- package/dist/chunk-5E2DDDMJ.cjs +2 -0
- package/dist/chunk-5E2DDDMJ.cjs.map +1 -0
- package/dist/chunk-5JXGMU6K.js +2 -0
- package/dist/chunk-5JXGMU6K.js.map +1 -0
- package/dist/chunk-6EWE2PXX.cjs +2 -0
- package/dist/chunk-6EWE2PXX.cjs.map +1 -0
- package/dist/chunk-AKDNSOG6.js +2 -0
- package/dist/chunk-AKDNSOG6.js.map +1 -0
- package/dist/chunk-AYV6C6YU.cjs +19 -0
- package/dist/chunk-AYV6C6YU.cjs.map +1 -0
- package/dist/chunk-C4ZR72YB.cjs +3 -0
- package/dist/chunk-C4ZR72YB.cjs.map +1 -0
- package/dist/chunk-DGV6NM76.js +2 -0
- package/dist/chunk-DGV6NM76.js.map +1 -0
- package/dist/chunk-DW3ISHFW.js +3 -0
- package/dist/chunk-DW3ISHFW.js.map +1 -0
- package/dist/chunk-FCFBBB5S.cjs +2 -0
- package/dist/chunk-FCFBBB5S.cjs.map +1 -0
- package/dist/chunk-FYYDDWAY.cjs +2 -0
- package/dist/chunk-FYYDDWAY.cjs.map +1 -0
- package/dist/chunk-GFWBSTYA.js +2 -0
- package/dist/chunk-GFWBSTYA.js.map +1 -0
- package/dist/chunk-HQEUEZZE.cjs +2 -0
- package/dist/chunk-HQEUEZZE.cjs.map +1 -0
- package/dist/chunk-I36ZOBUW.cjs +2 -0
- package/dist/chunk-I36ZOBUW.cjs.map +1 -0
- package/dist/chunk-KNRQDMQ7.js +4 -0
- package/dist/chunk-KNRQDMQ7.js.map +1 -0
- package/dist/chunk-KYKSQHLH.cjs +2 -0
- package/dist/chunk-KYKSQHLH.cjs.map +1 -0
- package/dist/chunk-KZSNUA4U.js +2 -0
- package/dist/chunk-KZSNUA4U.js.map +1 -0
- package/dist/chunk-LDIWFKFA.cjs +2 -0
- package/dist/chunk-LDIWFKFA.cjs.map +1 -0
- package/dist/chunk-NBRX75ID.js +2 -0
- package/dist/chunk-NBRX75ID.js.map +1 -0
- package/dist/chunk-NKPY5IG3.js +2 -0
- package/dist/chunk-NKPY5IG3.js.map +1 -0
- package/dist/chunk-NMAMNFRD.js +2 -0
- package/dist/chunk-NMAMNFRD.js.map +1 -0
- package/dist/chunk-O4K6VGOH.cjs +2 -0
- package/dist/chunk-O4K6VGOH.cjs.map +1 -0
- package/dist/chunk-OGPS63WZ.cjs +2 -0
- package/dist/chunk-OGPS63WZ.cjs.map +1 -0
- package/dist/chunk-OOA5D6BW.cjs +2 -0
- package/dist/chunk-OOA5D6BW.cjs.map +1 -0
- package/dist/chunk-PC37XGLS.js +2 -0
- package/dist/chunk-PC37XGLS.js.map +1 -0
- package/dist/chunk-PGKNO72J.js +2 -0
- package/dist/chunk-PGKNO72J.js.map +1 -0
- package/dist/chunk-PVJGPE3V.cjs +2 -0
- package/dist/chunk-PVJGPE3V.cjs.map +1 -0
- package/dist/chunk-QEXGYHWM.cjs +2 -0
- package/dist/chunk-QEXGYHWM.cjs.map +1 -0
- package/dist/chunk-QWCG55SR.js +2 -0
- package/dist/chunk-QWCG55SR.js.map +1 -0
- package/dist/chunk-R2XOYY2B.js +2 -0
- package/dist/chunk-R2XOYY2B.js.map +1 -0
- package/dist/chunk-RGKTYIN3.js +19 -0
- package/dist/chunk-RGKTYIN3.js.map +1 -0
- package/dist/chunk-SPWMHIMC.js +2 -0
- package/dist/chunk-SPWMHIMC.js.map +1 -0
- package/dist/chunk-UMJ6E4XD.cjs +4 -0
- package/dist/chunk-UMJ6E4XD.cjs.map +1 -0
- package/dist/chunk-USYIWEPI.cjs +2 -0
- package/dist/chunk-USYIWEPI.cjs.map +1 -0
- package/dist/chunk-WRG5B5DZ.js +2 -0
- package/dist/chunk-WRG5B5DZ.js.map +1 -0
- package/dist/chunk-Y2ZD6UO6.cjs +2 -0
- package/dist/chunk-Y2ZD6UO6.cjs.map +1 -0
- package/dist/dialects/athena.cjs +2 -0
- package/dist/dialects/athena.cjs.map +1 -0
- package/dist/dialects/athena.d.cts +66 -0
- package/dist/dialects/athena.d.ts +66 -0
- package/dist/dialects/athena.js +2 -0
- package/dist/dialects/athena.js.map +1 -0
- package/dist/dialects/bigquery.cjs +3 -0
- package/dist/dialects/bigquery.cjs.map +1 -0
- package/dist/dialects/bigquery.d.cts +665 -0
- package/dist/dialects/bigquery.d.ts +665 -0
- package/dist/dialects/bigquery.js +3 -0
- package/dist/dialects/bigquery.js.map +1 -0
- package/dist/dialects/clickhouse.cjs +2 -0
- package/dist/dialects/clickhouse.cjs.map +1 -0
- package/dist/dialects/clickhouse.d.cts +660 -0
- package/dist/dialects/clickhouse.d.ts +660 -0
- package/dist/dialects/clickhouse.js +2 -0
- package/dist/dialects/clickhouse.js.map +1 -0
- package/dist/dialects/databricks.cjs +2 -0
- package/dist/dialects/databricks.cjs.map +1 -0
- package/dist/dialects/databricks.d.cts +495 -0
- package/dist/dialects/databricks.d.ts +495 -0
- package/dist/dialects/databricks.js +2 -0
- package/dist/dialects/databricks.js.map +1 -0
- package/dist/dialects/doris.cjs +2 -0
- package/dist/dialects/doris.cjs.map +1 -0
- package/dist/dialects/doris.d.cts +494 -0
- package/dist/dialects/doris.d.ts +494 -0
- package/dist/dialects/doris.js +2 -0
- package/dist/dialects/doris.js.map +1 -0
- package/dist/dialects/dremio.cjs +2 -0
- package/dist/dialects/dremio.cjs.map +1 -0
- package/dist/dialects/dremio.d.cts +532 -0
- package/dist/dialects/dremio.d.ts +532 -0
- package/dist/dialects/dremio.js +2 -0
- package/dist/dialects/dremio.js.map +1 -0
- package/dist/dialects/drill.cjs +2 -0
- package/dist/dialects/drill.cjs.map +1 -0
- package/dist/dialects/drill.d.cts +522 -0
- package/dist/dialects/drill.d.ts +522 -0
- package/dist/dialects/drill.js +2 -0
- package/dist/dialects/drill.js.map +1 -0
- package/dist/dialects/druid.cjs +2 -0
- package/dist/dialects/druid.cjs.map +1 -0
- package/dist/dialects/druid.d.cts +17 -0
- package/dist/dialects/druid.d.ts +17 -0
- package/dist/dialects/druid.js +2 -0
- package/dist/dialects/druid.js.map +1 -0
- package/dist/dialects/duckdb.cjs +101 -0
- package/dist/dialects/duckdb.cjs.map +1 -0
- package/dist/dialects/duckdb.d.cts +795 -0
- package/dist/dialects/duckdb.d.ts +795 -0
- package/dist/dialects/duckdb.js +101 -0
- package/dist/dialects/duckdb.js.map +1 -0
- package/dist/dialects/dune.cjs +2 -0
- package/dist/dialects/dune.cjs.map +1 -0
- package/dist/dialects/dune.d.cts +21 -0
- package/dist/dialects/dune.d.ts +21 -0
- package/dist/dialects/dune.js +2 -0
- package/dist/dialects/dune.js.map +1 -0
- package/dist/dialects/exasol.cjs +2 -0
- package/dist/dialects/exasol.cjs.map +1 -0
- package/dist/dialects/exasol.d.cts +524 -0
- package/dist/dialects/exasol.d.ts +524 -0
- package/dist/dialects/exasol.js +2 -0
- package/dist/dialects/exasol.js.map +1 -0
- package/dist/dialects/fabric.cjs +2 -0
- package/dist/dialects/fabric.cjs.map +1 -0
- package/dist/dialects/fabric.d.cts +473 -0
- package/dist/dialects/fabric.d.ts +473 -0
- package/dist/dialects/fabric.js +2 -0
- package/dist/dialects/fabric.js.map +1 -0
- package/dist/dialects/hive.cjs +2 -0
- package/dist/dialects/hive.cjs.map +1 -0
- package/dist/dialects/hive.d.cts +602 -0
- package/dist/dialects/hive.d.ts +602 -0
- package/dist/dialects/hive.js +2 -0
- package/dist/dialects/hive.js.map +1 -0
- package/dist/dialects/materialize.cjs +2 -0
- package/dist/dialects/materialize.cjs.map +1 -0
- package/dist/dialects/materialize.d.cts +910 -0
- package/dist/dialects/materialize.d.ts +910 -0
- package/dist/dialects/materialize.js +2 -0
- package/dist/dialects/materialize.js.map +1 -0
- package/dist/dialects/mysql.cjs +2 -0
- package/dist/dialects/mysql.cjs.map +1 -0
- package/dist/dialects/mysql.d.cts +294 -0
- package/dist/dialects/mysql.d.ts +294 -0
- package/dist/dialects/mysql.js +2 -0
- package/dist/dialects/mysql.js.map +1 -0
- package/dist/dialects/oracle.cjs +2 -0
- package/dist/dialects/oracle.cjs.map +1 -0
- package/dist/dialects/oracle.d.cts +550 -0
- package/dist/dialects/oracle.d.ts +550 -0
- package/dist/dialects/oracle.js +2 -0
- package/dist/dialects/oracle.js.map +1 -0
- package/dist/dialects/postgres.cjs +2 -0
- package/dist/dialects/postgres.cjs.map +1 -0
- package/dist/dialects/postgres.d.cts +598 -0
- package/dist/dialects/postgres.d.ts +598 -0
- package/dist/dialects/postgres.js +2 -0
- package/dist/dialects/postgres.js.map +1 -0
- package/dist/dialects/presto.cjs +2 -0
- package/dist/dialects/presto.cjs.map +1 -0
- package/dist/dialects/presto.d.cts +176 -0
- package/dist/dialects/presto.d.ts +176 -0
- package/dist/dialects/presto.js +2 -0
- package/dist/dialects/presto.js.map +1 -0
- package/dist/dialects/prql.cjs +2 -0
- package/dist/dialects/prql.cjs.map +1 -0
- package/dist/dialects/prql.d.cts +506 -0
- package/dist/dialects/prql.d.ts +506 -0
- package/dist/dialects/prql.js +2 -0
- package/dist/dialects/prql.js.map +1 -0
- package/dist/dialects/redshift.cjs +2 -0
- package/dist/dialects/redshift.cjs.map +1 -0
- package/dist/dialects/redshift.d.cts +141 -0
- package/dist/dialects/redshift.d.ts +141 -0
- package/dist/dialects/redshift.js +2 -0
- package/dist/dialects/redshift.js.map +1 -0
- package/dist/dialects/risingwave.cjs +2 -0
- package/dist/dialects/risingwave.cjs.map +1 -0
- package/dist/dialects/risingwave.d.cts +488 -0
- package/dist/dialects/risingwave.d.ts +488 -0
- package/dist/dialects/risingwave.js +2 -0
- package/dist/dialects/risingwave.js.map +1 -0
- package/dist/dialects/singlestore.cjs +2 -0
- package/dist/dialects/singlestore.cjs.map +1 -0
- package/dist/dialects/singlestore.d.cts +73 -0
- package/dist/dialects/singlestore.d.ts +73 -0
- package/dist/dialects/singlestore.js +2 -0
- package/dist/dialects/singlestore.js.map +1 -0
- package/dist/dialects/snowflake.cjs +3 -0
- package/dist/dialects/snowflake.cjs.map +1 -0
- package/dist/dialects/snowflake.d.cts +326 -0
- package/dist/dialects/snowflake.d.ts +326 -0
- package/dist/dialects/snowflake.js +3 -0
- package/dist/dialects/snowflake.js.map +1 -0
- package/dist/dialects/solr.cjs +2 -0
- package/dist/dialects/solr.cjs.map +1 -0
- package/dist/dialects/solr.d.cts +468 -0
- package/dist/dialects/solr.d.ts +468 -0
- package/dist/dialects/solr.js +2 -0
- package/dist/dialects/solr.js.map +1 -0
- package/dist/dialects/spark.cjs +2 -0
- package/dist/dialects/spark.cjs.map +1 -0
- package/dist/dialects/spark.d.cts +500 -0
- package/dist/dialects/spark.d.ts +500 -0
- package/dist/dialects/spark.js +2 -0
- package/dist/dialects/spark.js.map +1 -0
- package/dist/dialects/spark2.cjs +2 -0
- package/dist/dialects/spark2.cjs.map +1 -0
- package/dist/dialects/spark2.d.cts +497 -0
- package/dist/dialects/spark2.d.ts +497 -0
- package/dist/dialects/spark2.js +2 -0
- package/dist/dialects/spark2.js.map +1 -0
- package/dist/dialects/sqlite.cjs +2 -0
- package/dist/dialects/sqlite.cjs.map +1 -0
- package/dist/dialects/sqlite.d.cts +521 -0
- package/dist/dialects/sqlite.d.ts +521 -0
- package/dist/dialects/sqlite.js +2 -0
- package/dist/dialects/sqlite.js.map +1 -0
- package/dist/dialects/starrocks.cjs +2 -0
- package/dist/dialects/starrocks.cjs.map +1 -0
- package/dist/dialects/starrocks.d.cts +529 -0
- package/dist/dialects/starrocks.d.ts +529 -0
- package/dist/dialects/starrocks.js +2 -0
- package/dist/dialects/starrocks.js.map +1 -0
- package/dist/dialects/tableau.cjs +2 -0
- package/dist/dialects/tableau.cjs.map +1 -0
- package/dist/dialects/tableau.d.cts +476 -0
- package/dist/dialects/tableau.d.ts +476 -0
- package/dist/dialects/tableau.js +2 -0
- package/dist/dialects/tableau.js.map +1 -0
- package/dist/dialects/teradata.cjs +2 -0
- package/dist/dialects/teradata.cjs.map +1 -0
- package/dist/dialects/teradata.d.cts +549 -0
- package/dist/dialects/teradata.d.ts +549 -0
- package/dist/dialects/teradata.js +2 -0
- package/dist/dialects/teradata.js.map +1 -0
- package/dist/dialects/trino.cjs +2 -0
- package/dist/dialects/trino.cjs.map +1 -0
- package/dist/dialects/trino.d.cts +475 -0
- package/dist/dialects/trino.d.ts +475 -0
- package/dist/dialects/trino.js +2 -0
- package/dist/dialects/trino.js.map +1 -0
- package/dist/dialects/tsql.cjs +2 -0
- package/dist/dialects/tsql.cjs.map +1 -0
- package/dist/dialects/tsql.d.cts +719 -0
- package/dist/dialects/tsql.d.ts +719 -0
- package/dist/dialects/tsql.js +2 -0
- package/dist/dialects/tsql.js.map +1 -0
- package/dist/index.cjs +26 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +257 -0
- package/dist/index.d.ts +257 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/tokens-DOFGCO-T.d.cts +21871 -0
- package/dist/tokens-DOFGCO-T.d.ts +21871 -0
- package/package.json +267 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# sqlingo
|
|
2
|
+
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 98bee52: - 4f36310: Sync to sqlglot v30.0.0:
|
|
8
|
+
- feat: support multi-word DESCRIBE kinds in Snowflake (DYNAMIC TABLE, MASKING POLICY, API INTEGRATION, etc.)
|
|
9
|
+
- feat(duckdb): ARRAY_SORT, ARRAY_SLICE, ARRAY_INTERSECTION/EXCEPT bag/set semantics, ARRAYS_OVERLAP, SPLIT_PART, MAP_INSERT, MAP_PICK, RANDOM, DATE_TRUNC week start, IGNORE NULLS in AGG FUNC, GROUPS window frame, TO_VARIANT
|
|
10
|
+
- feat(snowflake): window frame for ranking functions, positional GENERATOR args, TO_GEOGRAPHY/TO_GEOMETRY as Cast, SPLIT NULL/empty separator, JSON path dynamic brackets, ARRAY_SORT with nulls
|
|
11
|
+
- feat(clickhouse): DETACH, combined aggregate functions (multi-suffix), cityHash64, ASSUME/CHECK constraints, dotcolon JSON array types, nested field INSERT, ArrayDistinct, ANY/ALL joins
|
|
12
|
+
- feat: consolidate SecurityProperty into SqlSecurityProperty with MySQL locateProperties
|
|
13
|
+
- feat(hive/spark): IGNORE NULLS boolean arg, dash in JSON path, RECURSIVE CTEs
|
|
14
|
+
- feat: parser fast path for column reference parsing
|
|
15
|
+
- fix: Athena kind case mismatch, Oracle InOutColumnConstraint.pop(), Spark DECLARE_DEFAULT_ASSIGNMENT, WindowSpecExpr type-only import, ClickHouse parseDefiner override
|
|
16
|
+
- fix: optimizer pushdown_dnf forward-reference guard, qualify_tables FQN alias mapping, unnest_subqueries crash
|
|
17
|
+
|
|
18
|
+
## 0.7.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- b453c63: Sync to sqlglot 29.0.1:
|
|
23
|
+
- feat(duckdb): support GET_CURRENT_TIME() mapping to CURRENT_TIME
|
|
24
|
+
- reorder JARO_WINKLER_SIMILARITY alphabetically in DuckDB FUNCTIONS
|
|
25
|
+
|
|
26
|
+
## 0.7.0
|
|
27
|
+
|
|
28
|
+
### Minor Changes
|
|
29
|
+
|
|
30
|
+
- a87134d: Minification mangles class names, causing emitted SQL to be gibberish
|
|
31
|
+
|
|
32
|
+
## 0.6.1 (retracted)
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- e6fdbfa: Update new API in readme
|
|
37
|
+
|
|
38
|
+
## 0.6.0 (retracted)
|
|
39
|
+
|
|
40
|
+
### BREAKING CHANGES
|
|
41
|
+
|
|
42
|
+
- Dialect imports no longer auto-register via side effects. Pass dialect classes directly or call `Dialect.register()` explicitly:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// Before (v0.5.0)
|
|
46
|
+
import "sqlingo/mysql";
|
|
47
|
+
parse("SELECT 1", { read: "mysql" });
|
|
48
|
+
|
|
49
|
+
// After (v0.6.0) - preferred: pass class directly
|
|
50
|
+
import { MySQL } from "sqlingo/mysql";
|
|
51
|
+
parse("SELECT 1", { read: MySQL });
|
|
52
|
+
|
|
53
|
+
// After (v0.6.0) - opt-in string lookup
|
|
54
|
+
import { Dialect } from "sqlingo";
|
|
55
|
+
import { MySQL } from "sqlingo/mysql";
|
|
56
|
+
Dialect.register(MySQL);
|
|
57
|
+
parse("SELECT 1", { read: "mysql" });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- `Dialect.register()` signature changed from `register(name, class)` to `register(...classes)`.
|
|
61
|
+
|
|
62
|
+
### Minor Changes
|
|
63
|
+
|
|
64
|
+
- 625fb15: Fix circular imports leading to unusability
|
|
65
|
+
- Side-effect-free API surface enables tree shaking
|
|
66
|
+
- Package marked with `"sideEffects": false`
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- Resolve all 44 failing dialect tests ported from sqlglot v29.0.0 (MySQL, BigQuery, Trino, Databricks, SingleStore, Doris, StarRocks, Drill, Druid, Solr)
|
|
71
|
+
- Fix generator method dispatch casing (`dPipeSql`, `atTimeZoneSql`, `regexpExtractAllSql`, `startsWithSql`) and `ExpressionKey.STARTS_WITH` enum value to match camelCase convention
|
|
72
|
+
- Fix `ORIGINAL_KEYWORDS` convention in Spark/Drill tokenizers, preventing `@cache` inheritance bugs for subclass dialects (e.g. Databricks VOID keyword)
|
|
73
|
+
- Fix `renameFunc` to mirror sqlglot's `*flatten(expression.args.values())`
|
|
74
|
+
- Fix `groupConcatSql` dialect-aware generation and `sep: null` semantics (Python `None` vs JS `undefined`)
|
|
75
|
+
- Fix `pivotAliasSql` to use `toIdentifier()` for numeric alias quoting without mutating shared AST
|
|
76
|
+
- Fix `unixDateSql` to route through dialect generators via `DateDiffExpr` instead of raw string
|
|
77
|
+
- Fix DuckDB `trimSql` BLOB-to-TEXT wrapping, `unnestSql` AS keyword, `numberToStrSql` culture check
|
|
78
|
+
- Fix `explodeProjectionToUnnest`: correct `BracketExpr` indexing, `func()` expression building, `offset: 1` for BigQuery `SAFE_ORDINAL`
|
|
79
|
+
- Fix BigQuery `arrayContainsSql` (`LiteralExpr` not `IdentifierExpr`), ML function kwargs snake-to-camelCase, `buildJsonStripNulls` kwargs, jsonpath `VAR_TOKENS` for hyphenated keys
|
|
80
|
+
- Fix `analyzeSql` clause ordering, `introducerSql` prefix, `boolXorSql` template literal, `ShaLLOW` typo, `sqlName()` call
|
|
81
|
+
- Fix `annotateTypes` to preserve `CastExpr` natural type (not overwrite with `UNKNOWN`), add `INVERSE_FORMAT_TRIE` for format roundtrip
|
|
82
|
+
- Fix MySQL `ESCAPE_FOLLOW_CHARS` static, escape string handling, `timestampTruncSql` quotes, `TO_DAYS` paren, `CharacterSet` default
|
|
83
|
+
- Fix expression `argOrder` for `GapFillExpr`, `TimeStrToTimeExpr`, `TimeExpr`, `RegexpExtractAllExpr`
|
|
84
|
+
- Fix Snowflake inverse time mapping (`mmmm`/`mon`), SingleStore WEEKDAY/Repeat/IsAscii, StarRocks `createSql`, Doris partition parsing/property quoting, Oracle `ON_CONDITION_EMPTY_BEFORE_ERROR`
|
|
85
|
+
- Fix `subsecondPrecision` to use regex instead of Luxon for space-separated timestamps
|
|
86
|
+
- Add missing `register()` on `ExplodeOuterExpr`, `PosexplodeOuterExpr`, `ApproxQuantileExpr`, `ArrayExceptExpr`, `JsonArrayExpr.fromArgList`, `JsonbContainsExpr`, `JsonArrayContainsExpr`, `AndExpr`, `OrExpr`, `XorExpr`
|
|
87
|
+
- Add `TsOrDsAddExpr` type annotation in Spark2/Hive typing for `ADD_MONTHS` transpilation
|
|
88
|
+
- Fix test porting issues: BigQuery byte strings, MySQL escape sequences, raw string newlines, hex byte chars, bracket assertions, `from_` to `from` property access
|
|
89
|
+
|
|
90
|
+
## 0.5.0 (retracted)
|
|
91
|
+
|
|
92
|
+
### Minor Changes
|
|
93
|
+
|
|
94
|
+
- 920aef4: Sync to sqlglot 29.0.0
|
|
95
|
+
|
|
96
|
+
## 0.4.2 (retracted)
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- cd3a34c: Bump deps to resolve dependabot security alerts: `vite` ^8.0.10 to ^8.1.0, `dompurify` override to ^3.4.11, add `ws` ^8.21.0 and `js-yaml` ^4.2.0 overrides
|
|
101
|
+
- f0d9075: Override read-yaml-file to fix changeset js-yaml compatibility
|
|
102
|
+
|
|
103
|
+
## 0.4.1 (retracted)
|
|
104
|
+
|
|
105
|
+
### Patch Changes
|
|
106
|
+
|
|
107
|
+
- 13e61b1: Fix various porting bugs in BigQuery, DuckDB, ClickHouse, and other dialects. All tests are now passing.
|
|
108
|
+
|
|
109
|
+
## 0.4.0 (retracted)
|
|
110
|
+
|
|
111
|
+
### Minor Changes
|
|
112
|
+
|
|
113
|
+
- ec190bb: Add missing snowflake, presto, clickhouse tests and fix various bugs related to them (undiscovered before). The work is still in progress as not 100% tests are passing yet
|
|
114
|
+
- 7ad6584: Annotate FORMAT_STRING(expr) for Spark ([upstream commit](https://github.com/tobymao/sqlglot/commit/1418494f777358f4b6bd1e05ee5cb02591d92c74))
|
|
115
|
+
- 7ad6584: Add numeric TRUNC output for additional dialects: ClickHouse, Presto, Hive, SQLite ([upstream commit](https://github.com/tobymao/sqlglot/commit/ff1fd521147cb66acc36f2da7b1590d9e7f8140f))
|
|
116
|
+
|
|
117
|
+
## 0.3.2 (retracted)
|
|
118
|
+
|
|
119
|
+
### Patch Changes
|
|
120
|
+
|
|
121
|
+
- 92777d6: Update README.md copywriting
|
|
122
|
+
|
|
123
|
+
## 0.3.1 (retracted)
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- Pin upstream sqlglot to 87250100 to include exp.Trunc for numeric truncation
|
|
128
|
+
|
|
129
|
+
## 0.3.0 (retracted)
|
|
130
|
+
|
|
131
|
+
### Minor Changes
|
|
132
|
+
|
|
133
|
+
- cdd20a2: Bump vitest to 4.1.0 & pin vite to 7.3.5 (to support esm decorators)
|
|
134
|
+
- 067de4d: Reorganize the packages to split the lockfile of playground from the sqlingo package
|
|
135
|
+
|
|
136
|
+
## 0.2.3 (retracted)
|
|
137
|
+
|
|
138
|
+
### Patch Changes
|
|
139
|
+
|
|
140
|
+
- e9855e1: Sync with [sqlglot@28.10.1](https://github.com/tobymao/sqlglot/pull/7032)
|
|
141
|
+
- Support missing meta when updating position metadata for an expression ([sqglot#7032](https://github.com/tobymao/sqlglot/pull/7032))
|
|
142
|
+
|
|
143
|
+
## 0.2.2 (retracted)
|
|
144
|
+
|
|
145
|
+
### Patch Changes
|
|
146
|
+
|
|
147
|
+
- 98abe58: Guard against prototype-polluting assignment in `Expression.setArgKey` [#2](https://github.com/huydo862003/sqlingo.js/pull/2)
|
|
148
|
+
|
|
149
|
+
## 0.2.1 (retracted)
|
|
150
|
+
|
|
151
|
+
### Patch Changes
|
|
152
|
+
|
|
153
|
+
- 7c03a7e:
|
|
154
|
+
- Update `dompurify` from 3.2.7 to 3.4.2 to resolve vulnerability issues [#1](https://github.com/huydo862003/sqlingo.js/pull/1)
|
|
155
|
+
- Update `picomatch` from 2.3.1 to 4.0.4 to resolve vulnerability issues [#1](https://github.com/huydo862003/sqlingo.js/pull/1)
|
|
156
|
+
- Update `postcss` from 8.5.8 to 8.5.14 to resolve vulnerability issues [#1](https://github.com/huydo862003/sqlingo.js/pull/1)
|
|
157
|
+
|
|
158
|
+
## 0.2.0 (retracted)
|
|
159
|
+
|
|
160
|
+
### Minor Changes
|
|
161
|
+
|
|
162
|
+
- 62626fd: Complete AI migration. Most code are human-generated now.
|
|
163
|
+
|
|
164
|
+
## 0.1.7 (retracted)
|
|
165
|
+
|
|
166
|
+
### Patch Changes
|
|
167
|
+
|
|
168
|
+
- 29256e1: Fix vulnerability issues
|
|
169
|
+
- b4924ce: Bump flatted to 3.4.2 to fix vulnerability issue
|
|
170
|
+
|
|
171
|
+
## 0.1.6 (retracted)
|
|
172
|
+
|
|
173
|
+
### Patch Changes
|
|
174
|
+
|
|
175
|
+
- 8967932: Fix copywriting of README
|
|
176
|
+
|
|
177
|
+
## 0.1.5 (retracted)
|
|
178
|
+
|
|
179
|
+
### Patch Changes
|
|
180
|
+
|
|
181
|
+
- Redesign homepage with genuix design system; bump to v0.1.5.
|
|
182
|
+
|
|
183
|
+
## 0.1.4 (retracted)
|
|
184
|
+
|
|
185
|
+
### Patch Changes
|
|
186
|
+
|
|
187
|
+
- 1ad4d3e: (fck-AI-slop) Migrating from AI slops
|
|
188
|
+
|
|
189
|
+
## 0.1.3 (retracted)
|
|
190
|
+
|
|
191
|
+
### Patch Changes
|
|
192
|
+
|
|
193
|
+
- 6aeadaa: Add disclaimer about AI usage
|
|
194
|
+
|
|
195
|
+
## 0.1.2 (retracted)
|
|
196
|
+
|
|
197
|
+
### Patch Changes
|
|
198
|
+
|
|
199
|
+
- a0cbe60: Add warnings to npm doc page
|
|
200
|
+
|
|
201
|
+
## 0.1.1 (retracted)
|
|
202
|
+
|
|
203
|
+
### Patch Changes
|
|
204
|
+
|
|
205
|
+
- c90ac1e: Update API doc for npm package
|
|
206
|
+
|
|
207
|
+
## 0.1.0 (retracted)
|
|
208
|
+
|
|
209
|
+
### Minor Changes
|
|
210
|
+
|
|
211
|
+
- Add lazy dialect entrypoints (`sqlingo/postgres`, `/mysql`, `/tsql`, `/mssql`, etc.). Import core without loading any dialect; register only what you need.
|
|
212
|
+
|
|
213
|
+
## 0.0.5 (retracted)
|
|
214
|
+
|
|
215
|
+
### Patch Changes
|
|
216
|
+
|
|
217
|
+
- dc5780a: Update copywriting
|
|
218
|
+
|
|
219
|
+
## 0.0.4 (retracted)
|
|
220
|
+
|
|
221
|
+
### Patch Changes
|
|
222
|
+
|
|
223
|
+
- 4667ffe: Update README
|
|
224
|
+
|
|
225
|
+
## 0.0.3 (retracted)
|
|
226
|
+
|
|
227
|
+
### Patch Changes
|
|
228
|
+
|
|
229
|
+
- cdf377d: Include CHANGELOG.md to package
|
|
230
|
+
|
|
231
|
+
## 0.0.2 (retracted)
|
|
232
|
+
|
|
233
|
+
### Patch Changes
|
|
234
|
+
|
|
235
|
+
- Add GitHub repository info to package.json
|
|
236
|
+
- Add npm-specific README with usage guide and copyright notice
|
|
237
|
+
|
|
238
|
+
## 0.0.1 (retracted)
|
|
239
|
+
|
|
240
|
+
### Patch Changes
|
|
241
|
+
|
|
242
|
+
- First alpha version
|
package/COPYRIGHT_NOTICE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
This project incorporates code from the following sources:
|
|
2
|
+
|
|
3
|
+
===============================================================================
|
|
4
|
+
|
|
5
|
+
sqlingo.js
|
|
6
|
+
Copyright (c) 2026 Huy DNA
|
|
7
|
+
Licensed under the MIT License
|
|
8
|
+
|
|
9
|
+
===============================================================================
|
|
10
|
+
|
|
11
|
+
SQLGlot (https://github.com/tobymao/sqlglot)
|
|
12
|
+
Copyright (c) 2025 Toby Mao
|
|
13
|
+
Licensed under the MIT License
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Huy DNA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# sqlingo
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/sqlingo)
|
|
4
|
+
[](https://github.com/huydo862003/sqlingo.js/blob/master/LICENSE)
|
|
5
|
+

|
|
6
|
+
<a href="https://github.com/huydo862003/Fck-AI-Slop#plan"><img src="https://img.shields.io/badge/human%20slop-90EE90"></a>
|
|
7
|
+
|
|
8
|
+
A JavaScript/TypeScript port of [SQLGlot](https://github.com/tobymao/sqlglot) which is compatible with browser and Node runtimes.
|
|
9
|
+
|
|
10
|
+
This package allows you to parse, transpile, optimize, and execute SQL across **32 dialects** in JavaScript.
|
|
11
|
+
|
|
12
|
+
WARNING: This package is still in alpha.
|
|
13
|
+
- Although the SQLGlot tests have all passed, but finding contrived failures may require me to use this package extensively myself.
|
|
14
|
+
- You can also help me report bugs in the Github issue.
|
|
15
|
+
|
|
16
|
+
NOTICE: AI is not the decision maker, designer or maintainer for this project. It is indeed sometimes used to port straightforward code with less effort. However, the point is to always keep its usage under control & understand what's going on, so I can maintain this project reliably as sqlglot updates.
|
|
17
|
+
|
|
18
|
+
- [GitHub](https://github.com/huydo862003/sqlingo.js)
|
|
19
|
+
- [Issues](https://github.com/huydo862003/sqlingo.js/issues)
|
|
20
|
+
- [Changelog](https://github.com/huydo862003/sqlingo.js/blob/master/CHANGELOG.md)
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- 32 SQL dialects: Postgres, MySQL, BigQuery, Snowflake, DuckDB, ClickHouse, Redshift, Athena, Spark, and many more
|
|
25
|
+
- Some SQLGlot feature set: parsing, transpilation, optimization, column lineage, SQL diffing, and execution
|
|
26
|
+
- Pure JavaScript: no need for WASM or native dependencies
|
|
27
|
+
- TypeScript-first: full type definitions included
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install sqlingo
|
|
33
|
+
# or
|
|
34
|
+
pnpm add sqlingo
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Peer dependency: [`luxon`](https://www.npmjs.com/package/luxon) (^3.7.2) is required for date/time operations.
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
This example demonstrates transpiling a query from Spark to Postgres and then optimizing it.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { transpile, parseOne, optimize, MappingSchema } from "sqlingo";
|
|
45
|
+
import { Postgres } from "sqlingo/postgres";
|
|
46
|
+
import { Spark } from "sqlingo/spark";
|
|
47
|
+
|
|
48
|
+
// Transpile between dialects
|
|
49
|
+
const [pgSql] = transpile("SELECT APPROX_COUNT_DISTINCT(x) FROM table", {
|
|
50
|
+
read: Spark,
|
|
51
|
+
write: Postgres,
|
|
52
|
+
});
|
|
53
|
+
console.log(pgSql);
|
|
54
|
+
// Output: SELECT COUNT(DISTINCT x) FROM "table"
|
|
55
|
+
|
|
56
|
+
// Optimize an expression
|
|
57
|
+
const sql = "SELECT a, b FROM t WHERE a + 1 = 2";
|
|
58
|
+
const schema = new MappingSchema({ t: { a: "int", b: "int" } });
|
|
59
|
+
|
|
60
|
+
const optimized = optimize(parseOne(sql), { schema });
|
|
61
|
+
console.log(optimized.sql());
|
|
62
|
+
// Output: SELECT t.a AS a, t.b AS b FROM t AS t WHERE t.a = 1
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Core Usage
|
|
66
|
+
|
|
67
|
+
### Parsing
|
|
68
|
+
|
|
69
|
+
Parse SQL strings into expression trees (AST).
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { parse, parseOne } from "sqlingo";
|
|
73
|
+
|
|
74
|
+
// Parse multiple statements
|
|
75
|
+
const expressions = parse("SELECT 1; SELECT 2");
|
|
76
|
+
|
|
77
|
+
// Parse a single statement
|
|
78
|
+
const expr = parseOne("SELECT a, b FROM t WHERE a > 1");
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Transpiling
|
|
82
|
+
|
|
83
|
+
Convert SQL between different dialects.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { transpile } from "sqlingo";
|
|
87
|
+
import { DuckDB } from "sqlingo/duckdb";
|
|
88
|
+
import { Hive } from "sqlingo/hive";
|
|
89
|
+
|
|
90
|
+
const [result] = transpile("SELECT EPOCH_MS(1618088028295)", {
|
|
91
|
+
read: DuckDB,
|
|
92
|
+
write: Hive,
|
|
93
|
+
});
|
|
94
|
+
// Output: "SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Tokenizing
|
|
98
|
+
|
|
99
|
+
Extract tokens from a SQL string for lower-level analysis.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { tokenize } from "sqlingo";
|
|
103
|
+
import { Postgres } from "sqlingo/postgres";
|
|
104
|
+
|
|
105
|
+
const tokens = tokenize("SELECT 1", {
|
|
106
|
+
dialect: Postgres,
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## SQL Builder
|
|
111
|
+
|
|
112
|
+
Build queries programmatically using a fluent API.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { select, condition } from "sqlingo";
|
|
116
|
+
import { MySQL } from "sqlingo/mysql";
|
|
117
|
+
|
|
118
|
+
const query = select("a", "b").from("t").where(condition("a > 1")).limit(10);
|
|
119
|
+
|
|
120
|
+
console.log(
|
|
121
|
+
query.sql({
|
|
122
|
+
dialect: MySQL,
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
// Output: SELECT a, b FROM t WHERE a > 1 LIMIT 10
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Optimization & Analysis
|
|
129
|
+
|
|
130
|
+
### Optimization
|
|
131
|
+
|
|
132
|
+
Simplify and normalize queries based on schema information.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { optimize, MappingSchema } from "sqlingo";
|
|
136
|
+
|
|
137
|
+
const schema = new MappingSchema({
|
|
138
|
+
// define your schema
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const optimized = optimize(parseOne("SELECT * FROM t"), { schema });
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Column Lineage
|
|
145
|
+
|
|
146
|
+
Trace the origin of columns through subqueries and joins.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { lineage } from "sqlingo";
|
|
150
|
+
|
|
151
|
+
const node = lineage("b", "SELECT a AS b FROM (SELECT x AS a FROM y)");
|
|
152
|
+
console.log(node.source.name);
|
|
153
|
+
// Output: "y"
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Registering a Custom Dialect
|
|
157
|
+
|
|
158
|
+
You can extend the library by registering custom dialects or overriding existing behavior.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { Dialect, Generator, transpile } from "sqlingo";
|
|
162
|
+
|
|
163
|
+
class MyDialect extends Dialect {
|
|
164
|
+
static DIALECT_NAME = "my_dialect";
|
|
165
|
+
|
|
166
|
+
static Generator = class extends Generator {
|
|
167
|
+
// Override how specific expressions are generated
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Register for string-based lookup
|
|
172
|
+
Dialect.register(MyDialect);
|
|
173
|
+
|
|
174
|
+
const [result] = transpile("SELECT 1", { write: MyDialect });
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Supported Dialects
|
|
178
|
+
|
|
179
|
+
Athena, BigQuery, ClickHouse, Databricks, Doris, Dremio, Drill, Druid, DuckDB, Dune, Exasol, Fabric, Hive, Materialize, MySQL, Oracle, Postgres, Presto, PRQL, Redshift, RisingWave, SingleStore, Snowflake, Solr, Spark, Spark2, SQLite, StarRocks, Tableau, Teradata, Trino, TSQL
|
|
180
|
+
|
|
181
|
+
## SQLGlot Compatibility
|
|
182
|
+
|
|
183
|
+
This package tracks [SQLGlot](https://github.com/tobymao/sqlglot) v30.0.0 (commit `a3929be`). The API surface mirrors SQLGlot's Python API, adapted to TypeScript conventions. See [CONVENTION.md](https://github.com/huydo862003/sqlingo.js/blob/master/CONVENTION.md) for details.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT. See [LICENSE](https://github.com/huydo862003/sqlingo.js/blob/master/LICENSE).
|
|
188
|
+
|
|
189
|
+
Based on [SQLGlot](https://github.com/tobymao/sqlglot) by Toby Mao (MIT). See [COPYRIGHT_NOTICE](https://github.com/huydo862003/sqlingo.js/blob/master/COPYRIGHT_NOTICE).
|
package/README.npm.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# sqlingo
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/sqlingo)
|
|
4
|
+
[](https://github.com/huydo862003/sqlingo.js/blob/master/LICENSE)
|
|
5
|
+

|
|
6
|
+
<a href="https://github.com/huydo862003/Fck-AI-Slop#plan"><img src="https://img.shields.io/badge/human%20slop-90EE90"></a>
|
|
7
|
+
|
|
8
|
+
A JavaScript/TypeScript port of [SQLGlot](https://github.com/tobymao/sqlglot) which is compatible with browser and Node runtimes.
|
|
9
|
+
|
|
10
|
+
This package allows you to parse, transpile, optimize, and execute SQL across **32 dialects** in JavaScript.
|
|
11
|
+
|
|
12
|
+
WARNING: This package is still in alpha.
|
|
13
|
+
- Although the SQLGlot tests have all passed, but finding contrived failures may require me to use this package extensively myself.
|
|
14
|
+
- You can also help me report bugs in the Github issue.
|
|
15
|
+
|
|
16
|
+
NOTICE: AI is not the decision maker, designer or maintainer for this project. It is indeed sometimes used to port straightforward code with less effort. However, the point is to always keep its usage under control & understand what's going on, so I can maintain this project reliably as sqlglot updates.
|
|
17
|
+
|
|
18
|
+
- [GitHub](https://github.com/huydo862003/sqlingo.js)
|
|
19
|
+
- [Issues](https://github.com/huydo862003/sqlingo.js/issues)
|
|
20
|
+
- [Changelog](https://github.com/huydo862003/sqlingo.js/blob/master/CHANGELOG.md)
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- 32 SQL dialects: Postgres, MySQL, BigQuery, Snowflake, DuckDB, ClickHouse, Redshift, Athena, Spark, and many more
|
|
25
|
+
- Some SQLGlot feature set: parsing, transpilation, optimization, column lineage, SQL diffing, and execution
|
|
26
|
+
- Pure JavaScript: no need for WASM or native dependencies
|
|
27
|
+
- TypeScript-first: full type definitions included
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install sqlingo
|
|
33
|
+
# or
|
|
34
|
+
pnpm add sqlingo
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Peer dependency: [`luxon`](https://www.npmjs.com/package/luxon) (^3.7.2) is required for date/time operations.
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
This example demonstrates transpiling a query from Spark to Postgres and then optimizing it.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { transpile, parseOne, optimize, MappingSchema } from "sqlingo";
|
|
45
|
+
import { Postgres } from "sqlingo/postgres";
|
|
46
|
+
import { Spark } from "sqlingo/spark";
|
|
47
|
+
|
|
48
|
+
// Transpile between dialects
|
|
49
|
+
const [pgSql] = transpile("SELECT APPROX_COUNT_DISTINCT(x) FROM table", {
|
|
50
|
+
read: Spark,
|
|
51
|
+
write: Postgres,
|
|
52
|
+
});
|
|
53
|
+
console.log(pgSql);
|
|
54
|
+
// Output: SELECT COUNT(DISTINCT x) FROM "table"
|
|
55
|
+
|
|
56
|
+
// Optimize an expression
|
|
57
|
+
const sql = "SELECT a, b FROM t WHERE a + 1 = 2";
|
|
58
|
+
const schema = new MappingSchema({ t: { a: "int", b: "int" } });
|
|
59
|
+
|
|
60
|
+
const optimized = optimize(parseOne(sql), { schema });
|
|
61
|
+
console.log(optimized.sql());
|
|
62
|
+
// Output: SELECT t.a AS a, t.b AS b FROM t AS t WHERE t.a = 1
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Core Usage
|
|
66
|
+
|
|
67
|
+
### Parsing
|
|
68
|
+
|
|
69
|
+
Parse SQL strings into expression trees (AST).
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { parse, parseOne } from "sqlingo";
|
|
73
|
+
|
|
74
|
+
// Parse multiple statements
|
|
75
|
+
const expressions = parse("SELECT 1; SELECT 2");
|
|
76
|
+
|
|
77
|
+
// Parse a single statement
|
|
78
|
+
const expr = parseOne("SELECT a, b FROM t WHERE a > 1");
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Transpiling
|
|
82
|
+
|
|
83
|
+
Convert SQL between different dialects.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { transpile } from "sqlingo";
|
|
87
|
+
import { DuckDB } from "sqlingo/duckdb";
|
|
88
|
+
import { Hive } from "sqlingo/hive";
|
|
89
|
+
|
|
90
|
+
const [result] = transpile("SELECT EPOCH_MS(1618088028295)", {
|
|
91
|
+
read: DuckDB,
|
|
92
|
+
write: Hive,
|
|
93
|
+
});
|
|
94
|
+
// Output: "SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Tokenizing
|
|
98
|
+
|
|
99
|
+
Extract tokens from a SQL string for lower-level analysis.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { tokenize } from "sqlingo";
|
|
103
|
+
import { Postgres } from "sqlingo/postgres";
|
|
104
|
+
|
|
105
|
+
const tokens = tokenize("SELECT 1", {
|
|
106
|
+
dialect: Postgres,
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## SQL Builder
|
|
111
|
+
|
|
112
|
+
Build queries programmatically using a fluent API.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { select, condition } from "sqlingo";
|
|
116
|
+
import { MySQL } from "sqlingo/mysql";
|
|
117
|
+
|
|
118
|
+
const query = select("a", "b").from("t").where(condition("a > 1")).limit(10);
|
|
119
|
+
|
|
120
|
+
console.log(
|
|
121
|
+
query.sql({
|
|
122
|
+
dialect: MySQL,
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
// Output: SELECT a, b FROM t WHERE a > 1 LIMIT 10
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Optimization & Analysis
|
|
129
|
+
|
|
130
|
+
### Optimization
|
|
131
|
+
|
|
132
|
+
Simplify and normalize queries based on schema information.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { optimize, MappingSchema } from "sqlingo";
|
|
136
|
+
|
|
137
|
+
const schema = new MappingSchema({
|
|
138
|
+
// define your schema
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const optimized = optimize(parseOne("SELECT * FROM t"), { schema });
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Column Lineage
|
|
145
|
+
|
|
146
|
+
Trace the origin of columns through subqueries and joins.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
import { lineage } from "sqlingo";
|
|
150
|
+
|
|
151
|
+
const node = lineage("b", "SELECT a AS b FROM (SELECT x AS a FROM y)");
|
|
152
|
+
console.log(node.source.name);
|
|
153
|
+
// Output: "y"
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Registering a Custom Dialect
|
|
157
|
+
|
|
158
|
+
You can extend the library by registering custom dialects or overriding existing behavior.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { Dialect, Generator, transpile } from "sqlingo";
|
|
162
|
+
|
|
163
|
+
class MyDialect extends Dialect {
|
|
164
|
+
static DIALECT_NAME = "my_dialect";
|
|
165
|
+
|
|
166
|
+
static Generator = class extends Generator {
|
|
167
|
+
// Override how specific expressions are generated
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Register for string-based lookup
|
|
172
|
+
Dialect.register(MyDialect);
|
|
173
|
+
|
|
174
|
+
const [result] = transpile("SELECT 1", { write: MyDialect });
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Supported Dialects
|
|
178
|
+
|
|
179
|
+
Athena, BigQuery, ClickHouse, Databricks, Doris, Dremio, Drill, Druid, DuckDB, Dune, Exasol, Fabric, Hive, Materialize, MySQL, Oracle, Postgres, Presto, PRQL, Redshift, RisingWave, SingleStore, Snowflake, Solr, Spark, Spark2, SQLite, StarRocks, Tableau, Teradata, Trino, TSQL
|
|
180
|
+
|
|
181
|
+
## SQLGlot Compatibility
|
|
182
|
+
|
|
183
|
+
This package tracks [SQLGlot](https://github.com/tobymao/sqlglot) v30.0.0 (commit `a3929be`). The API surface mirrors SQLGlot's Python API, adapted to TypeScript conventions. See [CONVENTION.md](https://github.com/huydo862003/sqlingo.js/blob/master/CONVENTION.md) for details.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT. See [LICENSE](https://github.com/huydo862003/sqlingo.js/blob/master/LICENSE).
|
|
188
|
+
|
|
189
|
+
Based on [SQLGlot](https://github.com/tobymao/sqlglot) by Toby Mao (MIT). See [COPYRIGHT_NOTICE](https://github.com/huydo862003/sqlingo.js/blob/master/COPYRIGHT_NOTICE).
|