Skip to content

Commit

Permalink
change hare_err package name to dberr
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamey Cribbs committed Feb 10, 2021
1 parent 758918b commit 56b36c0
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 105 deletions.
16 changes: 8 additions & 8 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"sync"

"github.com/jameycribbs/hare/hare_err"
"github.com/jameycribbs/hare/dberr"
)

type Record interface {
Expand Down Expand Up @@ -75,7 +75,7 @@ func (db *Database) Close() error {

func (db *Database) CreateTable(tableName string) error {
if db.TableExists(tableName) {
return hare_err.TableExists
return dberr.TableExists
}

if err := db.store.CreateTable(tableName); err != nil {
Expand All @@ -95,7 +95,7 @@ func (db *Database) CreateTable(tableName string) error {

func (db *Database) Delete(tableName string, id int) error {
if !db.TableExists(tableName) {
return hare_err.NoTable
return dberr.NoTable
}

db.locks[tableName].Lock()
Expand All @@ -110,7 +110,7 @@ func (db *Database) Delete(tableName string, id int) error {

func (db *Database) DropTable(tableName string) error {
if !db.TableExists(tableName) {
return hare_err.NoTable
return dberr.NoTable
}

db.locks[tableName].Lock()
Expand All @@ -131,7 +131,7 @@ func (db *Database) DropTable(tableName string) error {

func (db *Database) Find(tableName string, id int, rec Record) error {
if !db.TableExists(tableName) {
return hare_err.NoTable
return dberr.NoTable
}

db.locks[tableName].RLock()
Expand All @@ -154,7 +154,7 @@ func (db *Database) Find(tableName string, id int, rec Record) error {

func (db *Database) IDs(tableName string) ([]int, error) {
if !db.TableExists(tableName) {
return nil, hare_err.NoTable
return nil, dberr.NoTable
}

db.locks[tableName].Lock()
Expand All @@ -170,7 +170,7 @@ func (db *Database) IDs(tableName string) ([]int, error) {

func (db *Database) Insert(tableName string, rec Record) (int, error) {
if !db.TableExists(tableName) {
return 0, hare_err.NoTable
return 0, dberr.NoTable
}

db.locks[tableName].Lock()
Expand Down Expand Up @@ -199,7 +199,7 @@ func (db *Database) TableExists(tableName string) bool {

func (db *Database) Update(tableName string, rec Record) error {
if !db.TableExists(tableName) {
return hare_err.NoTable
return dberr.NoTable
}

db.locks[tableName].Lock()
Expand Down
34 changes: 17 additions & 17 deletions database_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"

"github.com/jameycribbs/hare/datastores/disk"
"github.com/jameycribbs/hare/hare_err"
"github.com/jameycribbs/hare/dberr"
)

func TestAllDatabaseDiskTests(t *testing.T) {
Expand Down Expand Up @@ -41,7 +41,7 @@ func TestAllDatabaseDiskTests(t *testing.T) {
db := newTestDatabaseDisk(t)
db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
gotErr := db.Find("contacts", 3, &Contact{})

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -82,12 +82,12 @@ func TestAllDatabaseDiskTests(t *testing.T) {
}
},
func(t *testing.T) {
//CreateTable (ErrTableExists)...
//CreateTable (TableExists error)...

db := newTestDatabaseDisk(t)
defer db.Close()

wantErr := hare_err.TableExists
wantErr := dberr.TableExists
gotErr := db.CreateTable("contacts")

if !errors.Is(gotErr, wantErr) {
Expand All @@ -105,20 +105,20 @@ func TestAllDatabaseDiskTests(t *testing.T) {
t.Fatal(err)
}

wantErr := hare_err.NoRecord
wantErr := dberr.NoRecord
gotErr := db.Find("contacts", 3, &Contact{})

if !errors.Is(gotErr, wantErr) {
t.Errorf("want %v; got %v", wantErr, gotErr)
}
},
func(t *testing.T) {
//Delete (ErrNoTable)...
//Delete (NoTable error)...

db := newTestDatabaseDisk(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
gotErr := db.Delete("nonexistent", 3)

if !errors.Is(gotErr, wantErr) {
Expand All @@ -144,12 +144,12 @@ func TestAllDatabaseDiskTests(t *testing.T) {
}
},
func(t *testing.T) {
//DropTable (ErrNoTable)...
//DropTable (NoTable error)...

db := newTestDatabaseDisk(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
gotErr := db.DropTable("nonexistent")

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -177,12 +177,12 @@ func TestAllDatabaseDiskTests(t *testing.T) {
}
},
func(t *testing.T) {
//Find (ErrNoRecord)...
//Find (NoRecord error)...

db := newTestDatabaseDisk(t)
defer db.Close()

wantErr := hare_err.NoRecord
wantErr := dberr.NoRecord
gotErr := db.Find("contacts", 5, &Contact{})

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -215,12 +215,12 @@ func TestAllDatabaseDiskTests(t *testing.T) {
}
},
func(t *testing.T) {
//IDs() (ErrNoTable)...
//IDs() (NoTable error)...

db := newTestDatabaseDisk(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
_, gotErr := db.IDs("nonexistent")

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -258,12 +258,12 @@ func TestAllDatabaseDiskTests(t *testing.T) {
}
},
func(t *testing.T) {
//Insert (ErrNoTable)...
//Insert (NoTable error)...

db := newTestDatabaseDisk(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
_, gotErr := db.Insert("nonexistent", &Contact{FirstName: "Robin", LastName: "Williams", Age: 88})

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -316,12 +316,12 @@ func TestAllDatabaseDiskTests(t *testing.T) {
}
},
func(t *testing.T) {
//Update (ErrNoTable)...
//Update (NoTable error)...

db := newTestDatabaseDisk(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
gotErr := db.Update("nonexistent", &Contact{ID: 4, FirstName: "Hazel", LastName: "Koller", Age: 26})

if !errors.Is(gotErr, wantErr) {
Expand Down
34 changes: 17 additions & 17 deletions database_ram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/jameycribbs/hare/datastores/ram"
"github.com/jameycribbs/hare/hare_err"
"github.com/jameycribbs/hare/dberr"
)

func TestAllDatabaseRamTests(t *testing.T) {
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestAllDatabaseRamTests(t *testing.T) {
db := newTestDatabaseRam(t)
db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
gotErr := db.Find("contacts", 3, &Contact{})

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -80,12 +80,12 @@ func TestAllDatabaseRamTests(t *testing.T) {
}
},
func(t *testing.T) {
//CreateTable (ErrTableExists)...
//CreateTable (TableExists error)...

db := newTestDatabaseRam(t)
defer db.Close()

wantErr := hare_err.TableExists
wantErr := dberr.TableExists
gotErr := db.CreateTable("contacts")

if !errors.Is(gotErr, wantErr) {
Expand All @@ -103,20 +103,20 @@ func TestAllDatabaseRamTests(t *testing.T) {
t.Fatal(err)
}

wantErr := hare_err.NoRecord
wantErr := dberr.NoRecord
gotErr := db.Find("contacts", 3, &Contact{})

if !errors.Is(gotErr, wantErr) {
t.Errorf("want %v; got %v", wantErr, gotErr)
}
},
func(t *testing.T) {
//Delete (ErrNoTable)...
//Delete (NoTable error)...

db := newTestDatabaseRam(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
gotErr := db.Delete("nonexistent", 3)

if !errors.Is(gotErr, wantErr) {
Expand All @@ -142,12 +142,12 @@ func TestAllDatabaseRamTests(t *testing.T) {
}
},
func(t *testing.T) {
//DropTable (ErrNoTable)...
//DropTable (NoTable error)...

db := newTestDatabaseRam(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
gotErr := db.DropTable("nonexistent")

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -175,12 +175,12 @@ func TestAllDatabaseRamTests(t *testing.T) {
}
},
func(t *testing.T) {
//Find (ErrNoRecord)...
//Find (NoRecord error)...

db := newTestDatabaseRam(t)
defer db.Close()

wantErr := hare_err.NoRecord
wantErr := dberr.NoRecord
gotErr := db.Find("contacts", 5, &Contact{})

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -213,12 +213,12 @@ func TestAllDatabaseRamTests(t *testing.T) {
}
},
func(t *testing.T) {
//IDs() (ErrNoTable)...
//IDs() (NoTable error)...

db := newTestDatabaseRam(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
_, gotErr := db.IDs("nonexistent")

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -256,12 +256,12 @@ func TestAllDatabaseRamTests(t *testing.T) {
}
},
func(t *testing.T) {
//Insert (ErrNoTable)...
//Insert (NoTable error)...

db := newTestDatabaseRam(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
_, gotErr := db.Insert("nonexistent", &Contact{FirstName: "Robin", LastName: "Williams", Age: 88})

if !errors.Is(gotErr, wantErr) {
Expand Down Expand Up @@ -314,12 +314,12 @@ func TestAllDatabaseRamTests(t *testing.T) {
}
},
func(t *testing.T) {
//Update (ErrNoTable)...
//Update (NoTable error)...

db := newTestDatabaseRam(t)
defer db.Close()

wantErr := hare_err.NoTable
wantErr := dberr.NoTable
gotErr := db.Update("nonexistent", &Contact{ID: 4, FirstName: "Hazel", LastName: "Koller", Age: 26})

if !errors.Is(gotErr, wantErr) {
Expand Down
10 changes: 5 additions & 5 deletions datastores/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"strings"

"github.com/jameycribbs/hare/hare_err"
"github.com/jameycribbs/hare/dberr"
)

type Disk struct {
Expand Down Expand Up @@ -43,7 +43,7 @@ func (dsk *Disk) Close() error {

func (dsk *Disk) CreateTable(tableName string) error {
if dsk.TableExists(tableName) {
return hare_err.TableExists
return dberr.TableExists
}

filePtr, err := dsk.openFile(tableName, true)
Expand Down Expand Up @@ -101,7 +101,7 @@ func (dsk *Disk) InsertRec(tableName string, id int, rec []byte) error {
ids := tableFile.ids()
for _, i := range ids {
if id == i {
return hare_err.IDExists
return dberr.IDExists
}
}

Expand Down Expand Up @@ -186,7 +186,7 @@ func (dsk *Disk) UpdateRec(tableName string, id int, rec []byte) error {
func (dsk *Disk) getTableFile(tableName string) (*tableFile, error) {
tableFile, ok := dsk.tableFiles[tableName]
if !ok {
return nil, hare_err.NoTable
return nil, dberr.NoTable
}

return tableFile, nil
Expand Down Expand Up @@ -263,7 +263,7 @@ func (dsk Disk) openFile(tableName string, createIfNeeded bool) (*os.File, error
func (dsk *Disk) closeTable(tableName string) error {
tableFile, ok := dsk.tableFiles[tableName]
if !ok {
return hare_err.NoTable
return dberr.NoTable
}

if err := tableFile.close(); err != nil {
Expand Down
Loading

0 comments on commit 56b36c0

Please sign in to comment.