diff --git a/internal/storage/postgres/action.go b/internal/storage/postgres/action.go index 74b4d0e..9cf8010 100644 --- a/internal/storage/postgres/action.go +++ b/internal/storage/postgres/action.go @@ -56,45 +56,47 @@ func (a *Action) ByTxId(ctx context.Context, txId uint64, limit, offset int) (ac } func (a *Action) ByAddress(ctx context.Context, addressId uint64, filters storage.AddressActionsFilter) (actions []storage.AddressAction, err error) { - query := a.DB().NewSelect(). + subQuery := a.DB().NewSelect(). Model((*storage.AddressAction)(nil)). Where("address_id = ?", addressId) if filters.ActionTypes.Bits > 0 { - query = query.Where("action_type IN (?)", bun.In(filters.ActionTypes.Strings())) + subQuery = subQuery.Where("action_type IN (?)", bun.In(filters.ActionTypes.Strings())) } - query = sortScope(query, "action_id", filters.Sort) - query = limitScope(query, filters.Limit) - query = offsetScope(query, filters.Offset) + subQuery = sortScope(subQuery, "action_id", filters.Sort) + subQuery = limitScope(subQuery, filters.Limit) + subQuery = offsetScope(subQuery, filters.Offset) - err = a.DB().NewSelect(). - TableExpr("(?) as address_action", query). + query := a.DB().NewSelect(). + TableExpr("(?) as address_action", subQuery). ColumnExpr("address_action.*"). ColumnExpr("action.id as action__id, action.height as action__height, action.time as action__time, action.position as action__position, action.type as action__type, action.tx_id as action__tx_id, action.data as action__data"). ColumnExpr("tx.hash as tx__hash"). Join("left join tx on tx.id = address_action.tx_id"). - Join("left join action on action.id = address_action.action_id"). - Scan(ctx, &actions) + Join("left join action on action.id = address_action.action_id") + query = sortScope(query, "action_id", filters.Sort) + err = query.Scan(ctx, &actions) return } func (a *Action) ByRollup(ctx context.Context, rollupId uint64, limit, offset int, sort sdk.SortOrder) (actions []storage.RollupAction, err error) { - query := a.DB().NewSelect(). + subQuery := a.DB().NewSelect(). Model((*storage.RollupAction)(nil)). Where("rollup_id = ?", rollupId) - query = sortScope(query, "action_id", sort) - query = limitScope(query, limit) - query = offsetScope(query, offset) + subQuery = sortScope(subQuery, "action_id", sort) + subQuery = limitScope(subQuery, limit) + subQuery = offsetScope(subQuery, offset) - err = a.DB().NewSelect(). - TableExpr("(?) as rollup_action", query). + query := a.DB().NewSelect(). + TableExpr("(?) as rollup_action", subQuery). ColumnExpr("rollup_action.*"). ColumnExpr("action.id as action__id, action.height as action__height, action.time as action__time, action.position as action__position, action.type as action__type, action.tx_id as action__tx_id, action.data as action__data"). ColumnExpr("tx.hash as tx__hash"). Join("left join tx on tx.id = rollup_action.tx_id"). - Join("left join action on action.id = rollup_action.action_id"). - Scan(ctx, &actions) + Join("left join action on action.id = rollup_action.action_id") + query = sortScope(query, "action_id", sort) + err = query.Scan(ctx, &actions) return }