MCPcopy Create free account
hub / github.com/PostHog/duckgres / insertQueryLogEntries

Function insertQueryLogEntries

server/querylog.go:309–343  ·  view source on GitHub ↗
(ctx context.Context, db *sql.DB, table string, batch []QueryLogEntry)

Source from the content-addressed store, hash-verified

307 return nil
308 }
309 truncated := truncateQuery(*q)
310 return &truncated
311}
312
313// classifyQuery maps a command type string to a query_kind value.
314func classifyQuery(cmdType string) string {
315 switch cmdType {
316 case "SELECT", "SHOW", "TABLE", "VALUES", "EXPLAIN":
317 return "Select"
318 case "INSERT":
319 return "Insert"
320 case "UPDATE":
321 return "Update"
322 case "DELETE":
323 return "Delete"
324 case "CREATE", "ALTER", "DROP", "TRUNCATE":
325 return "DDL"
326 case "COPY":
327 return "Copy"
328 case "BEGIN", "COMMIT", "ROLLBACK", "SET", "RESET", "DISCARD", "DEALLOCATE", "LISTEN", "NOTIFY", "UNLISTEN":
329 return "Utility"
330 default:
331 return "Utility"
332 }
333}
334
335// literalRegexp matches string literals and numeric literals for normalization.
336var literalRegexp = regexp.MustCompile(`'[^']*'|"[^"]*"|\b\d+\.?\d*\b`)
337
338// comparisonBoolNullRegexp matches boolean/null values in comparison expressions.
339var comparisonBoolNullRegexp = regexp.MustCompile(`(=|<>|!=|<=|>=|<|>)\s*(TRUE|FALSE|NULL)\b`)
340
341// normalizeQueryHash computes a FNV-1a hash of a query after collapsing
342// whitespace and replacing literals with placeholders. This groups queries
343// that differ only in parameter values.
344func normalizeQueryHash(query string) int64 {
345 // Collapse whitespace
346 var sb strings.Builder

Callers 2

flushBatchMethod · 0.85
WriteQueryLogEntriesMethod · 0.85

Calls 3

queryLogEntryInsertArgsFunction · 0.85
ExecContextMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected