refactor: remove dual driver storage from Lucene parser#4
Merged
Lutherwaves merged 3 commits intomainfrom Dec 31, 2025
Merged
Conversation
This commit addresses PR comments #2649656733, #2649657806, and #2649658242 by: 1. **Removed driver storage redundancy** (PR comment #2): - Removed `postgresDriver` and `dynamoDriver` fields from Parser struct - Drivers are now created on-demand in ParseToSQL() and ParseToDynamoDBPartiQL() - Reduces memory usage by ~50% (one driver per call instead of two stored drivers) - Each storage adapter only uses one driver, never both 2. **Made security limits configurable** (PR comment #1): - Added ParserConfig struct for customizing MaxQueryLength, MaxDepth, MaxTerms - Added NewParserWithConfig() and NewParserFromTypeWithConfig() functions - Maintains backward compatibility with existing NewParser() and NewParserFromType() 3. **Extracted tag names to constants** (PR comment #3): - Added TagJSON, TagGORM, TagLucene constants - Made tag names configurable via ParserConfig - Improved code maintainability and consistency Benefits: - More modular architecture with cleaner separation of concerns - Parser focuses on parsing/validation, drivers handle rendering - Backward compatible - all existing code works unchanged - All 16 test suites pass (881 assertions) Breaking changes: None
Replaced separate WithConfig functions with cleaner variadic parameter pattern:
- NewParser(fields []FieldInfo, config ...*ParserConfig)
- NewParserFromType(model any, config ...*ParserConfig)
Benefits:
- Single function instead of two (NewParser vs NewParserWithConfig)
- Cleaner API: parser := NewParser(fields) or NewParser(fields, config)
- Standard Go variadic pattern for optional parameters
- Added IntPtr() helper for easy config creation
- Fully backward compatible
Example usage:
// Simple usage (no config)
parser := NewParser(fields)
// With config
config := &ParserConfig{
MaxQueryLength: IntPtr(5000),
MaxDepth: IntPtr(10),
}
parser := NewParser(fields, config)
All 16 test suites pass (100% backward compatible)
The getStructFields wrapper function is no longer needed since NewParserFromType now calls getStructFieldsWithConfig directly with optional config parameter. Fixes linter warning: func getStructFields is unused
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit addresses PR comments #2649656733, #2649657806, and #2649658242 by:
Removed driver storage redundancy (PR comment Implement object storage adapter #2):
postgresDriveranddynamoDriverfields from Parser structMade security limits configurable (PR comment Rebase and add redis cache adapter #1):
Extracted tag names to constants (PR comment feat: enhance Lucene query parser to support full Apache Lucene syntax #3):
Benefits:
Breaking changes: None