Skip to content

Commit

Permalink
Resolve beta feedback issues (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
remade authored Oct 31, 2024
1 parent 8448815 commit 05a50a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
27 changes: 20 additions & 7 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,29 @@ func Select[TResult any, TWhat TableOrRecord](db *DB, what TWhat) (*TResult, err

func Patch(db *DB, what interface{}, patches []PatchData) (*[]PatchData, error) {
var patchRes connection.RPCResponse[[]PatchData]
err := db.con.Send(&patchRes, "patch", what, patches, true)
return patchRes.Result, err
if err := db.con.Send(&patchRes, "patch", what, patches, true); err != nil {
return nil, err
}

return patchRes.Result, nil
}

func Delete[TWhat TableOrRecord](db *DB, what TWhat) error {
return db.con.Send(nil, "delete", what)
func Delete[TResult any, TWhat TableOrRecord](db *DB, what TWhat) (*TResult, error) {
var res connection.RPCResponse[TResult]
if err := db.con.Send(&res, "delete", what); err != nil {
return nil, err
}

return res.Result, nil
}

func Upsert[TWhat TableOrRecord](db *DB, what TWhat, data interface{}) error {
return db.con.Send(nil, "upsert", what, data)
func Upsert[TResult any, TWhat TableOrRecord](db *DB, what TWhat, data interface{}) (*TResult, error) {
var res connection.RPCResponse[TResult]
if err := db.con.Send(&res, "upsert", what, data); err != nil {
return nil, err
}

return res.Result, nil
}

// Update a table or record in the database like a PUT request.
Expand All @@ -245,7 +258,7 @@ func Update[TResult any, TWhat TableOrRecord](db *DB, what TWhat, data interface
}

// Merge a table or record in the database like a PATCH request.
func Merge[TResult any](db *DB, what, data interface{}) (*TResult, error) {
func Merge[TResult any, TWhat TableOrRecord](db *DB, what TWhat, data interface{}) (*TResult, error) {
var res connection.RPCResponse[TResult]
if err := db.con.Send(&res, "merge", what, data); err != nil {
return nil, err
Expand Down
11 changes: 4 additions & 7 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func TestSurrealDBSuite(t *testing.T) {

// SetupTest is called after each test
func (s *SurrealDBTestSuite) TearDownTest() {
err := surrealdb.Delete[models.Table](s.db, "users")
_, err := surrealdb.Delete[[]testUser, models.Table](s.db, "users")
s.Require().NoError(err)

err = surrealdb.Delete[models.Table](s.db, "persons")
_, err = surrealdb.Delete[[]testUser, models.Table](s.db, "persons")
s.Require().NoError(err)

err = surrealdb.Delete[models.Table](s.db, "knows")
_, err = surrealdb.Delete[[]testUser, models.Table](s.db, "knows")
s.Require().NoError(err)
}

Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *SurrealDBTestSuite) TestDelete() {
s.Require().NoError(err)

// Delete the users...
err = surrealdb.Delete(s.db, "users")
_, err = surrealdb.Delete[[]testUser](s.db, "users")
s.Require().NoError(err)
}

Expand Down Expand Up @@ -460,9 +460,6 @@ func (s *SurrealDBTestSuite) TestQueryRaw() {
var selected []testPerson
err = queries[1].GetResult(&selected)
s.Require().NoError(err)

fmt.Println(created)
fmt.Println(selected)
}

func (s *SurrealDBTestSuite) TestRPCError() {
Expand Down

0 comments on commit 05a50a3

Please sign in to comment.