MCPcopy Create free account
hub / github.com/Permify/permify / GenerateGCQuery

Function GenerateGCQuery

internal/storage/postgres/utils/common.go:88–100  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

86// It constructs a query to delete expired records from the specified table
87// based on the provided value, which represents a transaction ID.
88func 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

Callers 1

common_test.goFile · 0.92

Calls 1

DeleteMethod · 0.65

Tested by

no test coverage detected