Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve beta feedback issues #163

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 +460,4 @@ func (s *SurrealDBTestSuite) TestQueryRaw() {
var selected []testPerson
err = queries[1].GetResult(&selected)
s.Require().NoError(err)

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