StopContext drains remaining entries until ctx expires, then closes the DB to unblock any in-flight flush.
(ctx context.Context)
| 234 | ctx = context.Background() |
| 235 | } |
| 236 | |
| 237 | var sb strings.Builder |
| 238 | if table == "" { |
| 239 | table = "query_log" |
| 240 | } |
| 241 | // Column list, placeholder count, and argument order all come from the |
| 242 | // single registry in querylog_schema.go so they cannot drift apart. |
| 243 | colsPerRow := len(queryLogEntryColumns()) |
| 244 | sb.WriteString("INSERT INTO ") |
| 245 | sb.WriteString(table) |
| 246 | sb.WriteString(" (") |
| 247 | sb.WriteString(strings.Join(queryLogEntryColumnNames(), ", ")) |
| 248 | sb.WriteString(") VALUES ") |
| 249 | |
| 250 | args := make([]any, 0, len(batch)*colsPerRow) |
| 251 | for i, e := range batch { |
| 252 | if i > 0 { |
| 253 | sb.WriteString(", ") |
| 254 | } |
| 255 | base := i * colsPerRow |
| 256 | sb.WriteByte('(') |
| 257 | for col := range colsPerRow { |
| 258 | if col > 0 { |
| 259 | sb.WriteByte(',') |
| 260 | } |
| 261 | fmt.Fprintf(&sb, "$%d", base+col+1) |
| 262 | } |
| 263 | sb.WriteByte(')') |