cerca

lean forum software (pmc local branch)
Log | Files | Refs | README | LICENSE

commit f9ca90d2e732db266d7a7182efbd06e386aeddde
parent ccfc124b4139ccc6cbc8cadcece1402c4e50c8ca
Author: Nat Welch <nat@natwelch.com>
Date:   Wed, 12 Jan 2022 02:23:27 +0000

Creaate db if missing

Diffstat:
Mdatabase/database.go | 10+++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/database/database.go b/database/database.go @@ -1,10 +1,10 @@ package database import ( + "cerca/util" "context" "database/sql" "fmt" - "cerca/util" "html/template" "log" "net/url" @@ -18,6 +18,14 @@ type DB struct { } func InitDB(filepath string) DB { + if _, err := os.Stat(filepath); errors.Is(err, os.ErrNotExist) { + file, err := os.Create(filepath) + if err != nil { + log.Fatal(err) + } + defer file.Close() + } + db, err := sql.Open("sqlite3", filepath) util.Check(err, "opening sqlite3 database at %s", filepath) if db == nil {