testing/javascript: Add test case for blobs

This commit is contained in:
Pekka Enberg
2025-08-22 10:44:47 +03:00
parent 9aff35e5af
commit a259d123de
2 changed files with 40 additions and 0 deletions

View File

@@ -290,6 +290,26 @@ test.serial("Statement.get() values", async (t) => {
t.deepEqual(await stmt.get(9007199254740991n), [9007199254740991]);
});
test.serial("Statement.get() [blob]", async (t) => {
const db = t.context.db;
// Create table with blob column
await db.exec("CREATE TABLE IF NOT EXISTS blobs (id INTEGER PRIMARY KEY, data BLOB)");
// Test inserting and retrieving blob data
const binaryData = Buffer.from([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64]); // "Hello World"
const insertStmt = await db.prepare("INSERT INTO blobs (data) VALUES (?)");
await insertStmt.run([binaryData]);
// Retrieve the blob data
const selectStmt = await db.prepare("SELECT data FROM blobs WHERE id = 1");
const result = await selectStmt.get();
t.truthy(result, "Should return a result");
t.true(Buffer.isBuffer(result.data), "Should return Buffer for blob data");
t.deepEqual(result.data, binaryData, "Blob data should match original");
});
// ==========================================================================
// Statement.iterate()
// ==========================================================================