Skip to content

Commit 9844a65

Browse files
committed
fix: change SQLTagStore.size from method to getter for API parity with node.js
1 parent 683f74f commit 9844a65

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.3.0] (2025-12-16)
6+
7+
### Changed
8+
9+
- **BREAKING**: `SQLTagStore.size` changed from method to getter for Node.js API parity (Node.js PR #60246)
10+
- Before: `sql.size()`
11+
- After: `sql.size`
12+
513
## [0.2.1] (2025-12-01)
614

715
### Added
@@ -75,5 +83,7 @@ All notable changes to this project will be documented in this file.
7583
- macOS (x64, ARM64)
7684
- Linux (x64, ARM64), (glibc 2.28+, musl)
7785

86+
[0.3.0]: https://github.com/PhotoStructure/node-sqlite/releases/tag/v0.3.0
87+
[0.2.1]: https://github.com/PhotoStructure/node-sqlite/releases/tag/v0.2.1
7888
[0.2.0]: https://github.com/PhotoStructure/node-sqlite/releases/tag/v0.2.0
7989
[0.0.1]: https://github.com/PhotoStructure/node-sqlite/releases/tag/v0.0.1

src/sql-tag-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class SQLTagStore {
4949
/**
5050
* Returns the current number of cached statements.
5151
*/
52-
size(): number {
52+
get size(): number {
5353
return this.cache.size();
5454
}
5555

src/types/sql-tag-store-instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface SQLTagStoreInstance {
1212
/**
1313
* Returns the current number of cached statements.
1414
*/
15-
size(): number;
15+
readonly size: number;
1616
/**
1717
* Clears all cached statements.
1818
*/

test/sql-tag-store.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,26 @@ describe("SQLTagStore Tests", () => {
9191

9292
test("TagStore capacity, size, and clear", () => {
9393
expect(sql.capacity).toBe(10);
94-
expect(sql.size()).toBe(0);
94+
expect(sql.size).toBe(0);
9595

9696
expect(sql.run`INSERT INTO foo (text) VALUES (${"one"})`.changes).toBe(1);
97-
expect(sql.size()).toBe(1);
97+
expect(sql.size).toBe(1);
9898

9999
expect(sql.get`SELECT * FROM foo WHERE text = ${"one"}`).toBeDefined();
100-
expect(sql.size()).toBe(2);
100+
expect(sql.size).toBe(2);
101101

102102
// Using the same template string shouldn't increase the size
103103
expect(sql.get`SELECT * FROM foo WHERE text = ${"two"}`).toBeUndefined();
104-
expect(sql.size()).toBe(2);
104+
expect(sql.size).toBe(2);
105105

106106
expect(
107107
(sql.all`SELECT * FROM foo` as Array<{ id: number; text: string }>)
108108
.length,
109109
).toBe(1);
110-
expect(sql.size()).toBe(3);
110+
expect(sql.size).toBe(3);
111111

112112
sql.clear();
113-
expect(sql.size()).toBe(0);
113+
expect(sql.size).toBe(0);
114114
expect(sql.capacity).toBe(10);
115115
});
116116

@@ -141,7 +141,7 @@ describe("SQLTagStore Tests", () => {
141141

142142
test("evicts finalized statements from cache", () => {
143143
expect(sql.run`INSERT INTO foo (text) VALUES (${"test"})`.changes).toBe(1);
144-
expect(sql.size()).toBe(1);
144+
expect(sql.size).toBe(1);
145145

146146
// Get the cached statement through a different path - directly from db
147147
const stmt = db.prepare("INSERT INTO foo (text) VALUES (?)");
@@ -156,16 +156,16 @@ describe("SQLTagStore Tests", () => {
156156
expect(sql3.run`INSERT INTO foo (text) VALUES (${"cached"})`.changes).toBe(
157157
1,
158158
);
159-
expect(sql3.size()).toBe(1);
159+
expect(sql3.size).toBe(1);
160160

161161
// Get a direct reference to a statement and finalize
162162
// Note: The cached statement is not directly accessible, so we test via size
163163
sql3.clear();
164-
expect(sql3.size()).toBe(0);
164+
expect(sql3.size).toBe(0);
165165

166166
// Re-run should create a new statement
167167
expect(sql3.run`INSERT INTO foo (text) VALUES (${"new"})`.changes).toBe(1);
168-
expect(sql3.size()).toBe(1);
168+
expect(sql3.size).toBe(1);
169169
});
170170

171171
test("LRU eviction when at capacity", () => {
@@ -183,18 +183,18 @@ describe("SQLTagStore Tests", () => {
183183
1,
184184
);
185185
expect(smallSql.get`SELECT * FROM foo WHERE id = ${1}`).toBeDefined();
186-
expect(smallSql.size()).toBe(3);
186+
expect(smallSql.size).toBe(3);
187187

188188
// Add a 4th - should evict the oldest (first INSERT into foo)
189189
expect(smallSql.all`SELECT * FROM bar`.length).toBe(1);
190-
expect(smallSql.size()).toBe(3);
190+
expect(smallSql.size).toBe(3);
191191

192192
// Verify LRU behavior - the INSERT into foo should be evicted
193193
// Accessing it again should add it back
194194
expect(smallSql.run`INSERT INTO foo (text) VALUES (${"c"})`.changes).toBe(
195195
1,
196196
);
197-
expect(smallSql.size()).toBe(3);
197+
expect(smallSql.size).toBe(3);
198198
});
199199

200200
test("statement finalized property works", () => {

0 commit comments

Comments
 (0)