(ctx context.Context, v interface{})
| 93 | } |
| 94 | |
| 95 | func (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 | |
| 113 | func (d *sqliteModel) Read(ctx context.Context, key string, v interface{}) error { |
| 114 | schema, err := d.schema(v) |
nothing calls this directly
no test coverage detected