GenerateGCQueryForTenant generates a Squirrel DELETE query builder for tenant-aware garbage collection. It constructs a query to delete expired records from the specified table for a specific tenant based on the provided value, which represents a transaction ID.
(sl squirrel.StatementBuilderType, table, tenantID string, value uint64)
| 103 | // It constructs a query to delete expired records from the specified table for a specific tenant |
| 104 | // based on the provided value, which represents a transaction ID. |
| 105 | func GenerateGCQueryForTenant(sl squirrel.StatementBuilderType, table, tenantID string, value uint64) squirrel.DeleteBuilder { |
| 106 | // Create a Squirrel DELETE builder for the specified table. |
| 107 | deleteBuilder := sl.Delete(table) |
| 108 | |
| 109 | // Create an expression to check if 'expired_tx_id' is not equal to ActiveRecordTxnID (expired records). |
| 110 | expiredNotActiveExpr := squirrel.Expr("expired_tx_id <> ?::xid8", ActiveRecordTxnID) |
| 111 | |
| 112 | // Create an expression to check if 'expired_tx_id' is less than the provided value (before the cutoff). |
| 113 | beforeExpr := squirrel.Expr("expired_tx_id < ?::xid8", value) |
| 114 | |
| 115 | // Add the WHERE clauses to the DELETE query builder to filter and delete expired data for the specific tenant. |
| 116 | return deleteBuilder.Where(squirrel.Eq{"tenant_id": tenantID}).Where(expiredNotActiveExpr).Where(beforeExpr) |
| 117 | } |
| 118 | |
| 119 | // HandleError records an error in the given span, logs the error, and returns a standardized error. |
| 120 | // This function is used for consistent error handling across different parts of the application. |
no test coverage detected