(ctx context.Context, v interface{})
| 91 | } |
| 92 | |
| 93 | func (d *postgresModel) Create(ctx context.Context, v interface{}) error { |
| 94 | schema, err := d.schema(v) |
| 95 | if err != nil { |
| 96 | return err |
| 97 | } |
| 98 | fields := model.StructToMap(schema, v) |
| 99 | cols, placeholders, values := buildInsert(schema, fields) |
| 100 | query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", quoteIdent(schema.Table), cols, placeholders) |
| 101 | _, err = d.db.ExecContext(ctx, query, values...) |
| 102 | if err != nil { |
| 103 | if strings.Contains(err.Error(), "duplicate key") || strings.Contains(err.Error(), "unique constraint") { |
| 104 | return model.ErrDuplicateKey |
| 105 | } |
| 106 | return fmt.Errorf("model/postgres: create: %w", err) |
| 107 | } |
| 108 | return nil |
| 109 | } |
| 110 | |
| 111 | func (d *postgresModel) Read(ctx context.Context, key string, v interface{}) error { |
| 112 | schema, err := d.schema(v) |
nothing calls this directly
no test coverage detected