GenerateGCQuery generates a Squirrel DELETE query builder for garbage collection. It constructs a query to delete expired records from the specified table based on the provided value, which represents a transaction ID.
(sl squirrel.StatementBuilderType, table string, value uint64)
| 86 | // It constructs a query to delete expired records from the specified table |
| 87 | // based on the provided value, which represents a transaction ID. |
| 88 | func GenerateGCQuery(sl squirrel.StatementBuilderType, table string, value uint64) squirrel.DeleteBuilder { |
| 89 | // Create a Squirrel DELETE builder for the specified table. |
| 90 | deleteBuilder := sl.Delete(table) |
| 91 | |
| 92 | // Create an expression to check if 'expired_tx_id' is not equal to ActiveRecordTxnID (expired records). |
| 93 | expiredNotActiveExpr := squirrel.Expr("expired_tx_id <> ?::xid8", ActiveRecordTxnID) |
| 94 | |
| 95 | // Create an expression to check if 'expired_tx_id' is less than the provided value (before the cutoff). |
| 96 | beforeExpr := squirrel.Expr("expired_tx_id < ?::xid8", value) |
| 97 | |
| 98 | // Add the WHERE clauses to the DELETE query builder to filter and delete expired data. |
| 99 | return deleteBuilder.Where(expiredNotActiveExpr).Where(beforeExpr) |
| 100 | } |
| 101 | |
| 102 | // GenerateGCQueryForTenant generates a Squirrel DELETE query builder for tenant-aware garbage collection. |
| 103 | // It constructs a query to delete expired records from the specified table for a specific tenant |