Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions internal/contact/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,26 @@ func (r *Repository) GetByEmail(email string) (*Contact, error) {
}

func insertTagIfNotExist(txn *sql.Tx, tags []Tag) error {
// todo: implement bulk inserts here
for _, tag := range tags {
_, err := txn.Exec(`INSERT OR IGNORE INTO tags (text) VALUES (?)`, tag.Text)
if err != nil {
return fmt.Errorf("failed to insert tag: %w", err)
}
if len(tags) == 0 {
return nil
}

placeholders := make([]string, len(tags))
args := make([]interface{}, len(tags))

for i, tag := range tags {
placeholders[i] = "(?)"
args[i] = tag.Text
}

query := fmt.Sprintf(
`INSERT OR IGNORE INTO tags (text) VALUES %s`,
strings.Join(placeholders, ", "),
)

_, err := txn.Exec(query, args...)
if err != nil {
return fmt.Errorf("failed to bulk insert tags: %w", err)
}

return nil
Expand Down