MCPcopy Create free account
hub / github.com/cloudwan/gohan / StateFetchContext

Method StateFetchContext

db/sql/sql.go:1154–1182  ·  view source on GitHub ↗

StateFetch fetches the state of the specified resource

(ctx context.Context, s *schema.Schema, filter transaction.Filter)

Source from the content-addressed store, hash-verified

1152
1153//StateFetch fetches the state of the specified resource
1154func (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
1185func (tx *Transaction) RawTransaction() *sqlx.Tx {

Callers 1

StateFetchMethod · 0.95

Calls 10

measureTimeMethod · 0.95
logQueryMethod · 0.95
makeStateColumnsFunction · 0.85
AddFilterToQueryFunction · 0.85
decodeStateFunction · 0.85
StateVersioningMethod · 0.80
GetDbTableNameMethod · 0.80
quoteFunction · 0.70
ErrorfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected