Skip to content

Commit 2a011de

Browse files
mumezclaude
andcommitted
Update class comments for PqDatabase and PqCursor
Add codec-related documentation: - PqDatabase: codec API, collaborators, examples, implementation notes - PqCursor: codec methods, collaborators, codec iteration example Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8adc35e commit 2a011de

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

repository/PunQLite-DB/PqCursor.class.st

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ Responsibility:
77
- Enable seeking to specific keys with exact match, greater-than, or less-than semantics
88
- Allow reading and deletion of entries at the current cursor position
99
- Implement standard Smalltalk enumeration protocol (do:, reverseDo:)
10+
- Support codec-based value decoding during iteration
1011
1112
Collaborators:
12-
- PqDatabase: The database I iterate over, provides handle and settings
13+
- PqDatabase: The database I iterate over, provides handle, settings, and codec
1314
- UnQLiteFFI: Makes low-level cursor FFI calls (init, seek, next, prev, release)
1415
- UnQLiteFetchCallback: Used for callback-based data retrieval
16+
- PqCodec: Decodes values when using codec-aware retrieval methods
1517
- UnQLiteConstants: Provides cursor positioning constants (CURSOR_MATCH_*)
1618
1719
Public API and Key Messages:
@@ -25,6 +27,8 @@ Public API and Key Messages:
2527
- #seek:untilEndDo: - Seek to key and iterate forward from there
2628
- #currentKey, #currentValue - Read data at current position
2729
- #currentStringKey, #currentStringValue - Read as strings
30+
- #currentValueIntoDecoded: - Read and decode value using database's codec
31+
- #currentValueInto:by: - Read and decode value using specified codec
2832
- #deleteCurrent - Delete entry at current position
2933
- #close - Release cursor resources
3034
@@ -42,6 +46,14 @@ Example:
4246
""Iterates over 'banana' and 'cherry'""
4347
Transcript show: c currentStringKey; cr]].
4448
49+
""Codec-based iteration""
50+
db := PqDatabase openOnMemory.
51+
db codec: PqJsonCodec new.
52+
db storeAt: 'data' valueEncoded: #('a' 'b' 'c').
53+
db cursorDo: [:cursor |
54+
cursor do: [:c |
55+
c currentValueIntoDecoded: [:value | Transcript show: value printString; cr]]].
56+
4557
Internal Representation:
4658
- database - The PqDatabase being iterated
4759
- handle - Native unqlite_kv_cursor* pointer (inherited from PqObject)
@@ -55,6 +67,7 @@ Implementation Points:
5567
- CURSOR_MATCH_GE and CURSOR_MATCH_LE provide range query support
5668
- Callback-based retrieval is available via #currentKeyInto: and #currentValueInto:
5769
- Buffer size for key/value retrieval defaults to database's fetchBufferSize
70+
- Codec for decoding is obtained from the associated database instance
5871
"
5972
Class {
6073
#name : #PqCursor,

repository/PunQLite-DB/PqDatabase.class.st

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ Responsibility:
88
- Create and manage cursors for efficient iteration
99
- Provide access to Jx9 scripting engine and JSON document collections
1010
- Handle data marshalling between Smalltalk objects and byte arrays
11+
- Support pluggable codecs for transparent object serialization
1112
1213
Collaborators:
1314
- UnQLiteFFI: Makes low-level FFI calls for all database operations
1415
- PqCursor: Created via #newCursor for efficient database iteration
1516
- PqCollection: Created via #collectionName: for JSON document storage
1617
- PqJx9Executer: Created via #jx9 for Jx9 script execution
1718
- PqValueAppender: Created via #appenderAt: for efficient value appending
19+
- PqCodec: Encodes/decodes values (PqUtf8Codec, PqJsonCodec, PqFuelCodec)
1820
- UnQLiteConstants: Provides mode constants and return codes
1921
2022
Public API and Key Messages:
@@ -28,6 +30,11 @@ Public API and Key Messages:
2830
- #newCursor - Create a cursor for efficient scanning
2931
- #transact: - Execute a block within a manual transaction
3032
- #close - Close database and release native resources
33+
- #codec, #codec: - Get/set the codec for value encoding/decoding
34+
- #storeAt:valueEncoded: - Store a value using the default codec
35+
- #fetchAt:intoDecoded: - Fetch and decode a value using the default codec
36+
- #storeAt:value:by: - Store a value using a specified codec
37+
- #fetchAt:into:by: - Fetch and decode a value using a specified codec
3138
3239
Example:
3340
""Basic key-value operations""
@@ -44,9 +51,17 @@ Example:
4451
db cursorDo: [:cursor |
4552
cursor do: [:c | Transcript show: c currentStringKey, ' => ', c currentStringValue; cr]].
4653
54+
""Using codec for object serialization""
55+
db := PqDatabase openOnMemory.
56+
db codec: PqJsonCodec new.
57+
db storeAt: 'users' valueEncoded: #('Alice' 'Bob' 'Charlie').
58+
db fetchAt: 'users' intoDecoded: [:users | users do: [:u | Transcript show: u; cr]].
59+
db close.
60+
4761
Internal Representation:
4862
- Inherits handle from PqObject - points to unqlite* database handle
4963
- handleIsValid - tracks whether database is open
64+
- codec - PqCodec instance for value encoding/decoding (lazy initialized)
5065
5166
Implementation Points:
5267
- Keys and values are stored as byte arrays (UTF-8 for strings)
@@ -56,6 +71,7 @@ Implementation Points:
5671
- Always call #close to release native resources (use #ensure: in production)
5772
- Cursors become invalid after database modifications
5873
- Fetch operations may need larger buffer sizes for large values (see #fetchBufferSize:)
74+
- Default codec is PqUtf8Codec, configurable via PqSettings>>defaultCodecClassName
5975
"
6076
Class {
6177
#name : #PqDatabase,

0 commit comments

Comments
 (0)