From 34e720ec1c7e0c66c0eb461cb1dd0f4b378e6f94 Mon Sep 17 00:00:00 2001 From: Vladislav Filatov Date: Wed, 28 Aug 2024 13:34:54 +0200 Subject: [PATCH] Append to an existing DB (cherry picked from commit 084a5e4cfa480bb383741ff97b33c048cd3860f9) --- coyote.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/coyote.go b/coyote.go index 9bcf388..fbda297 100644 --- a/coyote.go +++ b/coyote.go @@ -232,12 +232,7 @@ func main() { var insert *sql.Stmt if ctx.IsSet("store") { filename := ctx.String("store") - file, err := os.Create(filename) - if err != nil { - log.Fatal(err) - } - file.Close() - db, err = sql.Open("sqlite", filename+"?_txlock=exclusive") + db, err = sql.Open("sqlite", filename+"?_txlock=exclusive&mode=rwc") if err != nil { log.Fatal(err) } @@ -249,7 +244,7 @@ func main() { log.Printf("💔 Closing database connection") }() - create, err := db.Prepare(`CREATE TABLE event + create, err := db.Prepare(`CREATE TABLE IF NOT EXISTS event ( "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "timestamp" TIMESTAMP DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'localtime')),