(ctx context.Context, name string, msgs message.WriteInserts)
| 22 | } |
| 23 | |
| 24 | func (c *Client) WriteTableBatch(ctx context.Context, name string, msgs message.WriteInserts) (err error) { |
| 25 | if len(msgs) == 0 { |
| 26 | return nil |
| 27 | } |
| 28 | |
| 29 | tx, err := c.db.BeginTx(ctx, nil) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | |
| 34 | defer func() { |
| 35 | if err == nil { |
| 36 | err = tx.Commit() |
| 37 | if err != nil { |
| 38 | c.logger.Error().Err(err).Msg("failed to commit transaction") |
| 39 | } |
| 40 | } |
| 41 | if err != nil { |
| 42 | if rollbackErr := tx.Rollback(); rollbackErr != nil { |
| 43 | c.logger.Error().Err(rollbackErr).Str("table", msgs[0].GetTable().Name).Msg("Failed to rollback transaction") |
| 44 | } |
| 45 | } |
| 46 | }() |
| 47 | |
| 48 | for _, msg := range msgs { |
| 49 | err = c.insertMessage(ctx, tx, msg) |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | func (c *Client) insertMessage(ctx context.Context, tx *sql.Tx, m *message.WriteInsert) error { |
| 59 | table := m.GetTable() |
nothing calls this directly
no test coverage detected