@@ -25,7 +25,7 @@ import Test.Spec.Reporter.Console (consoleReporter)
2525import Test.Spec.Runner (runSpec)
2626import Type.Function (type (#))
2727import Type.Proxy (Proxy(..))
28−import Test.Sqlite.TempDb (mkTempDbUrl)
28+import Test.Sqlite.TempDb (mkTempDbUrl, testBytes, uint8ArrayValues)
2929import Yoga.JSON (class ReadForeign, readImpl, unsafeStringify)
3030import Yoga.SQLite.SQLite as SQLite
3131import Yoga.SQLite.Schema
@@ -108,6 +108,14 @@ type F64DocsTable = Table "f64docs"
108108f64DocsTable :: Proxy F64DocsTable
109109f64DocsTable = Proxy
110110
111+type BlobsTable = Table "blobs"
112+ ( id :: Int # PrimaryKey # AutoIncrement
113+ , body :: Blob
114+ )
115+
116+blobsTable :: Proxy BlobsTable
117+blobsTable = Proxy
118+
111119type RandomRowIdTable = Table "things"
112120 ( id :: Int # PrimaryKey # RandomRowId
113121 , name :: String
@@ -479,6 +487,10 @@ spec = before setupConn do
479487 let result = createTableDDL @LinkedCodesTable
480488 result `shouldEqual` "CREATE TABLE linked_codes (code TEXT NOT NULL REFERENCES codes(code), id INTEGER PRIMARY KEY AUTOINCREMENT)"
481489
490+ it "derives BLOB columns from Blob" \_ -> do
491+ let result = createTableDDL @BlobsTable
492+ result `shouldEqual` "CREATE TABLE blobs (body BLOB NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT)"
493+
482494 describe "SQL builder output" do
483495 it "SELECT *" \_ -> do
484496 toSQL typedSelectAll `shouldEqual` "SELECT * FROM users"
@@ -700,6 +712,13 @@ spec = before setupConn do
700712 let result = map (\r -> unF64Vector r.embedding) (rows :: Array { id :: Int, title :: String, embedding :: F64Vector "3" })
701713 result `shouldEqual` [[1.0, 2.0, 3.0]]
702714
715+ it "round-trips a sliced Uint8Array as one BLOB" \conn -> do
716+ SQLite.executeSimple (SQLite.SQL (createTableDDL @BlobsTable)) conn # void
717+ runExecute conn {} (from blobsTable # insert { body: blobFromUint8Array testBytes }) # void
718+ rows <- runQuery conn {} (from blobsTable # selectAll)
719+ let values = map (uint8ArrayValues <<< blobToUint8Array <<< _.body) (rows :: Array { id :: Int, body :: Blob })
720+ values `shouldEqual` [ [ 0, 1, 2, 127, 128, 255 ] ]
721+
703722 it "columnTypes populated after query" \conn -> do
704723 SQLite.executeSimple (SQLite.SQL (createTableDDL @UsersTable)) conn # void
705724 runExecute conn {} (from usersTable # insert { name: "Alice", email: "a@b.com", age: Just 30 }) # void