Implement zero-cost SQL query logging for MySQL, Postgres, and SQLite

- Add log: boolean option to SQL.Options types
- Implement ActiveRecord-style logging with Output.prettyln in Zig
- Add timing information to track query duration
- Enable logging for all three database adapters:
  - MySQL: Added to MySQLQuery.zig with timing in doRun/onResult/onWriteFail
  - PostgreSQL: Added to PostgresSQLQuery.zig with timing in doRun/onResult/onWriteFail
  - SQLite: Added to sqlite.ts using performance.now() and console.log
- Zero-cost when disabled - only activates when log: true
- Single-line output format: [**ADAPTER**] (duration) SQL [values]

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2025-08-28 04:51:43 +00:00
parent 3545cca8cc
commit 6082b33437
12 changed files with 161 additions and 0 deletions

View File

@@ -695,6 +695,7 @@ pub fn call(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JS
const connection_timeout = arguments[12].toInt32();
const max_lifetime = arguments[13].toInt32();
const use_unnamed_prepared_statements = arguments[14].asBoolean();
const log_enabled = if (arguments.len > 15) arguments[15].asBoolean() else false;
const ptr: *PostgresSQLConnection = try bun.default_allocator.create(PostgresSQLConnection);
@@ -719,6 +720,7 @@ pub fn call(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JS
.max_lifetime_interval_ms = @intCast(max_lifetime),
.flags = .{
.use_unnamed_prepared_statements = use_unnamed_prepared_statements,
.log_enabled = log_enabled,
},
};