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

Method Create

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

Source from the content-addressed store, hash-verified

93}
94
95func (d *sqliteModel) Create(ctx context.Context, v interface{}) error {
96 schema, err := d.schema(v)
97 if err != nil {
98 return err
99 }
100 fields := model.StructToMap(schema, v)
101 cols, placeholders, values := buildInsert(schema, fields)
102 query := fmt.Sprintf("INSERT INTO %q (%s) VALUES (%s)", schema.Table, cols, placeholders)
103 _, err = d.db.ExecContext(ctx, query, values...)
104 if err != nil {
105 if strings.Contains(err.Error(), "UNIQUE constraint") || strings.Contains(err.Error(), "PRIMARY KEY") {
106 return model.ErrDuplicateKey
107 }
108 return fmt.Errorf("model/sqlite: create: %w", err)
109 }
110 return nil
111}
112
113func (d *sqliteModel) Read(ctx context.Context, key string, v interface{}) error {
114 schema, err := d.schema(v)

Callers

nothing calls this directly

Calls 5

schemaMethod · 0.95
StructToMapFunction · 0.92
buildInsertFunction · 0.70
ErrorMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected