Skip to content

v1.21.0

Compare
Choose a tag to compare
@aryanmehrotra aryanmehrotra released this 23 Sep 12:21
· 676 commits to main since this release
8c27cc1

Release v1.21.0

✨ Features

  • Support for DGraph

    Dgraph can be added using the method on gofrApp AddDgraph.
    Following methods are supported:
// Dgraph defines the methods for interacting with a Dgraph database.

type Dgraph interface {
// Query executes a read-only query in the Dgraph database and returns the result.
Query(ctx context.Context, query string) (interface{}, error)

// QueryWithVars executes a read-only query with variables in the Dgraph database.
QueryWithVars(ctx context.Context, query string, vars map[string]string) (interface{}, error)

// Mutate executes a write operation (mutation) in the Dgraph database and returns the result.
Mutate(ctx context.Context, mu interface{}) (interface{}, error)

// Alter applies schema or other changes to the Dgraph database.
Alter(ctx context.Context, op interface{}) error

// NewTxn creates a new transaction (read-write) for interacting with the Dgraph database.
NewTxn() interface{}

// NewReadOnlyTxn creates a new read-only transaction for querying the Dgraph database.
NewReadOnlyTxn() interface{}

// HealthChecker checks the health of the Dgraph instance.
HealthChecker
}

To use Dgraph in your GoFr application, follow the steps given below:

Step 1

go get gofr.dev/pkg/gofr/datasource/dgraph

Step 2

app.AddDgraph(dgraph.New(dgraph.Config{
Host: "localhost",
Port: "8080",
}))

GoFr supports both queries and mutations in Dgraph. To know more: Read the Docs

🛠 Enhancements

  • Migrations in Cassandra

    Users can now add migrations while using Cassandra as the datasource. This enhancement assumes that user has already created the KEYSPACE in cassandra. A KEYSPACE in Cassandra is a container for tables that defines data replication settings across the cluster. Visit the Docs to know more.
type Cassandra interface {
    Exec(query string, args ...interface{}) error
    NewBatch(name string, batchType int) error
    BatchQuery(name, stmt string, values ...any) error
    ExecuteBatch(name string) error
        HealthCheck(ctx context.Context) (any, error)
}

To achieve atomicity during migrations, users can leverage batch operations using the NewBatch, BatchQuery, and ExecuteBatch methods. These methods allow multiple queries to be executed as a single atomic operation.

When using batch operations, consider using batchType: LoggedBatch i.e. 0 for atomicity or an UnloggedBatch i.e. 1 for improved performance where atomicity isn't required. This approach provides a way to maintain data consistency during complex migrations.

  • Added mocks for Metrics

    MockContainer can be used to set expectation for metrics in the application while writing test.

    Usage:

        // GoFr's mockContainer
        _, mock := NewMockContainer(t)  
      
        // Set mock expectations using the mocks from NewMockContainer
        mock.Metrics.EXPECT().IncrementCounter(context.Background(), "name")
      
        // Call to your function where metrics has to be mocked
        .
        .
        .