@@ -165,12 +165,10 @@ final class SQLCompletionProvider {
165165 ] )
166166
167167 case . alterTableColumn:
168- // After ALTER TABLE tablename DROP/MODIFY/CHANGE/AFTER - suggest column names
168+ // After ALTER TABLE tablename DROP/MODIFY/CHANGE/RENAME or AFTER/BEFORE - suggest column names
169169 if let firstTable = context. tableReferences. first {
170170 items = await schemaProvider. columnCompletionItems ( for: firstTable. tableName)
171171 }
172- // Add positioning keywords
173- items += filterKeywords ( [ " COLUMN " , " FIRST " , " AFTER " , " BEFORE " ] )
174172
175173 case . createTable:
176174 // Inside CREATE TABLE (...) - suggest constraints and data types
@@ -373,125 +371,4 @@ final class SQLCompletionProvider {
373371 }
374372}
375373
376- // MARK: - SQL Keywords Helper
377-
378- /// Helper for common SQL keywords and functions
379- enum SQLKeywords {
380- /// Common SQL functions for autocomplete
381- static func functionItems( ) -> [ SQLCompletionItem ] {
382- let functions : [ ( name: String , signature: String ? , doc: String ? ) ] = [
383- // Aggregate functions
384- ( " COUNT " , " COUNT(*) " , " Counts rows " ) ,
385- ( " SUM " , " SUM(column) " , " Sums values " ) ,
386- ( " AVG " , " AVG(column) " , " Calculates average " ) ,
387- ( " MIN " , " MIN(column) " , " Finds minimum value " ) ,
388- ( " MAX " , " MAX(column) " , " Finds maximum value " ) ,
389- ( " GROUP_CONCAT " , " GROUP_CONCAT(column) " , " Concatenates values (MySQL) " ) ,
390- ( " STRING_AGG " , " STRING_AGG(column, delimiter) " , " Concatenates values (PostgreSQL) " ) ,
391-
392- // String functions
393- ( " CONCAT " , " CONCAT(str1, str2, ...) " , " Concatenates strings " ) ,
394- ( " SUBSTRING " , " SUBSTRING(str, start, length) " , " Extracts substring " ) ,
395- ( " SUBSTR " , " SUBSTR(str, start, length) " , " Extracts substring " ) ,
396- ( " UPPER " , " UPPER(str) " , " Converts to uppercase " ) ,
397- ( " LOWER " , " LOWER(str) " , " Converts to lowercase " ) ,
398- ( " TRIM " , " TRIM(str) " , " Removes whitespace " ) ,
399- ( " LTRIM " , " LTRIM(str) " , " Removes left whitespace " ) ,
400- ( " RTRIM " , " RTRIM(str) " , " Removes right whitespace " ) ,
401- ( " LENGTH " , " LENGTH(str) " , " Returns string length " ) ,
402- ( " CHAR_LENGTH " , " CHAR_LENGTH(str) " , " Returns character length " ) ,
403- ( " REPLACE " , " REPLACE(str, from, to) " , " Replaces substring " ) ,
404- ( " LEFT " , " LEFT(str, length) " , " Returns leftmost characters " ) ,
405- ( " RIGHT " , " RIGHT(str, length) " , " Returns rightmost characters " ) ,
406- ( " REVERSE " , " REVERSE(str) " , " Reverses string " ) ,
407-
408- // Date/Time functions
409- ( " NOW " , " NOW() " , " Returns current datetime " ) ,
410- ( " CURRENT_DATE " , " CURRENT_DATE " , " Returns current date " ) ,
411- ( " CURRENT_TIME " , " CURRENT_TIME " , " Returns current time " ) ,
412- ( " CURRENT_TIMESTAMP " , " CURRENT_TIMESTAMP " , " Returns current timestamp " ) ,
413- ( " DATE " , " DATE(datetime) " , " Extracts date part " ) ,
414- ( " TIME " , " TIME(datetime) " , " Extracts time part " ) ,
415- ( " YEAR " , " YEAR(date) " , " Extracts year " ) ,
416- ( " MONTH " , " MONTH(date) " , " Extracts month " ) ,
417- ( " DAY " , " DAY(date) " , " Extracts day " ) ,
418- ( " HOUR " , " HOUR(datetime) " , " Extracts hour " ) ,
419- ( " MINUTE " , " MINUTE(datetime) " , " Extracts minute " ) ,
420- ( " SECOND " , " SECOND(datetime) " , " Extracts second " ) ,
421- ( " DATE_FORMAT " , " DATE_FORMAT(date, format) " , " Formats date (MySQL) " ) ,
422- ( " TO_CHAR " , " TO_CHAR(value, format) " , " Formats value (PostgreSQL) " ) ,
423- ( " EXTRACT " , " EXTRACT(field FROM source) " , " Extracts date/time field " ) ,
424- ( " DATE_ADD " , " DATE_ADD(date, INTERVAL value unit) " , " Adds interval to date " ) ,
425- ( " DATE_SUB " , " DATE_SUB(date, INTERVAL value unit) " , " Subtracts interval from date " ) ,
426- ( " DATEDIFF " , " DATEDIFF(date1, date2) " , " Difference between dates " ) ,
427- ( " AGE " , " AGE(timestamp) " , " Calculate age (PostgreSQL) " ) ,
428-
429- // Mathematical functions
430- ( " ABS " , " ABS(number) " , " Absolute value " ) ,
431- ( " ROUND " , " ROUND(number, decimals) " , " Rounds number " ) ,
432- ( " CEIL " , " CEIL(number) " , " Rounds up " ) ,
433- ( " CEILING " , " CEILING(number) " , " Rounds up " ) ,
434- ( " FLOOR " , " FLOOR(number) " , " Rounds down " ) ,
435- ( " MOD " , " MOD(n, m) " , " Modulo operation " ) ,
436- ( " POWER " , " POWER(base, exponent) " , " Raises to power " ) ,
437- ( " POW " , " POW(base, exponent) " , " Raises to power " ) ,
438- ( " SQRT " , " SQRT(number) " , " Square root " ) ,
439- ( " RAND " , " RAND() " , " Random number " ) ,
440- ( " RANDOM " , " RANDOM() " , " Random number (PostgreSQL) " ) ,
441-
442- // Conditional functions
443- ( " COALESCE " , " COALESCE(val1, val2, ...) " , " Returns first non-null value " ) ,
444- ( " IFNULL " , " IFNULL(value, alt) " , " Returns alt if value is null (MySQL) " ) ,
445- ( " NULLIF " , " NULLIF(val1, val2) " , " Returns null if values equal " ) ,
446- ( " IF " , " IF(condition, true_val, false_val) " , " Conditional expression (MySQL) " ) ,
447- ( " CASE " , " CASE WHEN ... THEN ... END " , " Case expression " ) ,
448-
449- // Type conversion
450- ( " CAST " , " CAST(value AS type) " , " Converts data type " ) ,
451- ( " CONVERT " , " CONVERT(value, type) " , " Converts data type " ) ,
452-
453- // JSON functions (MySQL 5.7+, PostgreSQL 9.2+)
454- ( " JSON_EXTRACT " , " JSON_EXTRACT(json, path) " , " Extracts JSON value " ) ,
455- ( " JSON_OBJECT " , " JSON_OBJECT(key, value, ...) " , " Creates JSON object " ) ,
456- ( " JSON_ARRAY " , " JSON_ARRAY(value, ...) " , " Creates JSON array " ) ,
457- ( " JSONB_BUILD_OBJECT " , " JSONB_BUILD_OBJECT(key, val, ...) " , " Creates JSONB object (PostgreSQL) " ) ,
458-
459- // Window functions
460- ( " ROW_NUMBER " , " ROW_NUMBER() OVER(...) " , " Assigns row number " ) ,
461- ( " RANK " , " RANK() OVER(...) " , " Assigns rank " ) ,
462- ( " DENSE_RANK " , " DENSE_RANK() OVER(...) " , " Assigns dense rank " ) ,
463- ( " LAG " , " LAG(column, offset) OVER(...) " , " Accesses previous row " ) ,
464- ( " LEAD " , " LEAD(column, offset) OVER(...) " , " Accesses next row " ) ,
465- ]
466-
467- return functions. map { name, signature, doc in
468- SQLCompletionItem . function ( name, signature: signature, documentation: doc)
469- }
470- }
471-
472- /// SQL operators for autocomplete
473- static func operatorItems( ) -> [ SQLCompletionItem ] {
474- let operators : [ ( op: String , doc: String ) ] = [
475- ( " = " , " Equal to " ) ,
476- ( " <> " , " Not equal to " ) ,
477- ( " != " , " Not equal to (alternative) " ) ,
478- ( " > " , " Greater than " ) ,
479- ( " < " , " Less than " ) ,
480- ( " >= " , " Greater than or equal " ) ,
481- ( " <= " , " Less than or equal " ) ,
482- ( " IS NULL " , " Checks for NULL value " ) ,
483- ( " IS NOT NULL " , " Checks for non-NULL value " ) ,
484- ( " LIKE " , " Pattern matching " ) ,
485- ( " NOT LIKE " , " Negated pattern matching " ) ,
486- ( " IN " , " Value in list " ) ,
487- ( " NOT IN " , " Value not in list " ) ,
488- ( " BETWEEN " , " Value in range " ) ,
489- ( " NOT BETWEEN " , " Value not in range " ) ,
490- ]
491-
492- return operators. map { op, doc in
493- SQLCompletionItem . operator ( op, documentation: doc)
494- }
495- }
496- }
497374
0 commit comments