mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
- Test that log option can be set on SQL connections - Verify SQLite operations work with logging enabled/disabled - Test boolean values for log option are accepted 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { test, expect } from "bun:test";
|
|
import { tempDirWithFiles } from "harness";
|
|
|
|
test("SQL logging option can be set and passed to adapters", async () => {
|
|
// Test SQLite logging option
|
|
try {
|
|
const sql = new Bun.SQL(":memory:", { log: true });
|
|
expect(sql).toBeDefined();
|
|
|
|
// Verify we can create tables and run queries
|
|
await sql`CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)`;
|
|
await sql`INSERT INTO users (name) VALUES ('Alice')`;
|
|
const users = await sql`SELECT * FROM users`;
|
|
expect(users).toHaveLength(1);
|
|
expect(users[0].name).toBe("Alice");
|
|
} catch (error) {
|
|
console.error("SQLite logging test failed:", error);
|
|
throw error;
|
|
}
|
|
|
|
// Test that log: false works (default case)
|
|
try {
|
|
const sqlNoLog = new Bun.SQL(":memory:", { log: false });
|
|
expect(sqlNoLog).toBeDefined();
|
|
await sqlNoLog`CREATE TABLE test (id INTEGER)`;
|
|
} catch (error) {
|
|
console.error("SQLite no-logging test failed:", error);
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
test("SQL logging option accepts boolean values", () => {
|
|
// Test that log option can be true
|
|
expect(() => new Bun.SQL(":memory:", { log: true })).not.toThrow();
|
|
|
|
// Test that log option can be false
|
|
expect(() => new Bun.SQL(":memory:", { log: false })).not.toThrow();
|
|
|
|
// Test that log option can be undefined (defaults to false)
|
|
expect(() => new Bun.SQL(":memory:", {})).not.toThrow();
|
|
expect(() => new Bun.SQL(":memory:")).not.toThrow();
|
|
}); |