[fix] Testing fixes
- sqlite error handling and wrapping - more responsive commands - database updates
This commit is contained in:
@@ -2,6 +2,8 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
@@ -13,8 +15,7 @@ import (
|
||||
)
|
||||
|
||||
/*
|
||||
all sqlx methods for CRUD functionalities of commands and servers. All database methods should use the internal
|
||||
methods query, exec, queryrow -- these wrapper functions handle timeouts and other configuration
|
||||
all sqlx methods for CRUD functionalities of commands and servers.
|
||||
*/
|
||||
|
||||
const (
|
||||
@@ -123,6 +124,9 @@ func (d *database) GetCmd(name string) (string, error) {
|
||||
ctx, cl := d.timeout()
|
||||
defer cl()
|
||||
err := d.QueryRowxContext(ctx, query, name).Scan(&cmd)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return "", errors.New("Command not found")
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -222,6 +226,9 @@ func (d *database) GetServer(name string) (model.Server, error) {
|
||||
defer cancel()
|
||||
var s model.Server
|
||||
err := d.QueryRowxContext(ctx, query, name).StructScan(&s)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return model.Server{}, errors.New("Server not found")
|
||||
}
|
||||
if err != nil {
|
||||
return model.Server{}, err
|
||||
}
|
||||
@@ -246,6 +253,9 @@ func (d *database) GetActiveServer() (model.Server, error) {
|
||||
defer cancel()
|
||||
var s model.Server
|
||||
err := d.QueryRowxContext(ctx, query).StructScan(&s)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return s, errors.New("No active server set")
|
||||
}
|
||||
return s, err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user