sequel-duckdb 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/lib/sequel/adapters/duckdb.rb +3 -3
  4. data/lib/sequel/adapters/shared/duckdb.rb +17 -17
  5. data/lib/sequel/duckdb/version.rb +1 -1
  6. metadata +21 -60
  7. data/.beads/.beads-credential-key +0 -1
  8. data/.beads/.gitignore +0 -66
  9. data/.beads/README.md +0 -85
  10. data/.beads/config.yaml +0 -56
  11. data/.beads/hooks/post-checkout +0 -24
  12. data/.beads/hooks/post-merge +0 -24
  13. data/.beads/hooks/pre-commit +0 -24
  14. data/.beads/hooks/pre-push +0 -24
  15. data/.beads/hooks/prepare-commit-msg +0 -24
  16. data/.beads/metadata.json +0 -7
  17. data/.kiro/specs/advanced-sql-features-implementation/design.md +0 -26
  18. data/.kiro/specs/advanced-sql-features-implementation/requirements.md +0 -43
  19. data/.kiro/specs/advanced-sql-features-implementation/tasks.md +0 -28
  20. data/.kiro/specs/duckdb-sql-syntax-compatibility/design.md +0 -272
  21. data/.kiro/specs/duckdb-sql-syntax-compatibility/requirements.md +0 -84
  22. data/.kiro/specs/duckdb-sql-syntax-compatibility/tasks.md +0 -107
  23. data/.kiro/specs/edge-cases-and-validation-fixes/requirements.md +0 -32
  24. data/.kiro/specs/integration-test-database-setup/design.md +0 -0
  25. data/.kiro/specs/integration-test-database-setup/requirements.md +0 -117
  26. data/.kiro/specs/sequel-duckdb-adapter/design.md +0 -549
  27. data/.kiro/specs/sequel-duckdb-adapter/requirements.md +0 -202
  28. data/.kiro/specs/sequel-duckdb-adapter/tasks.md +0 -292
  29. data/.kiro/specs/sql-expression-handling-fix/design.md +0 -331
  30. data/.kiro/specs/sql-expression-handling-fix/requirements.md +0 -86
  31. data/.kiro/specs/sql-expression-handling-fix/tasks.md +0 -25
  32. data/.kiro/specs/test-infrastructure-improvements/requirements.md +0 -106
  33. data/.kiro/steering/product.md +0 -26
  34. data/.kiro/steering/structure.md +0 -88
  35. data/.kiro/steering/tech.md +0 -137
  36. data/.kiro/steering/testing.md +0 -213
  37. data/.mdformat.toml +0 -2
  38. data/.rubocop.yml +0 -161
  39. data/.rubocop_todo.yml +0 -323
  40. data/.yardopts +0 -8
  41. data/AGENTS.md +0 -180
  42. data/API_DOCUMENTATION.md +0 -943
  43. data/FINAL_STATUS.md +0 -99
  44. data/MIGRATION_EXAMPLES.md +0 -740
  45. data/PERFORMANCE_OPTIMIZATIONS.md +0 -726
  46. data/REFACTORING_SUMMARY.md +0 -264
  47. data/Rakefile +0 -43
  48. data/TASK_10.2_IMPLEMENTATION_SUMMARY.md +0 -182
  49. data/docs/DUCKDB_SQL_PATTERNS.md +0 -448
  50. data/docs/TASK_12_VERIFICATION_SUMMARY.md +0 -135
  51. data/justfile +0 -50
  52. data/plans/date_arithmetic.md +0 -420
  53. data/plans/engineering/Sequel.md +0 -471
  54. data/plans/engineering/duckdb.md +0 -712
  55. data/plans/engineering/sqlite.md +0 -453
  56. data/plans/mock_connection_bug.md +0 -333
  57. data/plans/mock_without_driver_gem.md +0 -371
  58. data/plans/over_engineering_analysis.md +0 -122
  59. data/plans/schema_management.md +0 -383
  60. data/sig/sequel/duckdb.rbs +0 -6
