@@ -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
1213Collaborators:
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
2022Public 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
3239Example:
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+
4761Internal 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
5166Implementation 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"
6076Class {
6177 #name : #PqDatabase ,
0 commit comments