Skip to content

Commit abbdaa1

Browse files
committed
improvement(table): correct JSDoc examples for required columns arg
1 parent 8503120 commit abbdaa1

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

apps/sim/lib/table/sql.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,27 @@ const ALLOWED_OPERATORS = new Set([
7575
*
7676
* @param filter - Filter object with field conditions and logical operators
7777
* @param tableName - Table name for the query (e.g., 'user_table_rows')
78+
* @param columns - Column definitions; drives type-aware JSONB casts (numeric for numbers, timestamptz for dates)
7879
* @returns SQL WHERE clause or undefined if no filter specified
7980
* @throws {TableQueryValidationError} if field name is invalid or operator is not allowed
8081
*
8182
* @example
8283
* // Simple equality
83-
* buildFilterClause({ name: 'John' }, 'user_table_rows')
84+
* buildFilterClause({ name: 'John' }, 'user_table_rows', [{ name: 'name', type: 'string' }])
8485
*
85-
* // Complex filter with operators
86-
* buildFilterClause({ age: { $gte: 18 }, status: { $in: ['active', 'pending'] } }, 'user_table_rows')
86+
* // Range on a date column — emits `::timestamptz` on both sides
87+
* buildFilterClause(
88+
* { birthDate: { $gte: '2024-01-01' } },
89+
* 'user_table_rows',
90+
* [{ name: 'birthDate', type: 'date' }],
91+
* )
8792
*
8893
* // Logical operators
89-
* buildFilterClause({ $or: [{ status: 'active' }, { verified: true }] }, 'user_table_rows')
94+
* buildFilterClause(
95+
* { $or: [{ status: 'active' }, { verified: true }] },
96+
* 'user_table_rows',
97+
* [{ name: 'status', type: 'string' }, { name: 'verified', type: 'boolean' }],
98+
* )
9099
*/
91100
export function buildFilterClause(
92101
filter: Filter,
@@ -157,18 +166,25 @@ function buildFilterClauseInternal(
157166
*
158167
* @param sort - Sort object with field names and directions
159168
* @param tableName - Table name for the query (e.g., 'user_table_rows')
160-
* @param columns - Optional column definitions for type-aware sorting
169+
* @param columns - Column definitions; drives type-aware casts (numeric for numbers, timestamptz for dates)
161170
* @returns SQL ORDER BY clause or undefined if no sort specified
162171
* @throws {TableQueryValidationError} if field name or sort direction is invalid
163172
*
164173
* @example
165-
* buildSortClause({ name: 'asc', age: 'desc' }, 'user_table_rows')
166-
* // Returns: ORDER BY data->>'name' ASC, data->>'age' DESC
174+
* buildSortClause(
175+
* { name: 'asc' },
176+
* 'user_table_rows',
177+
* [{ name: 'name', type: 'string' }],
178+
* )
179+
* // Returns: ORDER BY user_table_rows.data->>'name' ASC
167180
*
168181
* @example
169-
* // With column types for proper numeric sorting
170-
* buildSortClause({ salary: 'desc' }, 'user_table_rows', [{ name: 'salary', type: 'number' }])
171-
* // Returns: ORDER BY (data->>'salary')::numeric DESC NULLS LAST
182+
* buildSortClause(
183+
* { salary: 'desc' },
184+
* 'user_table_rows',
185+
* [{ name: 'salary', type: 'number' }],
186+
* )
187+
* // Returns: ORDER BY (user_table_rows.data->>'salary')::numeric DESC NULLS LAST
172188
*/
173189
export function buildSortClause(
174190
sort: Sort,

0 commit comments

Comments
 (0)