StateFetch fetches the state of the specified resource
(ctx context.Context, s *schema.Schema, filter transaction.Filter)
| 1152 | |
| 1153 | //StateFetch fetches the state of the specified resource |
| 1154 | func (tx *Transaction) StateFetchContext(ctx context.Context, s *schema.Schema, filter transaction.Filter) (state transaction.ResourceState, err error) { |
| 1155 | defer tx.measureTime(time.Now(), s.ID, "state_fetch") |
| 1156 | |
| 1157 | if !s.StateVersioning() { |
| 1158 | err = fmt.Errorf("Schema %s does not support state versioning", s.ID) |
| 1159 | return |
| 1160 | } |
| 1161 | cols := makeStateColumns(s) |
| 1162 | q := sq.Select(cols...).From(quote(s.GetDbTableName())) |
| 1163 | q, _ = AddFilterToQuery(s, q, filter, true) |
| 1164 | sql, args, err := q.ToSql() |
| 1165 | if err != nil { |
| 1166 | return |
| 1167 | } |
| 1168 | tx.logQuery(sql, args...) |
| 1169 | rows, err := tx.transaction.QueryxContext(ctx, sql, args...) |
| 1170 | if err != nil { |
| 1171 | return |
| 1172 | } |
| 1173 | defer rows.Close() |
| 1174 | if !rows.Next() { |
| 1175 | err = transaction.ErrResourceNotFound |
| 1176 | return |
| 1177 | } |
| 1178 | data := map[string]interface{}{} |
| 1179 | rows.MapScan(data) |
| 1180 | err = decodeState(data, &state) |
| 1181 | return |
| 1182 | } |
| 1183 | |
| 1184 | //RawTransaction returns raw transaction |
| 1185 | func (tx *Transaction) RawTransaction() *sqlx.Tx { |
no test coverage detected