-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Problem
When iterating over query results that include blob columns (like F32_BLOB vectors), CLibsql::Slice#to_blob throws:
/lib/libsql.rb:167:in `to_blob': uninitialized constant CLibsql::Slice::Blob (NameError)
b = Blob.new self[:ptr].read_string self[:len]
^^^^
Root Cause
In lib/libsql.rb, the Slice class (line 162) is defined inside the CLibsql module. Its to_blob method (line 166-170) calls Blob.new:
def to_blob
b = Blob.new self[:ptr].read_string self[:len]
deinit
b
endHowever, Blob is defined as Libsql::Blob (line 265), not CLibsql::Blob. Ruby's constant lookup searches:
CLibsql::Slice::Blob(not found)CLibsql::Blob(not found)::Blob(not found)
Solution
Change line 167 to use the fully qualified constant:
b = Libsql::Blob.new self[:ptr].read_string self[:len]Reproduction
require 'libsql'
db = Libsql::Database.new(path: 'test.db')
conn = db.connect
# Create table with blob column
conn.execute("CREATE TABLE test (id INTEGER PRIMARY KEY, data BLOB)")
conn.execute("INSERT INTO test (data) VALUES (?)", ["\x00\x01\x02".b])
# This crashes when iterating results with blob columns
conn.query("SELECT * FROM test").each { |row| p row }Workaround
Users can apply this monkey-patch before using blobs:
CLibsql.const_set(:Blob, Libsql::Blob) unless defined?(CLibsql::Blob)Version
turso_libsql 0.2.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels