Skip to content
Snippets Groups Projects
Verified Commit cc2c6004 authored by Pea Nut's avatar Pea Nut
Browse files

Check for empty dburi in OpenDatabase

parent 8c93c820
Branches
Tags
1 merge request!56Add cli to manage invite tokens, fixes #61
package storage
import (
"errors"
"fmt"
"strings"
......@@ -10,6 +11,11 @@ import (
)
func OpenDatabase(dburi string) (*sqlx.DB, error) {
if len(dburi) == 0 {
return nil, errors.New("Could not open database (dburi is empty)")
}
// https://www.sqlite.org/wal.html
// https://www.sqlite.org/foreignkeys.html
if !strings.Contains(dburi, "?") {
......@@ -25,9 +31,8 @@ func OpenDatabase(dburi string) (*sqlx.DB, error) {
db.SetMaxOpenConns(1)
_, err = db.Exec(`CREATE TABLE IF NOT EXISTS tokens (
key TEXT PRIMARY KEY NOT NULL,
buckets TEXT NOT NULL
)`)
key TEXT PRIMARY KEY NOT NULL,
buckets TEXT NOT NULL)`)
if err != nil {
return nil, fmt.Errorf("Error creating tokens table: %w", err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment