MCPcopy Index your code
hub / github.com/micro/go-micro / Update

Method Update

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected