From b7186618c4233f909da7b0eb0bb81eebc6af391e Mon Sep 17 00:00:00 2001 From: JasonShin Date: Sun, 8 Feb 2026 17:23:02 +1100 Subject: [PATCH 1/2] add more function supports --- .../sql_parser/expressions/functions.rs | 8 +++++++- tests/demo/cte/cte.queries.ts | 2 +- tests/demo/cte/cte.snapshot.ts | 2 +- tests/demo/window/lag_lead.queries.ts | 16 ++++++++-------- tests/demo/window/lag_lead.snapshot.ts | 17 ++++++++--------- tests/demo/window/rank_functions.queries.ts | 14 +++++++------- tests/demo/window/rank_functions.snapshot.ts | 15 +++++++-------- tests/demo/window/row_number.queries.ts | 8 ++++---- tests/demo/window/row_number.snapshot.ts | 9 ++++----- 9 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/ts_generator/sql_parser/expressions/functions.rs b/src/ts_generator/sql_parser/expressions/functions.rs index 8ef9af8e..63a8b80e 100644 --- a/src/ts_generator/sql_parser/expressions/functions.rs +++ b/src/ts_generator/sql_parser/expressions/functions.rs @@ -3,6 +3,8 @@ pub static NUMERIC_FUNCTIONS: &[&str] = &[ "ABS", "ACOS", "ASIN", "ATAN", "ATAN2", "AVG", "CEIL", "CEILING", "COS", "COT", "COUNT", "DEGREES", "DIV", "EXP", "FLOOR", "GREATEST", "LEAST", "LN", "LOG", "LOG10", "LOG2", "MAX", "MIN", "MOD", "PI", "POW", "POWER", "RADIANS", "RAND", "ROUND", "SIGN", "SIN", "SQRT", "SUM", "TAN", "TRUNCATE", "TRUNC", + // Window / ranking functions that always return a numeric value + "RANK", "DENSE_RANK", "ROW_NUMBER", "NTILE", "PERCENT_RANK", "CUME_DIST", ]; pub static STRING_FUNCTIONS: &[&str] = &[ @@ -113,7 +115,11 @@ pub fn is_date_function(func_name: &str) -> bool { } // Type-polymorphic functions that return the type of their first argument -pub static TYPE_POLYMORPHIC_FUNCTIONS: &[&str] = &["IFNULL", "COALESCE", "NULLIF", "NVL"]; +pub static TYPE_POLYMORPHIC_FUNCTIONS: &[&str] = &[ + "IFNULL", "COALESCE", "NULLIF", "NVL", + // Window value functions — return the same type as their first argument + "LAG", "LEAD", "FIRST_VALUE", "LAST_VALUE", "NTH_VALUE", +]; pub fn is_type_polymorphic_function(func_name: &str) -> bool { TYPE_POLYMORPHIC_FUNCTIONS.contains(&func_name.to_uppercase().as_str()) diff --git a/tests/demo/cte/cte.queries.ts b/tests/demo/cte/cte.queries.ts index 2af81abb..7feb0c82 100644 --- a/tests/demo/cte/cte.queries.ts +++ b/tests/demo/cte/cte.queries.ts @@ -15,7 +15,7 @@ export type RankWithCteParams = []; export interface IRankWithCteResult { id: number; name: string; - rk: any; + rk: number; } export interface IRankWithCteQuery { diff --git a/tests/demo/cte/cte.snapshot.ts b/tests/demo/cte/cte.snapshot.ts index 2af81abb..7feb0c82 100644 --- a/tests/demo/cte/cte.snapshot.ts +++ b/tests/demo/cte/cte.snapshot.ts @@ -15,7 +15,7 @@ export type RankWithCteParams = []; export interface IRankWithCteResult { id: number; name: string; - rk: any; + rk: number; } export interface IRankWithCteQuery { diff --git a/tests/demo/window/lag_lead.queries.ts b/tests/demo/window/lag_lead.queries.ts index fdf8f830..b1c2842a 100644 --- a/tests/demo/window/lag_lead.queries.ts +++ b/tests/demo/window/lag_lead.queries.ts @@ -3,7 +3,7 @@ export type BasicLagParams = []; export interface IBasicLagResult { id: number; name: string; - previousName: any; + previousName: string; } export interface IBasicLagQuery { @@ -16,7 +16,7 @@ export type BasicLeadParams = []; export interface IBasicLeadResult { id: number; name: string; - nextName: any; + nextName: string; } export interface IBasicLeadQuery { @@ -29,7 +29,7 @@ export type LagWithDefaultParams = []; export interface ILagWithDefaultResult { id: number; name: string; - previousName: any; + previousName: string; } export interface ILagWithDefaultQuery { @@ -42,8 +42,8 @@ export type LagAndLeadParams = []; export interface ILagAndLeadResult { id: number; name: string; - nextName: any; - previousName: any; + nextName: string; + previousName: string; } export interface ILagAndLeadQuery { @@ -56,7 +56,7 @@ export type LagWithPartitionParams = []; export interface ILagWithPartitionResult { id: number; name: string; - previousInRarity: any; + previousInRarity: string; rarity: string | null; } @@ -68,9 +68,9 @@ export interface ILagWithPartitionQuery { export type FirstLastValueParams = []; export interface IFirstLastValueResult { - firstInRarity: any; + firstInRarity: string; id: number; - lastInRarity: any; + lastInRarity: string; name: string; rarity: string | null; } diff --git a/tests/demo/window/lag_lead.snapshot.ts b/tests/demo/window/lag_lead.snapshot.ts index 6de87008..b1c2842a 100644 --- a/tests/demo/window/lag_lead.snapshot.ts +++ b/tests/demo/window/lag_lead.snapshot.ts @@ -3,7 +3,7 @@ export type BasicLagParams = []; export interface IBasicLagResult { id: number; name: string; - previousName: any; + previousName: string; } export interface IBasicLagQuery { @@ -16,7 +16,7 @@ export type BasicLeadParams = []; export interface IBasicLeadResult { id: number; name: string; - nextName: any; + nextName: string; } export interface IBasicLeadQuery { @@ -29,7 +29,7 @@ export type LagWithDefaultParams = []; export interface ILagWithDefaultResult { id: number; name: string; - previousName: any; + previousName: string; } export interface ILagWithDefaultQuery { @@ -42,8 +42,8 @@ export type LagAndLeadParams = []; export interface ILagAndLeadResult { id: number; name: string; - nextName: any; - previousName: any; + nextName: string; + previousName: string; } export interface ILagAndLeadQuery { @@ -56,7 +56,7 @@ export type LagWithPartitionParams = []; export interface ILagWithPartitionResult { id: number; name: string; - previousInRarity: any; + previousInRarity: string; rarity: string | null; } @@ -68,9 +68,9 @@ export interface ILagWithPartitionQuery { export type FirstLastValueParams = []; export interface IFirstLastValueResult { - firstInRarity: any; + firstInRarity: string; id: number; - lastInRarity: any; + lastInRarity: string; name: string; rarity: string | null; } @@ -79,4 +79,3 @@ export interface IFirstLastValueQuery { params: FirstLastValueParams; result: IFirstLastValueResult; } - diff --git a/tests/demo/window/rank_functions.queries.ts b/tests/demo/window/rank_functions.queries.ts index f122f0c7..d292e684 100644 --- a/tests/demo/window/rank_functions.queries.ts +++ b/tests/demo/window/rank_functions.queries.ts @@ -3,7 +3,7 @@ export type BasicRankParams = []; export interface IBasicRankResult { id: number; name: string; - rank: any; + rank: number; rarity: string | null; } @@ -15,7 +15,7 @@ export interface IBasicRankQuery { export type DenseRankParams = []; export interface IDenseRankResult { - denseRank: any; + denseRank: number; id: number; name: string; rarity: string | null; @@ -31,7 +31,7 @@ export type RankWithPartitionParams = []; export interface IRankWithPartitionResult { id: number; name: string; - rank: any; + rank: number; rarity: string | null; } @@ -43,12 +43,12 @@ export interface IRankWithPartitionQuery { export type MultipleRankingParams = []; export interface IMultipleRankingResult { - denseRank: any; + denseRank: number; id: number; name: string; - rank: any; + rank: number; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IMultipleRankingQuery { @@ -61,7 +61,7 @@ export type NtileQuartilesParams = []; export interface INtileQuartilesResult { id: number; name: string; - quartile: any; + quartile: number; } export interface INtileQuartilesQuery { diff --git a/tests/demo/window/rank_functions.snapshot.ts b/tests/demo/window/rank_functions.snapshot.ts index d9e2d04b..d292e684 100644 --- a/tests/demo/window/rank_functions.snapshot.ts +++ b/tests/demo/window/rank_functions.snapshot.ts @@ -3,7 +3,7 @@ export type BasicRankParams = []; export interface IBasicRankResult { id: number; name: string; - rank: any; + rank: number; rarity: string | null; } @@ -15,7 +15,7 @@ export interface IBasicRankQuery { export type DenseRankParams = []; export interface IDenseRankResult { - denseRank: any; + denseRank: number; id: number; name: string; rarity: string | null; @@ -31,7 +31,7 @@ export type RankWithPartitionParams = []; export interface IRankWithPartitionResult { id: number; name: string; - rank: any; + rank: number; rarity: string | null; } @@ -43,12 +43,12 @@ export interface IRankWithPartitionQuery { export type MultipleRankingParams = []; export interface IMultipleRankingResult { - denseRank: any; + denseRank: number; id: number; name: string; - rank: any; + rank: number; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IMultipleRankingQuery { @@ -61,11 +61,10 @@ export type NtileQuartilesParams = []; export interface INtileQuartilesResult { id: number; name: string; - quartile: any; + quartile: number; } export interface INtileQuartilesQuery { params: NtileQuartilesParams; result: INtileQuartilesResult; } - diff --git a/tests/demo/window/row_number.queries.ts b/tests/demo/window/row_number.queries.ts index b5e1c546..9f639c69 100644 --- a/tests/demo/window/row_number.queries.ts +++ b/tests/demo/window/row_number.queries.ts @@ -4,7 +4,7 @@ export interface IBasicRowNumberResult { id: number; name: string; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IBasicRowNumberQuery { @@ -18,7 +18,7 @@ export interface IRowNumberWithPartitionResult { id: number; name: string; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IRowNumberWithPartitionQuery { @@ -32,7 +32,7 @@ export interface IRowNumberWithWhereResult { id: number; name: string; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IRowNumberWithWhereQuery { @@ -46,7 +46,7 @@ export interface IRowNumberWithParamsResult { id: number; name: string; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IRowNumberWithParamsQuery { diff --git a/tests/demo/window/row_number.snapshot.ts b/tests/demo/window/row_number.snapshot.ts index e4be758d..9f639c69 100644 --- a/tests/demo/window/row_number.snapshot.ts +++ b/tests/demo/window/row_number.snapshot.ts @@ -4,7 +4,7 @@ export interface IBasicRowNumberResult { id: number; name: string; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IBasicRowNumberQuery { @@ -18,7 +18,7 @@ export interface IRowNumberWithPartitionResult { id: number; name: string; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IRowNumberWithPartitionQuery { @@ -32,7 +32,7 @@ export interface IRowNumberWithWhereResult { id: number; name: string; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IRowNumberWithWhereQuery { @@ -46,11 +46,10 @@ export interface IRowNumberWithParamsResult { id: number; name: string; rarity: string | null; - rowNum: any; + rowNum: number; } export interface IRowNumberWithParamsQuery { params: RowNumberWithParamsParams; result: IRowNumberWithParamsResult; } - From 61193cdac913144230e479b028d702a9bebd4237 Mon Sep 17 00:00:00 2001 From: JasonShin Date: Sun, 8 Feb 2026 17:26:43 +1100 Subject: [PATCH 2/2] fmt --- .../sql_parser/expressions/functions.rs | 58 +++++++++++++++++-- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/ts_generator/sql_parser/expressions/functions.rs b/src/ts_generator/sql_parser/expressions/functions.rs index 63a8b80e..fb8d2bd4 100644 --- a/src/ts_generator/sql_parser/expressions/functions.rs +++ b/src/ts_generator/sql_parser/expressions/functions.rs @@ -1,10 +1,49 @@ // LIST OF FUNCTIONS FOUND https://www.w3schools.com/mysql/mysql_ref_functions.asp pub static NUMERIC_FUNCTIONS: &[&str] = &[ - "ABS", "ACOS", "ASIN", "ATAN", "ATAN2", "AVG", "CEIL", "CEILING", "COS", "COT", "COUNT", "DEGREES", "DIV", "EXP", - "FLOOR", "GREATEST", "LEAST", "LN", "LOG", "LOG10", "LOG2", "MAX", "MIN", "MOD", "PI", "POW", "POWER", "RADIANS", - "RAND", "ROUND", "SIGN", "SIN", "SQRT", "SUM", "TAN", "TRUNCATE", "TRUNC", + "ABS", + "ACOS", + "ASIN", + "ATAN", + "ATAN2", + "AVG", + "CEIL", + "CEILING", + "COS", + "COT", + "COUNT", + "DEGREES", + "DIV", + "EXP", + "FLOOR", + "GREATEST", + "LEAST", + "LN", + "LOG", + "LOG10", + "LOG2", + "MAX", + "MIN", + "MOD", + "PI", + "POW", + "POWER", + "RADIANS", + "RAND", + "ROUND", + "SIGN", + "SIN", + "SQRT", + "SUM", + "TAN", + "TRUNCATE", + "TRUNC", // Window / ranking functions that always return a numeric value - "RANK", "DENSE_RANK", "ROW_NUMBER", "NTILE", "PERCENT_RANK", "CUME_DIST", + "RANK", + "DENSE_RANK", + "ROW_NUMBER", + "NTILE", + "PERCENT_RANK", + "CUME_DIST", ]; pub static STRING_FUNCTIONS: &[&str] = &[ @@ -116,9 +155,16 @@ pub fn is_date_function(func_name: &str) -> bool { // Type-polymorphic functions that return the type of their first argument pub static TYPE_POLYMORPHIC_FUNCTIONS: &[&str] = &[ - "IFNULL", "COALESCE", "NULLIF", "NVL", + "IFNULL", + "COALESCE", + "NULLIF", + "NVL", // Window value functions — return the same type as their first argument - "LAG", "LEAD", "FIRST_VALUE", "LAST_VALUE", "NTH_VALUE", + "LAG", + "LEAD", + "FIRST_VALUE", + "LAST_VALUE", + "NTH_VALUE", ]; pub fn is_type_polymorphic_function(func_name: &str) -> bool {