commit 412e80eb21a10d83d526043fadcd2bcd75c9ac6c
parent 2b577b37ebf92d224ba8657506e0ef0e99f039de
Author: Andrew Laack <andrew@laack.co>
Date: Mon, 4 May 2026 21:21:22 -0500
Better solution
Diffstat:
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/main.go b/main.go
@@ -117,7 +117,7 @@ func main() {
panic(err)
}
- insertLinkQuery := "INSERT INTO link (source, destination) VALUES (?, ?)"
+ insertLinkQuery := "INSERT INTO link (source, destination) VALUES (?, ?) ON CONFLICT DO NOTHING"
tx, _ := db.Begin()
@@ -127,11 +127,6 @@ func main() {
fmt.Printf("Inserting link %d into table\n", index)
if err != nil {
- if strings.Compare(err.Error(), "UNIQUE constraint failed: link.source, link.destination") == 0 {
- fmt.Println("Link already exists; continuing")
- continue
- }
-
panic(err)
}