You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GoFr supports injecting `Couchbase` that implements the following interface. Any driver that implements the interface can be
4
+
added using the `app.AddCouchbase()` method, and users can use Couchbase across the application with `gofr.Context`.
5
+
6
+
```go
7
+
typeCouchbaseinterface {
8
+
Get(ctx context.Context, key string, result any) error
9
+
10
+
Insert(ctx context.Context, key string, document, result any) error
11
+
12
+
Upsert(ctx context.Context, key string, document any, result any) error
13
+
14
+
Remove(ctx context.Context, key string) error
15
+
16
+
Query(ctx context.Context, statement string, params map[string]any, result any) error
17
+
18
+
AnalyticsQuery(ctx context.Context, statement string, params map[string]any, result any) error
19
+
}
20
+
```
21
+
22
+
Users can easily inject a driver that supports this interface, providing usability without compromising the extensibility to use multiple databases.
23
+
Don't forget to serup the Couchbase cluster in Couchbase Web Console first. [Follow for more details](https://docs.couchbase.com/server/current/install/getting-started-docker.html#section_jvt_zvj_42b).
24
+
To begin using Couchbase in your GoFr application, you need to import the Couchbase datasource package:
25
+
26
+
```shell
27
+
go get gofr.dev/pkg/gofr/datasource/couchbase@latest
28
+
```
29
+
30
+
### Example
31
+
32
+
Here is an example of how to use the Couchbase datasource in a GoFr application:
33
+
34
+
```go
35
+
package main
36
+
37
+
import (
38
+
"context"
39
+
"fmt"
40
+
"log"
41
+
42
+
"gofr.dev/pkg/gofr"
43
+
"gofr.dev/pkg/gofr/datasource/couchbase"
44
+
)
45
+
46
+
typeUserstruct {
47
+
IDstring`json:"id"`
48
+
Namestring`json:"name"`
49
+
Ageint`json:"age"`
50
+
}
51
+
52
+
funcmain() {
53
+
// Create a new GoFr application
54
+
a:= gofr.New()
55
+
56
+
// Add the Couchbase datasource to the application
0 commit comments