Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Aug 12, 2025

Summary

This PR implements bidirectional conversion functionality between SQL files and @SQL annotations in Doma DAO methods, allowing developers to seamlessly switch between these
two SQL definition approaches.

Changes

New Features

  • SQL Annotation to File Conversion (ConvertSqlAnnotationToFileAction)

    • Converts @SQL, @select, @update, @insert, @delete,@BatchUpdate, @BatchInsert, @BatchDelete, and @script annotations to external SQL files
    • Automatically creates SQL files in the appropriate META-INF directory structure
    • Preserves SQL formatting during conversion
  • SQL File to Annotation Conversion (ConvertSqlFileToAnnotationAction)

    • Converts external SQL files back to @SQL annotations
    • Maintains proper formatting and escaping of SQL content
    • Removes SQL files after successful conversion
  • SQL Annotation Converter Utility (SqlAnnotationConverter)

    • Core conversion logic for both directions
    • Handles SQL formatting using the new dedicated formatter
    • Manages file operations and annotation manipulation

Infrastructure Improvements

  • Dedicated SQL Formatter (InjectionSqlFormatter)
    • Extracted SQL formatting logic for use outside of the main formatter functionality
    • Enables consistent SQL formatting across different features
    • Supports formatting tasks with configurable options

Testing

  • Verify @SQL annotation to file conversion works correctly
  • Verify SQL file to @SQL annotation conversion maintains formatting
  • Test conversion for all supported annotation types (@select, @update, @insert, @delete, @script)
  • Confirm SQL files are created in correct directory structure
  • Validate that existing formatter functionality remains unaffected
  • Check that all existing tests pass

� Generated with Claude Code

Co-Authored-By: Claude [email protected]

@xterao xterao changed the title feature/sql generate by annotation Add bidirectional conversion between SQL files and @Sql annotations Aug 12, 2025
@xterao xterao added this to the 2.1.0 Release milestone Aug 14, 2025
@xterao xterao linked an issue Aug 14, 2025 that may be closed by this pull request
@xterao xterao requested a review from Copilot August 14, 2025 06:55
@xterao xterao self-assigned this Aug 14, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements bidirectional conversion functionality between SQL files and @SQL annotations in Doma DAO methods, enabling developers to seamlessly switch between inline SQL annotations and external SQL files.

  • SQL annotation to file conversion: Converts @SQL, @select, @update, @insert, @delete, @BatchUpdate, @BatchInsert, @BatchDelete, and @script annotations to external SQL files with automatic formatting
  • SQL file to annotation conversion: Converts external SQL files back to @SQL annotations with proper escaping and formatting
  • Infrastructure improvements: New dedicated SQL formatter and comprehensive test coverage for both conversion directions

Reviewed Changes

Copilot reviewed 85 out of 85 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
New test data files Expected output files for testing both conversion directions across different DAO annotation types
ConvertSqlFileToAnnotationActionTest.kt Test cases for SQL file to @SQL annotation conversion functionality
ConvertSqlAnnotationToFileActionTest.kt Test cases for @SQL annotation to SQL file conversion functionality
DomaToolsBundle*.properties Internationalized messages for the new conversion actions
Intention descriptions HTML documentation for the new intention actions
plugin.xml Plugin registration for the two new intention actions
DaoInjectionSqlVisitor.kt Refactored to use the new dedicated InjectionSqlFormatter
SqlInjectionPostProcessor.kt Updated to use the new InjectionSqlFormatter
InjectionSqlFormatter.kt New dedicated SQL formatter for injection contexts
PsiDaoMethod.kt Enhanced to handle SQL file deletion when overwriting existing files
SqlAnnotationConverter.kt Core conversion logic handling both directions with SQL formatting
ConvertSqlFileToAnnotationAction.kt Intention action for converting SQL files to @SQL annotations
ConvertSqlAnnotationToFileAction.kt Intention action for converting @SQL annotations to SQL files

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@xterao xterao force-pushed the feature/sql-generate-by-annotation branch from 6fd2bba to 41dbfa2 Compare August 14, 2025 08:14
@xterao xterao merged commit c290770 into main Aug 15, 2025
5 checks passed
@xterao xterao deleted the feature/sql-generate-by-annotation branch August 15, 2025 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mutual Generation Between @Sql Annotation and SQL Files

2 participants