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
No related branches found
No related tags found
1 merge request!56Add cli to manage invite tokens, fixes #61
package storage package storage
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
...@@ -10,6 +11,11 @@ import ( ...@@ -10,6 +11,11 @@ import (
) )
func OpenDatabase(dburi string) (*sqlx.DB, error) { 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/wal.html
// https://www.sqlite.org/foreignkeys.html // https://www.sqlite.org/foreignkeys.html
if !strings.Contains(dburi, "?") { if !strings.Contains(dburi, "?") {
...@@ -26,8 +32,7 @@ func OpenDatabase(dburi string) (*sqlx.DB, error) { ...@@ -26,8 +32,7 @@ func OpenDatabase(dburi string) (*sqlx.DB, error) {
_, err = db.Exec(`CREATE TABLE IF NOT EXISTS tokens ( _, err = db.Exec(`CREATE TABLE IF NOT EXISTS tokens (
key TEXT PRIMARY KEY NOT NULL, key TEXT PRIMARY KEY NOT NULL,
buckets TEXT NOT NULL buckets TEXT NOT NULL)`)
)`)
if err != nil { if err != nil {
return nil, fmt.Errorf("Error creating tokens table: %w", err) 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