@@ -1,331 +0,0 @@
1
- # Design Document: SQL Expression Handling Fix
2
-
3
- ## Overview
4
-
5
- This design addresses critical SQL expression handling issues in the sequel-duckdb adapter where SQL expressions, functions, and literal strings are incorrectly treated as regular string literals and quoted when they should be rendered as raw SQL. The fix involves implementing proper type detection and handling in the `literal_append` method to distinguish between different SQL object types.
6
-
7
- The core issue is that the current adapter implementation doesn't properly handle Sequel's expression objects (`Sequel::LiteralString`, `Sequel::SQL::Function`, etc.) and treats them as regular Ruby strings, causing them to be quoted inappropriately in the generated SQL.
8
-
9
- ## Architecture
10
-
11
- ### Current Problem
12
-
13
- The existing `literal_append` method in the DuckDB adapter handles `String` objects without first checking if they are `Sequel::LiteralString` objects. This causes `LiteralString` objects (created by `Sequel.lit()`) to be treated as regular strings and quoted inappropriately. The method correctly handles `Time` and `DateTime` objects but falls through to `literal_string_append` for all `String` objects, including `LiteralString`.
14
-
15
- ### Solution Architecture
16
-
17
- The solution follows Sequel core's established pattern by checking for `LiteralString` as a special case of `String` before applying string quoting:
18
-
19
- 1. **Sequel Core Pattern Compliance**: Follows the exact pattern used in Sequel core's `literal_append` method
20
- 2. **LiteralString Special Handling**: Checks for `LiteralString` before regular `String` processing
21
- 3. **Minimal Change**: Only adds the missing `LiteralString` check to existing logic
22
- 4. **Parent Delegation**: Continues to delegate `SQL::Function` and other expressions to parent class
23
-
24
- ### Design Pattern
25
-
26
- Following Sequel's adapter pattern, the fix will be implemented in the `DatasetMethods` module within `lib/sequel/adapters/shared/duckdb.rb`, allowing the main `Dataset` class to inherit the corrected behavior through the include mechanism.
27
-
28
- ## Components and Interfaces
29
-
30
- ### Core Component: Enhanced literal_append Method
31
-
32
- **Location**: `Sequel::DuckDB::DatasetMethods` module
33
-
34
- **Interface**:
35
-
36
- ```ruby
37
- def literal_append(sql, v)
38
- case v
39
- when Time
40
- literal_datetime_append(sql, v)
41
- when DateTime
42
- literal_datetime_append(sql, v)
43
- when String
44
- case v
45
- when LiteralString
46
- sql << v # Append directly without quoting
47
- else
48
- if v.encoding == Encoding::ASCII_8BIT
49
- literal_blob_append(sql, v)
50
- else
51
- literal_string_append(sql, v)
52
- end
53
- end
54
- else
55
- super
56
- end
57
- end
58
- ```
59
-
60
- ### Type Handling Components
61
-
62
- #### 1. LiteralString Handler
63
-
64
- - **Purpose**: Process `Sequel.lit()` expressions as raw SQL following Sequel core pattern
65
- - **Behavior**: Append string content directly without quoting (`sql << v`)
66
- - **Input**: `Sequel::LiteralString` objects (subclass of `String`)
67
- - **Output**: Raw SQL string appended to query
68
-
69
- #### 2. Regular String Handler
70
-
71
- - **Purpose**: Process regular Ruby strings with appropriate encoding handling
72
- - **Behavior**: Apply existing binary/text string logic
73
- - **Input**: Regular `String` objects (excluding `LiteralString`)
74
- - **Output**: Properly quoted and escaped string literals
75
-
76
- #### 3. Parent Class Delegation
77
-
78
- - **Purpose**: Handle all other data types including `SQL::Function`
79
- - **Behavior**: Delegate to parent class implementation (which already works correctly)
80
- - **Input**: All other Ruby/Sequel objects including `SQL::Expression` subclasses
81
- - **Output**: Appropriately formatted literals using Sequel core logic
82
-
83
- ### Integration Points
84
-
85
- #### Dataset Class Integration
86
-
87
- The enhanced `literal_append` method integrates with:
88
-
89
- - **SQL Generation Pipeline**: Core Sequel SQL building process
90
- - **Query Context Handling**: SELECT, WHERE, ORDER BY, GROUP BY, HAVING clauses
91
- - **Expression Composition**: Nested and complex expressions
92
-
93
- #### Sequel Framework Integration
94
-
95
- - **Parent Class Delegation**: Leverages existing Sequel functionality
96
- - **Type System Compatibility**: Works with Sequel's expression type hierarchy
97
- - **Error Handling**: Integrates with Sequel's error reporting system
98
-
99
- ## Data Models
100
-
101
- ### Input Data Types
102
-
103
- #### Sequel::LiteralString
104
-
105
- ```ruby
106
- # Created by: Sequel.lit("YEAR(created_at)")
107
- # Properties:
108
- # - Contains raw SQL string
109
- # - Should not be quoted
110
- # - Used for expressions, functions, literals
111
- ```
112
-
113
- #### Sequel::SQL::Function
114
-
115
- ```ruby
116
- # Created by: Sequel.function(:count, :*)
117
- # Properties:
118
- # - Function name and arguments
119
- # - Requires special rendering logic
120
- # - May contain nested expressions
121
- ```
122
-
123
- #### Regular Data Types
124
-
125
- ```ruby
126
- # String, Integer, Float, Date, Time, etc.
127
- # Properties:
128
- # - Standard Ruby types
129
- # - Require appropriate SQL formatting
130
- # - Should be quoted/escaped as needed
131
- ```
132
-
133
- ### Output Data Model
134
-
135
- #### SQL String Buffer
136
-
137
- - **Type**: String (mutable)
138
- - **Content**: Accumulated SQL query text
139
- - **Modification**: Appended to by `literal_append`
140
-
141
- ## Error Handling
142
-
143
- ### Error Categories
144
-
145
- #### 1. Unsupported Expression Types
146
-
147
- - **Scenario**: Unknown SQL expression object encountered
148
- - **Response**: Clear error message with object type information
149
- - **Error Type**: `Sequel::Error` or subclass
150
-
151
- #### 2. Expression Rendering Failures
152
-
153
- - **Scenario**: Function or expression rendering fails
154
- - **Response**: Context-aware error with failing expression details
155
- - **Error Type**: `Sequel::DatabaseError`
156
-
157
- #### 3. SQL Generation Failures
158
-
159
- - **Scenario**: Overall SQL generation fails due to expression issues
160
- - **Response**: Categorized error with query context
161
- - **Error Type**: `Sequel::DatabaseError`
162
-
163
- ### Error Handling Strategy
164
-
165
- ```ruby
166
- def literal_append(sql, v)
167
- case v
168
- when Time
169
- literal_datetime_append(sql, v)
170
- when DateTime
171
- literal_datetime_append(sql, v)
172
- when String
173
- case v
174
- when LiteralString
175
- sql << v
176
- else
177
- if v.encoding == Encoding::ASCII_8BIT
178
- literal_blob_append(sql, v)
179
- else
180
- literal_string_append(sql, v)
181
- end
182
- end
183
- else
184
- super
185
- end
186
- rescue => e
187
- raise Sequel::DatabaseError, "Failed to render SQL literal: #{e.message}"
188
- end
189
- ```
190
-
191
- ## Testing Strategy
192
-
193
- ### Test Categories
194
-
195
- #### 1. Unit Tests - SQL Generation
196
-
197
- - **Framework**: Sequel mock database
198
- - **Purpose**: Test SQL generation without database connections
199
- - **Coverage**: All expression types and combinations
200
- - **Location**: `test/sql_test.rb`
201
-
202
- #### 2. Integration Tests - Database Operations
203
-
204
- - **Framework**: Real DuckDB in-memory databases
205
- - **Purpose**: End-to-end expression functionality
206
- - **Coverage**: Query execution with expressions
207
- - **Location**: `test/dataset_test.rb`
208
-
209
- #### 3. Regression Tests
210
-
211
- - **Purpose**: Ensure backward compatibility
212
- - **Coverage**: Existing functionality continues working
213
- - **Location**: Multiple test files
214
-
215
- ### Test Implementation Approach
216
-
217
- #### Test-Driven Development
218
-
219
- 1. **Write failing tests** for each expression type
220
- 2. **Implement minimal fix** to make tests pass
221
- 3. **Refactor** while maintaining green tests
222
- 4. **Add edge case tests** and handle them
223
-
224
- #### Test Structure
225
-
226
- ```ruby
227
- def test_literal_string_handling
228
- # Test Sequel.lit() expressions
229
- dataset = @db[:users].select(Sequel.lit("YEAR(created_at)"))
230
- assert_equal "SELECT YEAR(created_at) FROM users", dataset.sql
231
- end
232
-
233
- def test_function_handling_still_works
234
- # Test that Sequel.function() calls continue to work (already working)
235
- dataset = @db[:users].select(Sequel.function(:count, :*))
236
- assert_equal "SELECT count(*) FROM users", dataset.sql
237
- end
238
-
239
- def test_regular_string_still_quoted
240
- # Test that regular strings are still properly quoted
241
- dataset = @db[:users].where(name: "John's")
242
- assert_equal "SELECT * FROM users WHERE (name = 'John''s')", dataset.sql
243
- end
244
- ```
245
-
246
- ### Coverage Requirements
247
-
248
- - **100% line coverage** for new `literal_append` method
249
- - **Branch coverage** for all case statements
250
- - **Edge case coverage** for error conditions
251
- - **Integration coverage** for all SQL clause types
252
-
253
- ## Design Decisions and Rationales
254
-
255
- ### Decision 1: Follow Sequel Core Pattern Exactly
256
-
257
- **Rationale**: Sequel core already has the correct pattern for handling `LiteralString` as a special case of `String`. Following this established pattern ensures compatibility and maintainability.
258
-
259
- **Evidence**: Sequel core's `literal_append` method in `/sequel/dataset/sql.rb` shows the exact pattern:
260
-
261
- ```ruby
262
- when String
263
- case v
264
- when LiteralString
265
- sql << v
266
- when SQL::Blob
267
- literal_blob_append(sql, v)
268
- else
269
- literal_string_append(sql, v)
270
- end
271
- ```
272
-
273
- ### Decision 2: Minimal Modification Approach
274
-
275
- **Rationale**: The current implementation already works correctly for most types. Only the `LiteralString` handling is missing, so we add the minimal necessary check.
276
-
277
- **Alternatives Considered**:
278
-
279
- - Complete rewrite of literal_append (rejected - unnecessary and risky)
280
- - Separate method for LiteralString (rejected - doesn't follow Sequel patterns)
281
-
282
- ### Decision 3: No Changes to Function Handling
283
-
284
- **Rationale**: Testing revealed that `SQL::Function` objects already work correctly through parent class delegation. The issue is specifically with `LiteralString` objects being treated as regular strings.
285
-
286
- **Evidence**:
287
-
288
- - `db[:test].select(Sequel.function(:count, :*)).sql` produces correct `"SELECT count(*) FROM test"`
289
- - `db[:test].select(Sequel.lit('YEAR(created_at)')).sql` incorrectly produces `"SELECT 'YEAR(created_at)' FROM test"`
290
-
291
- ### Decision 4: Preserve Existing Time/DateTime/Binary Handling
292
-
293
- **Rationale**: The current implementation correctly handles `Time`, `DateTime`, and binary string encoding. These should remain unchanged.
294
-
295
- **Benefits**:
296
-
297
- - Maintains backward compatibility for existing functionality
298
- - Focuses fix on the specific problem area
299
- - Reduces risk of regression in working features
300
-
301
- ### Decision 5: Integration in DatasetMethods Module
302
-
303
- **Rationale**: Following the established sequel-duckdb pattern where shared functionality is implemented in modules and included in main classes.
304
-
305
- **Benefits**:
306
-
307
- - Consistent with existing codebase architecture
308
- - Allows for easy testing and maintenance
309
- - Follows Sequel adapter conventions
310
-
311
- ## Implementation Phases
312
-
313
- ### Phase 1: Fix LiteralString Handling
314
-
315
- - Modify existing `literal_append` method to check for `LiteralString` before regular `String`
316
- - Add comprehensive unit tests for `LiteralString` handling
317
- - Verify existing functionality remains intact
318
-
319
- ### Phase 2: Comprehensive Testing
320
-
321
- - Add integration tests with real database operations
322
- - Test all SQL clause contexts (SELECT, WHERE, ORDER BY, etc.)
323
- - Add regression tests to ensure no existing functionality breaks
324
-
325
- ### Phase 3: Edge Cases and Error Handling
326
-
327
- - Test complex nested expressions
328
- - Verify error handling for malformed expressions
329
- - Performance verification with existing benchmarks
330
-
331
- This design provides a focused, low-risk solution that addresses the core SQL expression handling issues while maintaining full backward compatibility and following established Sequel adapter patterns.
@@ -1,86 +0,0 @@
1
- # Requirements Document
2
-
3
- ## Introduction
4
-
5
- This specification addresses critical SQL expression handling issues in the sequel-duckdb adapter. The adapter is currently incorrectly treating SQL expressions, functions, and literal strings as regular string literals, causing them to be quoted when they should be rendered as raw SQL. This breaks fundamental SQL generation functionality and prevents proper use of database functions, expressions, and literal SQL.
6
-
7
- ## Requirements
8
-
9
- ### Requirement 1: Sequel::LiteralString Handling
10
-
11
- **User Story:** As a developer using Sequel with DuckDB, I want to use `Sequel.lit()` to include raw SQL expressions in my queries, so that I can use database functions and complex expressions without them being quoted as strings.
12
-
13
- #### Acceptance Criteria
14
-
15
- 1. WHEN I use `Sequel.lit("YEAR(created_at)")` in a SELECT clause THEN the generated SQL SHALL contain `YEAR(created_at)` without quotes
16
- 2. WHEN I use `Sequel.lit("LENGTH(name) > 5")` in a WHERE clause THEN the generated SQL SHALL contain `LENGTH(name) > 5` without quotes
17
- 3. WHEN I use `Sequel.lit("CURRENT_TIMESTAMP")` in an UPDATE clause THEN the generated SQL SHALL contain `CURRENT_TIMESTAMP` without quotes
18
- 4. WHEN I use `Sequel.lit("name || ' ' || email AS full_info")` in a SELECT clause THEN the generated SQL SHALL contain the expression without quotes
19
-
20
- ### Requirement 2: Sequel::SQL::Function Handling
21
-
22
- **User Story:** As a developer using Sequel with DuckDB, I want to use `Sequel.function()` to call database functions, so that function calls are properly generated in SQL without being quoted as strings.
23
-
24
- #### Acceptance Criteria
25
-
26
- 1. WHEN I use `Sequel.function(:count, :*)` THEN the generated SQL SHALL contain `count(*)`
27
- 2. WHEN I use `Sequel.function(:sum, :amount)` THEN the generated SQL SHALL contain `sum(amount)`
28
- 3. WHEN I use `Sequel.function(:year, :created_at)` THEN the generated SQL SHALL contain `year(created_at)`
29
- 4. WHEN I use nested functions like `Sequel.function(:count, Sequel.function(:distinct, :name))` THEN the generated SQL SHALL contain `count(distinct(name))`
30
-
31
- ### Requirement 3: Complex Expression Handling
32
-
33
- **User Story:** As a developer using Sequel with DuckDB, I want to use complex SQL expressions with operators and functions, so that they are properly rendered as SQL without being quoted.
34
-
35
- #### Acceptance Criteria
36
-
37
- 1. WHEN I use expressions with mathematical operators THEN they SHALL be rendered as raw SQL
38
- 2. WHEN I use expressions with string concatenation operators THEN they SHALL be rendered as raw SQL
39
- 3. WHEN I use expressions with comparison operators THEN they SHALL be rendered as raw SQL
40
- 4. WHEN I use expressions with logical operators THEN they SHALL be rendered as raw SQL
41
-
42
- ### Requirement 4: Literal Append Method Override
43
-
44
- **User Story:** As a developer maintaining the sequel-duckdb adapter, I want the `literal_append` method to properly distinguish between different types of SQL objects, so that each type is handled appropriately.
45
-
46
- #### Acceptance Criteria
47
-
48
- 1. WHEN `literal_append` receives a `Sequel::LiteralString` object THEN it SHALL append the string content without quotes
49
- 2. WHEN `literal_append` receives a `Sequel::SQL::Function` object THEN it SHALL delegate to the appropriate function rendering method
50
- 3. WHEN `literal_append` receives a regular String object THEN it SHALL quote it as a string literal
51
- 4. WHEN `literal_append` receives other SQL expression objects THEN it SHALL delegate to the parent class method
52
-
53
- ### Requirement 5: Expression Context Preservation
54
-
55
- **User Story:** As a developer using Sequel with DuckDB, I want SQL expressions to maintain their context when used in different parts of queries, so that they work correctly in SELECT, WHERE, ORDER BY, GROUP BY, and HAVING clauses.
56
-
57
- #### Acceptance Criteria
58
-
59
- 1. WHEN I use expressions in SELECT clauses THEN they SHALL be rendered as raw SQL
60
- 2. WHEN I use expressions in WHERE clauses THEN they SHALL be rendered as raw SQL
61
- 3. WHEN I use expressions in ORDER BY clauses THEN they SHALL be rendered as raw SQL
62
- 4. WHEN I use expressions in GROUP BY clauses THEN they SHALL be rendered as raw SQL
63
- 5. WHEN I use expressions in HAVING clauses THEN they SHALL be rendered as raw SQL
64
- 6. WHEN I use expressions in UPDATE SET clauses THEN they SHALL be rendered as raw SQL
65
-
66
- ### Requirement 6: Backward Compatibility
67
-
68
- **User Story:** As a developer using the sequel-duckdb adapter, I want existing functionality to continue working after expression handling is fixed, so that my current code doesn't break.
69
-
70
- #### Acceptance Criteria
71
-
72
- 1. WHEN I use regular string values in queries THEN they SHALL still be properly quoted as string literals
73
- 2. WHEN I use numeric values in queries THEN they SHALL still be rendered as numeric literals
74
- 3. WHEN I use boolean values in queries THEN they SHALL still be rendered as boolean literals
75
- 4. WHEN I use date/time values in queries THEN they SHALL still be rendered with proper formatting
76
- 5. WHEN I use binary data in queries THEN it SHALL still be rendered as hex literals
77
-
78
- ### Requirement 7: Error Handling
79
-
80
- **User Story:** As a developer using the sequel-duckdb adapter, I want clear error messages when expression handling fails, so that I can debug issues effectively.
81
-
82
- #### Acceptance Criteria
83
-
84
- 1. WHEN an unsupported expression type is encountered THEN a clear error message SHALL be provided
85
- 2. WHEN expression rendering fails THEN the error SHALL include context about the failing expression
86
- 3. WHEN SQL generation fails due to expression issues THEN the error SHALL be properly categorized as a DatabaseError
@@ -1,25 +0,0 @@
1
- # Implementation Plan
2
-
3
- - [x] 1. Write tests for LiteralString handling
4
-
5
- - Add test in `test/sql_test.rb` to verify `Sequel.lit()` expressions are not quoted
6
- - Test LiteralString in SELECT clause: `db[:test].select(Sequel.lit('YEAR(created_at)')).sql`
7
- - Test LiteralString in WHERE clause: `db[:test].where(Sequel.lit('age > 18')).sql`
8
- - Add regression test to ensure regular strings are still quoted properly
9
- - Add test to ensure SQL::Function continues working (should be unchanged)
10
- - _Requirements: 1.1, 1.2, 4.1, 6.1_
11
-
12
- - [x] 2. Fix literal_append method to handle LiteralString
13
-
14
- - Modify existing `literal_append` method in `lib/sequel/adapters/shared/duckdb.rb`
15
- - Add `LiteralString` check as special case of `String` following Sequel core pattern
16
- - Change `when String` to nested case with `when LiteralString` that does `sql << v`
17
- - Preserve all existing logic for Time, DateTime, and binary strings
18
- - _Requirements: 1.1, 4.1, 4.2, 4.4, 6.1_
19
-
20
- - [x] 3. Add integration test with real database
21
-
22
- - Add test in `test/dataset_test.rb` using real DuckDB database
23
- - Test that LiteralString expressions actually execute correctly
24
- - Verify no regression in existing database operations
25
- - _Requirements: 1.2, 5.1, 6.1_
@@ -1,106 +0,0 @@
1
- # Requirements Document
2
-
3
- ## Introduction
4
-
5
- This specification addresses test infrastructure issues in the sequel-duckdb adapter test suite. Many tests are failing due to incorrect assertions, wrong expectations about dataset types, and improper test setup rather than actual functionality problems. The test infrastructure needs to be improved to properly test the adapter's functionality while being flexible about implementation details.
6
-
7
- ## Requirements
8
-
9
- ### Requirement 1: Dataset Type Assertion Fixes
10
-
11
- **User Story:** As a developer maintaining the sequel-duckdb adapter, I want tests to check functionality rather than exact class types, so that tests pass when the adapter works correctly regardless of internal Sequel implementation details.
12
-
13
- #### Acceptance Criteria
14
-
15
- 1. WHEN tests check dataset types THEN they SHALL use `respond_to?` or duck typing instead of exact class matching
16
- 2. WHEN Sequel creates dataset subclasses THEN tests SHALL accept them as valid datasets
17
- 3. WHEN tests verify dataset functionality THEN they SHALL test behavior rather than class hierarchy
18
- 4. WHEN new Sequel versions change internal class structures THEN tests SHALL continue to pass
19
-
20
- ### Requirement 2: Mock Database Configuration
21
-
22
- **User Story:** As a developer running tests for the sequel-duckdb adapter, I want the mock database to properly simulate DuckDB behavior, so that SQL generation tests accurately reflect real adapter behavior.
23
-
24
- #### Acceptance Criteria
25
-
26
- 1. WHEN mock database is created THEN it SHALL include DuckDB-specific dataset methods
27
- 2. WHEN mock database generates SQL THEN it SHALL use DuckDB syntax rules
28
- 3. WHEN mock database handles identifiers THEN it SHALL use DuckDB quoting rules
29
- 4. WHEN mock database processes expressions THEN it SHALL use DuckDB literal handling
30
-
31
- ### Requirement 3: Test Helper Method Improvements
32
-
33
- **User Story:** As a developer writing tests for the sequel-duckdb adapter, I want test helper methods that work correctly with DuckDB's SQL syntax variations, so that I can write reliable tests without worrying about syntax differences.
34
-
35
- #### Acceptance Criteria
36
-
37
- 1. WHEN `assert_sql` helper is used THEN it SHALL handle DuckDB syntax variations gracefully
38
- 2. WHEN SQL comparison is needed THEN helper methods SHALL normalize minor syntax differences
39
- 3. WHEN testing SQL patterns THEN helper methods SHALL support flexible matching
40
- 4. WHEN debugging test failures THEN helper methods SHALL provide clear error messages
41
-
42
- ### Requirement 4: Integration Test Setup
43
-
44
- **User Story:** As a developer running integration tests for the sequel-duckdb adapter, I want proper test database setup and teardown, so that integration tests run reliably and don't interfere with each other.
45
-
46
- #### Acceptance Criteria
47
-
48
- 1. WHEN integration tests run THEN each test SHALL have a clean database state
49
- 2. WHEN tests create tables THEN they SHALL be properly cleaned up after the test
50
- 3. WHEN tests insert data THEN it SHALL not affect other tests
51
- 4. WHEN tests fail THEN database state SHALL be properly reset for subsequent tests
52
-
53
- ### Requirement 5: Test Data Management
54
-
55
- **User Story:** As a developer writing tests for the sequel-duckdb adapter, I want consistent test data setup utilities, so that I can focus on testing functionality rather than data preparation.
56
-
57
- #### Acceptance Criteria
58
-
59
- 1. WHEN tests need sample data THEN standardized helper methods SHALL be available
60
- 2. WHEN tests need specific table schemas THEN reusable setup methods SHALL be provided
61
- 3. WHEN tests need to verify data integrity THEN helper methods SHALL validate expected state
62
- 4. WHEN tests need to clean up data THEN helper methods SHALL ensure complete cleanup
63
-
64
- ### Requirement 6: Error Message Improvements
65
-
66
- **User Story:** As a developer debugging failing tests in the sequel-duckdb adapter, I want clear and informative error messages, so that I can quickly identify and fix issues.
67
-
68
- #### Acceptance Criteria
69
-
70
- 1. WHEN SQL assertion fails THEN the error message SHALL show both expected and actual SQL clearly
71
- 2. WHEN dataset type assertion fails THEN the error message SHALL explain what was expected and why
72
- 3. WHEN database operation fails THEN the error message SHALL include relevant context
73
- 4. WHEN test setup fails THEN the error message SHALL indicate the specific setup step that failed
74
-
75
- ### Requirement 7: Test Organization and Naming
76
-
77
- **User Story:** As a developer maintaining the sequel-duckdb adapter test suite, I want tests to be well-organized and clearly named, so that I can easily understand what each test covers and find relevant tests when debugging.
78
-
79
- #### Acceptance Criteria
80
-
81
- 1. WHEN tests are grouped by functionality THEN the grouping SHALL be logical and consistent
82
- 2. WHEN test methods are named THEN the names SHALL clearly describe what is being tested
83
- 3. WHEN tests cover edge cases THEN they SHALL be clearly identified as such
84
- 4. WHEN tests are added THEN they SHALL follow established naming and organization patterns
85
-
86
- ### Requirement 8: Test Performance Optimization
87
-
88
- **User Story:** As a developer running the sequel-duckdb adapter test suite, I want tests to run quickly and efficiently, so that I can get fast feedback during development.
89
-
90
- #### Acceptance Criteria
91
-
92
- 1. WHEN unit tests run THEN they SHALL complete quickly without database connections
93
- 2. WHEN integration tests run THEN they SHALL use efficient database operations
94
- 3. WHEN test suite runs THEN it SHALL minimize redundant setup and teardown operations
95
- 4. WHEN tests are parallelized THEN they SHALL not interfere with each other
96
-
97
- ### Requirement 9: Test Coverage Validation
98
-
99
- **User Story:** As a developer maintaining the sequel-duckdb adapter, I want to ensure comprehensive test coverage, so that all functionality is properly tested and regressions are caught early.
100
-
101
- #### Acceptance Criteria
102
-
103
- 1. WHEN new functionality is added THEN corresponding tests SHALL be required
104
- 2. WHEN tests are removed THEN coverage impact SHALL be evaluated
105
- 3. WHEN test coverage is measured THEN it SHALL include both unit and integration tests
106
- 4. WHEN coverage gaps are identified THEN they SHALL be prioritized for additional testing
@@ -1,26 +0,0 @@
1
- # Product Overview
2
-
3
- sequel-duckdb is a Ruby gem that provides a complete database adapter for the Sequel toolkit to work with DuckDB. This gem enables Ruby applications to connect to and interact with DuckDB databases through Sequel's comprehensive ORM and database abstraction interface.
4
-
5
- ## Key Features
6
-
7
- - Full DuckDB database adapter for Sequel
8
- - Ruby 3.1+ compatibility
9
- - Complete SQL generation and query support
10
- - Connection management via ruby-duckdb gem
11
- - Comprehensive test coverage for all SQL operations
12
-
13
- ## Reference Projects
14
-
15
- - **jeremyevans/sequel**: Official Sequel repository for coding conventions
16
- - **sequel-hexspace**: Secondary reference for adapter structure
17
- - **sequel_impala**: Tertiary reference for implementation patterns
18
-
19
- ## Target Users
20
-
21
- - Ruby developers using Sequel ORM
22
- - Applications requiring DuckDB integration
23
-
24
- ## Implementation Approach
25
-
26
- This project follows the proven patterns from existing Sequel adapters, with implementation order guided by git history analysis of reference projects. All development is designed to be AI-agent friendly with thorough documentation and incremental implementation.
@@ -1,88 +0,0 @@
1
- # Project Structure
2
-
3
- ## Root Directory
4
-
5
- - **Gemfile**: Dependency specification
6
- - **Rakefile**: Build tasks and automation
7
- - **sequel-duckdb.gemspec**: Gem specification
8
- - **.rubocop.yml**: Code style configuration
9
- - **README.md**: Project documentation
10
- - **CHANGELOG.md**: Version history
11
-
12
- ## Core Library Structure (Following sequel-hexspace Pattern)
13
-
14
- ```text
15
- lib/
16
- └── sequel/
17
- └── adapters/
18
- ├── duckdb.rb # Main adapter file (Database & Dataset classes)
19
- └── shared/
20
- └── duckdb.rb # Shared DuckDB-specific functionality
21
- ```
22
-
23
- ## Organization Patterns
24
-
25
- - **Namespace**: `Sequel::DuckDB` - follows Sequel's adapter pattern exactly like sequel-hexspace
26
- - **Adapter Structure**: Main adapter in `lib/sequel/adapters/duckdb.rb` with Database and Dataset classes
27
- - **Shared Functionality**: Common methods in `lib/sequel/adapters/shared/duckdb.rb` with DatabaseMethods and DatasetMethods modules
28
- - **Database Class**: `Sequel::DuckDB::Database` includes `Sequel::DuckDB::DatabaseMethods` for connection management
29
- - **Dataset Class**: `Sequel::DuckDB::Dataset` includes `Sequel::DuckDB::DatasetMethods` for SQL generation
30
- - **Module Pattern**: Use include pattern exactly like sequel-hexspace to separate concerns between main classes and shared functionality
31
-
32
- ## Development Structure
33
-
34
- - **bin/**: Development executables (console, setup)
35
- - **test/**: Comprehensive test suite following sequel-hexspace pattern
36
- - **sig/**: RBS type signatures for Ruby 3+ type checking
37
- - **.kiro/**: AI assistant configuration and steering rules
38
-
39
- ## File Naming Conventions
40
-
41
- - Use snake_case for file names
42
- - Match file names to adapter names (duckdb.rb for DuckDB adapter)
43
- - Follow sequel-hexspace directory structure exactly
44
- - Standard Ruby gem layout with adapter-specific organization
45
-
46
- ## Key Architectural Decisions
47
-
48
- - **Database Adapter Pattern**: Full Sequel database adapter implementation following sequel-hexspace
49
- - **Reference-Driven Design**: Mirror sequel-hexspace structure and patterns exactly
50
- - **Test-First Development**: Comprehensive test coverage before implementation
51
- - **Incremental Implementation**: Small, clearly defined implementation pieces
52
- - **AI-Agent Friendly**: Thorough documentation for autonomous development
53
-
54
- ## Implementation Order (based on sequel-hexspace git history)
55
-
56
- 1. **Connection Management**: Database connection and basic connectivity
57
- 2. **Schema Operations**: Table creation, modification, introspection
58
- 3. **Basic SQL Generation**: SELECT, INSERT, UPDATE, DELETE operations
59
- 4. **Advanced SQL Features**: JOINs, subqueries, window functions
60
- 5. **DuckDB-Specific Features**: Specialized functions and optimizations
61
- 6. **Performance Optimizations**: Bulk operations, prepared statements
62
-
63
- ## Adding New Features
64
-
65
- - **Research First**: Study sequel-hexspace implementation patterns directly
66
- - **Document Thoroughly**: Create detailed specifications before coding
67
- - **Test-Driven**: Write comprehensive tests first
68
- - **Incremental**: Implement in small, testable pieces
69
- - **Follow Conventions**: Adhere to sequel-hexspace coding standards exactly
70
- - Place main Database and Dataset classes in `lib/sequel/adapters/duckdb.rb`
71
- - Place DatabaseMethods and DatasetMethods modules in `lib/sequel/adapters/shared/duckdb.rb`
72
- - Use include pattern to mix shared functionality into main classes
73
- - Mirror sequel-hexspace file organization and module structure exactly
74
-
75
- ## Testing Structure (Following sequel-hexspace Pattern)
76
-
77
- - **test/all.rb**: Test runner
78
- - **test/spec_helper.rb**: Test configuration and setup
79
- - **test/database_test.rb**: Database connection and basic functionality tests
80
- - **test/dataset_test.rb**: Comprehensive SQL generation tests
81
- - **test/schema_test.rb**: Schema operations and introspection tests
82
- - **test/prepared_statement_test.rb**: Prepared statement functionality
83
- - **test/sql_test.rb**: SQL generation and syntax tests
84
- - **test/type_test.rb**: Data type handling tests
85
- - Mirror sequel-hexspace test organization exactly
86
- - Test all SQL generation comprehensively
87
- - Include integration tests with actual DuckDB instances
88
- - Follow TDD methodology throughout development