|
2 | 2 |
|
3 | 3 | All notable changes to this project will be documented in this file. |
4 | 4 |
|
| 5 | +## [1.0.1] - 2025-10-22 |
| 6 | + |
| 7 | +### Patch Release - API Simplification |
| 8 | + |
| 9 | +Removed deprecated utility methods from Query class to simplify the API surface. This is a breaking change for code using the removed methods, but the core API remains stable. |
| 10 | + |
| 11 | +### Removed Methods |
| 12 | + |
| 13 | +The following utility methods have been removed to simplify the API surface: |
| 14 | + |
| 15 | +- `Query.getPositionalSql()` - No longer needed, Bun uses named parameters natively |
| 16 | +- `Query.getNamedParams()` - Replaced by simplified `getParams()` |
| 17 | +- `Query.getPlaceholders()` - Internal implementation detail, not needed in public API |
| 18 | +- `Query.hasParams()` - Check `Object.keys(getParams()).length > 0` instead |
| 19 | +- `Query.getParamCount()` - Check `Object.keys(getParams()).length` instead |
| 20 | +- `Query.bind()` - Use `Query.create()` with updated params instead |
| 21 | +- `Query.withParams()` - Use `Query.create()` with new params instead |
| 22 | +- `Query.debug()` - Not essential for production use |
| 23 | +- `Query.validate()` - Let SQLite handle validation on execution |
| 24 | + |
| 25 | +--- |
| 26 | + |
5 | 27 | ## [1.0.0] - 2025-10-22 |
6 | 28 |
|
7 | 29 | ### Breaking Changes |
8 | 30 |
|
9 | | -The Query class API has been simplified to leverage Bun's native SQLite named parameter support. This is a **major version bump** requiring code updates for users of previous versions. |
| 31 | +The Query class API has been significantly simplified to focus on core functionality and better leverage Bun's native SQLite named parameter support. |
10 | 32 |
|
11 | 33 | #### Removed Methods |
12 | 34 |
|
13 | | -- `Query.getPositionalSql()` - No longer needed, removed positional SQL conversion |
14 | | -- `Query.getParams()` returning `unknown[]` - Replaced with new `getParams()` returning object |
| 35 | +The following utility methods have been removed to simplify the API surface: |
| 36 | + |
| 37 | +- `Query.getPositionalSql()` - No longer needed, Bun uses named parameters natively |
| 38 | +- `Query.getNamedParams()` - Replaced by simplified `getParams()` |
| 39 | +- `Query.getPlaceholders()` - Internal implementation detail, not needed in public API |
| 40 | +- `Query.hasParams()` - Check `Object.keys(getParams()).length > 0` instead |
| 41 | +- `Query.getParamCount()` - Check `Object.keys(getParams()).length` instead |
| 42 | +- `Query.bind()` - Use `Query.create()` with updated params instead |
| 43 | +- `Query.withParams()` - Use `Query.create()` with new params instead |
| 44 | +- `Query.debug()` - Not essential for production use |
| 45 | +- `Query.validate()` - Let SQLite handle validation on execution |
15 | 46 |
|
16 | | -#### Renamed Methods |
| 47 | +#### Simplified API |
17 | 48 |
|
18 | | -- `Query.getOriginalSql()` → `Query.getSql()` |
19 | | -- `Query.getNamedParams()` → `Query.getParams()` |
| 49 | +The Query class now exposes only essential methods: |
| 50 | + |
| 51 | +```typescript |
| 52 | +// Factory methods |
| 53 | +Query.create(sql: string, params?: Record<string, unknown>): Result<Query> |
| 54 | +Query.simple(sql: string): Result<Query> |
| 55 | + |
| 56 | +// Getters |
| 57 | +query.getSql(): string // SQL with :paramName syntax |
| 58 | +query.getParams(): Record<string, unknown> // Parameters object |
| 59 | +``` |
20 | 60 |
|
21 | 61 | #### Benefits |
22 | 62 |
|
23 | | -- ✅ Simpler API - No "original" vs "positional" confusion |
24 | | -- ✅ Better readability - Method names are now self-explanatory |
25 | | -- ✅ Cleaner code - Direct use of Bun's native named parameter support |
26 | | -- ✅ Type safety - Parameters now always passed as objects, never arrays |
| 63 | +- ✅ **Minimal API Surface** - Only 2 factory methods + 2 getters |
| 64 | +- ✅ **Direct Bun Integration** - Uses Bun's native named parameter support |
| 65 | +- ✅ **Type Safety** - Parameters always passed as objects, never arrays |
| 66 | +- ✅ **Reduced Complexity** - No parameter conversion needed |
| 67 | +- ✅ **Cleaner Code** - Direct integration with database operations |
| 68 | +- ✅ **Immutability** - All getters return copies, not references |
| 69 | + |
| 70 | +#### Migration Guide |
27 | 71 |
|
28 | | -### Migration Guide |
| 72 | +If you were using the removed methods, here's how to migrate: |
29 | 73 |
|
30 | | -**Before:** |
| 74 | +**Parameter Binding (before: `bind()`)** |
31 | 75 | ```typescript |
32 | | -const query = Query.create("SELECT * FROM users WHERE email = :email", { email: "test@example.com" }) |
33 | | -const stmt = db.prepare(query.getPositionalSql()) |
34 | | -const result = stmt.get(...query.getParams()) // Spread array |
| 76 | +// Before |
| 77 | +const query1 = Query.create(sql, { email: "old@example.com", status: "active" }) |
| 78 | +const query2 = query1.bind("email", "new@example.com") |
| 79 | + |
| 80 | +// After - simply create a new query with updated params |
| 81 | +const query = Query.create(sql, { email: "new@example.com", status: "active" }) |
35 | 82 | ``` |
36 | 83 |
|
37 | | -**After:** |
| 84 | +**Parameter Replacement (before: `withParams()`)** |
38 | 85 | ```typescript |
39 | | -const query = Query.create("SELECT * FROM users WHERE email = :email", { email: "test@example.com" }) |
40 | | -const stmt = db.prepare(query.getSql()) |
41 | | -const result = stmt.get(query.getParams()) // Pass object directly |
| 86 | +// Before |
| 87 | +const query1 = Query.create(sql, { email: "user1@example.com" }) |
| 88 | +const query2 = query1.withParams({ email: "user2@example.com" }) |
| 89 | + |
| 90 | +// After - create a new query directly |
| 91 | +const query = Query.create(sql, { email: "user2@example.com" }) |
| 92 | +``` |
| 93 | + |
| 94 | +**Checking for Parameters (before: `hasParams()` / `getParamCount()`)** |
| 95 | +```typescript |
| 96 | +// Before |
| 97 | +if (query.hasParams()) { ... } |
| 98 | +const count = query.getParamCount() |
| 99 | + |
| 100 | +// After |
| 101 | +const params = query.getParams() |
| 102 | +if (Object.keys(params).length > 0) { ... } |
| 103 | +const count = Object.keys(params).length |
| 104 | +``` |
| 105 | + |
| 106 | +**Getting Placeholder Names (before: `getPlaceholders()`)** |
| 107 | +```typescript |
| 108 | +// Before |
| 109 | +const placeholders = query.getPlaceholders() |
| 110 | + |
| 111 | +// After - use Object.keys() on params |
| 112 | +const paramNames = Object.keys(query.getParams()) |
42 | 113 | ``` |
43 | 114 |
|
44 | | -### Updated Methods Automatically |
45 | | - |
46 | | -The following `BaseRepository` methods have been updated internally to use the new Query API: |
47 | | - |
48 | | -- `findById()` |
49 | | -- `findAll()` |
50 | | -- `findByQuery()` |
51 | | -- `findOneByQuery()` |
52 | | -- `count()` |
53 | | -- `countByQuery()` |
54 | | -- `exists()` |
55 | | -- `queryRaw()` |
56 | | -- `update()` |
57 | | -- `delete()` |
58 | | -- `deleteById()` |
59 | | -- `insert()` |
| 115 | +### Updated Components |
| 116 | + |
| 117 | +The following `BaseRepository` methods have been updated to use the simplified Query API: |
| 118 | + |
| 119 | +- `findById()` - Uses `getSql()` and `getParams()` |
| 120 | +- `findByQuery()` - Uses `getSql()` and `getParams()` |
| 121 | +- `findOneByQuery()` - Uses `getSql()` and `getParams()` |
| 122 | +- `countByQuery()` - Uses `getSql()` and `getParams()` |
| 123 | +- `exists()` - Uses `getSql()` and `getParams()` |
| 124 | +- `queryRaw()` - Uses `getSql()` and `getParams()` |
| 125 | +- `update()` - Uses `getSql()` and `getParams()` |
| 126 | +- `delete()` - Uses `getSql()` and `getParams()` |
| 127 | +- `deleteById()` - Uses `getSql()` and `getParams()` |
| 128 | +- `insert()` - Uses `getSql()` and `getParams()` |
| 129 | +- `insertWithId()` - Uses `getParams()` for ID validation |
60 | 130 |
|
61 | 131 | No code changes needed for these methods - they work the same from the caller's perspective. |
62 | 132 |
|
|
0 commit comments