MCPcopy Create free account
hub / github.com/micro/go-micro / Update

Method Update

model/postgres/postgres.go:127–148  ·  view source on GitHub ↗
(ctx context.Context, v interface{})

Source from the content-addressed store, hash-verified

125}
126
127func (d *postgresModel) Update(ctx context.Context, v interface{}) error {
128 schema, err := d.schema(v)
129 if err != nil {
130 return err
131 }
132 fields := model.StructToMap(schema, v)
133 key := model.KeyValue(schema, v)
134 setClauses, values := buildUpdate(schema, fields)
135 values = append(values, key)
136 paramIdx := len(values)
137 query := fmt.Sprintf("UPDATE %s SET %s WHERE %s = $%d",
138 quoteIdent(schema.Table), setClauses, quoteIdent(schema.Key), paramIdx)
139 result, err := d.db.ExecContext(ctx, query, values...)
140 if err != nil {
141 return fmt.Errorf("model/postgres: update: %w", err)
142 }
143 n, _ := result.RowsAffected()
144 if n == 0 {
145 return model.ErrNotFound
146 }
147 return nil
148}
149
150func (d *postgresModel) Delete(ctx context.Context, key string, v interface{}) error {
151 schema, err := d.schema(v)

Callers

nothing calls this directly

Calls 6

schemaMethod · 0.95
StructToMapFunction · 0.92
KeyValueFunction · 0.92
quoteIdentFunction · 0.85
buildUpdateFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected