mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
testing/javascript: Add test case for blobs
This commit is contained in:
@@ -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()
|
||||
// ==========================================================================
|
||||
|
||||
Reference in New Issue
Block a user