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

Release v1.21.0 #1043

Merged
merged 17 commits into from
Sep 23, 2024
Merged

Release v1.21.0 #1043

merged 17 commits into from
Sep 23, 2024

Conversation

aryanmehrotra
Copy link
Member

@aryanmehrotra aryanmehrotra commented Sep 23, 2024

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
}

Any driver that implements the following interface can be added using the app.AddDgraph() method. 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
        .
        .
        .
    
    

@aryanmehrotra aryanmehrotra changed the base branch from development to main September 23, 2024 11:00
srijan-27
srijan-27 previously approved these changes Sep 23, 2024
@srijan-27 srijan-27 dismissed their stale review September 23, 2024 11:05

The merge-base changed after approval.

@aryanmehrotra aryanmehrotra merged commit 8c27cc1 into main Sep 23, 2024
11 checks passed
@aryanmehrotra aryanmehrotra deleted the release/v1.21.0 branch September 23, 2024 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants