-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Couchbase support #2076
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
Merged
Merged
Couchbase support #2076
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f77aa35
init couchbase integration with basic methods and mocks
olxandr bc639f8
added tests for DB methods
olxandr 58e19cb
add rest methods and tests
olxandr 7edcfdd
address Insert and Upsert methods duplication
olxandr d843a08
go.work.sum conflicts resolve
olxandr 3ccb022
remove unused wrappers
olxandr 385fbd4
Merge branch 'development' into couchbase
Umang01-hash c2992bc
restore go.mod to its original state
olxandr 5c3aadf
add couchbase to mock container
olxandr b269c4d
make methods that aren't exposed via interface private
olxandr 15fd0d6
refactor Client methods so they match the interface methods signatures
olxandr a053ab1
add docs
olxandr fadb676
register healthcheck method
olxandr 6a9306b
Merge branch 'couchbase' of github.com:olxandr/gofr into couchbase
olxandr cd9cd0d
Merge branch 'development' into couchbase
olxandr 116ed9c
restore go.sum to its original state
olxandr 5e3659e
adapt logger interface according to main Logger
olxandr 37db2a0
do nothing if MutationResult is nil
olxandr fe72bec
more detailed info in docs
olxandr eae1ac9
add docker container setup
olxandr cd985d1
tracing refactor
olxandr 7d819af
Merge branch 'couchbase' of github.com:olxandr/gofr into couchbase
olxandr 7f3f574
linter fixes
olxandr 7102bd7
Merge branch 'development' into couchbase
olxandr d78dcf2
NewMockContainer() refactor (funlen statements limit exceeded)
olxandr ffb7a7f
Merge branch 'development' into couchbase
olxandr eec498a
Merge branch 'development' into couchbase
coolwednesday 0038455
Merge branch 'development' into couchbase
Umang01-hash 7d7f6b3
Merge branch 'development' into couchbase
Umang01-hash 4890417
Merge remote-tracking branch 'origin' into couchbase
Umang01-hash afb14dc
resolve merge conflicts
Umang01-hash a10ccef
update docs and remove <br>
Umang01-hash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
## Couchbase | ||
|
||
GoFr provides first-class support for Couchbase, one of the leading NoSQL databases in the industry. This integration allows developers to seamlessly connect their applications with Couchbase and leverage its powerful features for data management. | ||
|
||
The Couchbase interface in GoFr is designed to be intuitive and easy to use, abstracting away the complexities of the underlying driver. This allows developers to focus on their application logic without worrying about the boilerplate code for database interactions. | ||
|
||
```go | ||
type Couchbase interface { | ||
Get(ctx context.Context, key string, result any) error | ||
|
||
Insert(ctx context.Context, key string, document, result any) error | ||
|
||
Upsert(ctx context.Context, key string, document any, result any) error | ||
|
||
Remove(ctx context.Context, key string) error | ||
|
||
Query(ctx context.Context, statement string, params map[string]any, result any) error | ||
|
||
AnalyticsQuery(ctx context.Context, statement string, params map[string]any, result any) error | ||
} | ||
``` | ||
|
||
To begin using Couchbase in your GoFr application, you need to import the Couchbase datasource package: | ||
|
||
```shell | ||
go get gofr.dev/pkg/gofr/datasource/couchbase@latest | ||
``` | ||
|
||
### Example | ||
|
||
Here is an example of how to use the Couchbase datasource in a GoFr application: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"gofr.dev/pkg/gofr" | ||
"gofr.dev/pkg/gofr/datasource/couchbase" | ||
) | ||
|
||
type User struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Age int `json:"age"` | ||
} | ||
|
||
func main() { | ||
// Create a new GoFr application | ||
a := gofr.New() | ||
|
||
// Add the Couchbase datasource to the application | ||
a.AddCouchbase(couchbase.New(&couchbase.Config{ | ||
Host: "localhost", | ||
User: "Administrator", | ||
Password: "password", | ||
Bucket: "test-bucket", | ||
})) | ||
|
||
// Add the routes | ||
a.GET("/users/{id}", getUser) | ||
a.POST("/users", createUser) | ||
|
||
// Run the application | ||
a.Run() | ||
} | ||
|
||
func getUser(c *gofr.Context) (any, error) { | ||
// Get the user ID from the URL path | ||
id := c.PathParam("id") | ||
|
||
// Get the user from Couchbase | ||
var user User | ||
if err := c.Couchbase.Get(c, id, &user); err != nil { | ||
return nil, err | ||
} | ||
|
||
return user, nil | ||
} | ||
|
||
func createUser(c *gofr.Context) (any, error) { | ||
// Get the user from the request body | ||
var user User | ||
if err := c.Bind(&user); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Insert the user into Couchbase | ||
if err := c.Couchbase.Insert(c, user.ID, user, nil); err != nil { | ||
return nil, err | ||
} | ||
|
||
return "user created successfully", nil | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.