dgraph

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package dgraph is a generated GoMock package.

Package dgraph is a generated GoMock package.

Package dgraph is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the Dgraph client with logging and metrics.

func New

func New(config Config) *Client

New creates a new Dgraph client with the given configuration.

func (*Client) Alter

func (d *Client) Alter(ctx context.Context, op any) error

Alter applies schema or other changes to the Dgraph database.

func (*Client) Connect

func (d *Client) Connect()

Connect connects to the Dgraph database using the provided configuration.

func (*Client) HealthCheck

func (d *Client) HealthCheck(ctx context.Context) (any, error)

HealthCheck performs a basic health check by pinging the Dgraph server.

func (*Client) Mutate

func (d *Client) Mutate(ctx context.Context, mu any) (any, error)

Mutate executes a write operation (mutation) in the Dgraph database and returns the result.

func (*Client) NewReadOnlyTxn

func (d *Client) NewReadOnlyTxn() any

NewReadOnlyTxn creates a new read-only transaction for querying the Dgraph database.

func (*Client) NewTxn

func (d *Client) NewTxn() any

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

func (*Client) Query

func (d *Client) Query(ctx context.Context, query string) (any, error)

Query executes a read-only query in the Dgraph database and returns the result.

func (*Client) QueryWithVars

func (d *Client) QueryWithVars(ctx context.Context, query string, vars map[string]string) (any, error)

QueryWithVars executes a read-only query with variables in the Dgraph database. QueryWithVars executes a read-only query with variables in the Dgraph database.

func (*Client) UseLogger

func (d *Client) UseLogger(logger any)

UseLogger sets the logger for the Dgraph client which asserts the Logger interface.

func (*Client) UseMetrics

func (d *Client) UseMetrics(metrics any)

UseMetrics sets the metrics for the Dgraph client which asserts the Metrics interface.

func (*Client) UseTracer

func (d *Client) UseTracer(tracer any)

UseTracer sets the tracer for DGraph client.

type Config

type Config struct {
	Host string
	Port string
}

Config holds the configuration for connecting to Dgraph.

type DgraphClient

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

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

	// Alter applies schema or other changes to the Dgraph database.
	Alter(ctx context.Context, op *api.Operation) error

	// Login logs in to the Dgraph database.
	Login(ctx context.Context, userid string, password string) error

	// LoginIntoNamespace logs in to the Dgraph database with a specific namespace.
	LoginIntoNamespace(ctx context.Context, userid string, password string, namespace uint64) error

	// GetJwt returns the JWT token for the Dgraph client.
	GetJwt() api.Jwt

	// Relogin relogs in to the Dgraph database.
	Relogin(ctx context.Context) error
}

DgraphClient is an interface that defines the methods for interacting with Dgraph.

func NewDgraphClient

func NewDgraphClient(client *dgo.Dgraph) DgraphClient

NewDgraphClient returns a new Dgraph client.

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(pattern string, args ...interface{})
	Log(args ...interface{})
	Logf(pattern string, args ...interface{})
	Error(args ...interface{})
	Errorf(pattern string, args ...interface{})
}

Logger interface with required methods.

type Metrics

type Metrics interface {
	NewHistogram(name, desc string, buckets ...float64)

	RecordHistogram(ctx context.Context, name string, value float64, labels ...string)
}

type MockDgraphClient

type MockDgraphClient struct {
	// contains filtered or unexported fields
}

MockDgraphClient is a mock of DgraphClient interface.

func NewMockDgraphClient

func NewMockDgraphClient(ctrl *gomock.Controller) *MockDgraphClient

NewMockDgraphClient creates a new mock instance.

func (*MockDgraphClient) Alter

func (m *MockDgraphClient) Alter(ctx context.Context, op *api.Operation) error

Alter mocks base method.

func (*MockDgraphClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockDgraphClient) GetJwt

func (m *MockDgraphClient) GetJwt() api.Jwt

GetJwt mocks base method.

func (*MockDgraphClient) Login

func (m *MockDgraphClient) Login(ctx context.Context, userid, password string) error

Login mocks base method.

func (*MockDgraphClient) LoginIntoNamespace

func (m *MockDgraphClient) LoginIntoNamespace(ctx context.Context, userid, password string, namespace uint64) error

LoginIntoNamespace mocks base method.

func (*MockDgraphClient) NewReadOnlyTxn

func (m *MockDgraphClient) NewReadOnlyTxn() Txn

NewReadOnlyTxn mocks base method.

func (*MockDgraphClient) NewTxn

func (m *MockDgraphClient) NewTxn() Txn

NewTxn mocks base method.

func (*MockDgraphClient) Relogin

func (m *MockDgraphClient) Relogin(ctx context.Context) error

Relogin mocks base method.

type MockDgraphClientMockRecorder

type MockDgraphClientMockRecorder struct {
	// contains filtered or unexported fields
}

MockDgraphClientMockRecorder is the mock recorder for MockDgraphClient.

func (*MockDgraphClientMockRecorder) Alter

func (mr *MockDgraphClientMockRecorder) Alter(ctx, op any) *gomock.Call

Alter indicates an expected call of Alter.

func (*MockDgraphClientMockRecorder) GetJwt

GetJwt indicates an expected call of GetJwt.

func (*MockDgraphClientMockRecorder) Login

func (mr *MockDgraphClientMockRecorder) Login(ctx, userid, password any) *gomock.Call

Login indicates an expected call of Login.

func (*MockDgraphClientMockRecorder) LoginIntoNamespace

func (mr *MockDgraphClientMockRecorder) LoginIntoNamespace(ctx, userid, password, namespace any) *gomock.Call

LoginIntoNamespace indicates an expected call of LoginIntoNamespace.

func (*MockDgraphClientMockRecorder) NewReadOnlyTxn

func (mr *MockDgraphClientMockRecorder) NewReadOnlyTxn() *gomock.Call

NewReadOnlyTxn indicates an expected call of NewReadOnlyTxn.

func (*MockDgraphClientMockRecorder) NewTxn

NewTxn indicates an expected call of NewTxn.

func (*MockDgraphClientMockRecorder) Relogin

func (mr *MockDgraphClientMockRecorder) Relogin(ctx any) *gomock.Call

Relogin indicates an expected call of Relogin.

type MockLogger

type MockLogger struct {
	// contains filtered or unexported fields
}

MockLogger is a mock of Logger interface.

func NewMockLogger

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) Debug

func (m *MockLogger) Debug(args ...any)

Debug mocks base method.

func (*MockLogger) Debugf

func (m *MockLogger) Debugf(pattern string, args ...any)

Debugf mocks base method.

func (*MockLogger) EXPECT

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLogger) Error

func (m *MockLogger) Error(args ...any)

Error mocks base method.

func (*MockLogger) Errorf

func (m *MockLogger) Errorf(pattern string, args ...any)

Errorf mocks base method.

func (*MockLogger) Log

func (m *MockLogger) Log(args ...any)

Log mocks base method.

func (*MockLogger) Logf

func (m *MockLogger) Logf(pattern string, args ...any)

Logf mocks base method.

type MockLoggerMockRecorder

type MockLoggerMockRecorder struct {
	// contains filtered or unexported fields
}

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) Debug

func (mr *MockLoggerMockRecorder) Debug(args ...any) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Debugf

func (mr *MockLoggerMockRecorder) Debugf(pattern any, args ...any) *gomock.Call

Debugf indicates an expected call of Debugf.

func (*MockLoggerMockRecorder) Error

func (mr *MockLoggerMockRecorder) Error(args ...any) *gomock.Call

Error indicates an expected call of Error.

func (*MockLoggerMockRecorder) Errorf

func (mr *MockLoggerMockRecorder) Errorf(pattern any, args ...any) *gomock.Call

Errorf indicates an expected call of Errorf.

func (*MockLoggerMockRecorder) Log

func (mr *MockLoggerMockRecorder) Log(args ...any) *gomock.Call

Log indicates an expected call of Log.

func (*MockLoggerMockRecorder) Logf

func (mr *MockLoggerMockRecorder) Logf(pattern any, args ...any) *gomock.Call

Logf indicates an expected call of Logf.

type MockMetrics

type MockMetrics struct {
	// contains filtered or unexported fields
}

MockMetrics is a mock of Metrics interface.

func NewMockMetrics

func NewMockMetrics(ctrl *gomock.Controller) *MockMetrics

NewMockMetrics creates a new mock instance.

func (*MockMetrics) EXPECT

func (m *MockMetrics) EXPECT() *MockMetricsMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMetrics) NewHistogram

func (m *MockMetrics) NewHistogram(name, desc string, buckets ...float64)

NewHistogram mocks base method.

func (*MockMetrics) RecordHistogram

func (m *MockMetrics) RecordHistogram(ctx context.Context, name string, value float64, labels ...string)

RecordHistogram mocks base method.

type MockMetricsMockRecorder

type MockMetricsMockRecorder struct {
	// contains filtered or unexported fields
}

MockMetricsMockRecorder is the mock recorder for MockMetrics.

func (*MockMetricsMockRecorder) NewHistogram

func (mr *MockMetricsMockRecorder) NewHistogram(name, desc any, buckets ...any) *gomock.Call

NewHistogram indicates an expected call of NewHistogram.

func (*MockMetricsMockRecorder) RecordHistogram

func (mr *MockMetricsMockRecorder) RecordHistogram(ctx, name, value any, labels ...any) *gomock.Call

RecordHistogram indicates an expected call of RecordHistogram.

type MockTxn

type MockTxn struct {
	// contains filtered or unexported fields
}

MockTxn is a mock of Txn interface.

func NewMockTxn

func NewMockTxn(ctrl *gomock.Controller) *MockTxn

NewMockTxn creates a new mock instance.

func (*MockTxn) BestEffort

func (m *MockTxn) BestEffort() Txn

BestEffort mocks base method.

func (*MockTxn) Commit

func (m *MockTxn) Commit(ctx context.Context) error

Commit mocks base method.

func (*MockTxn) Discard

func (m *MockTxn) Discard(ctx context.Context) error

Discard mocks base method.

func (*MockTxn) Do

func (m *MockTxn) Do(ctx context.Context, req *api.Request) (*api.Response, error)

Do mocks base method.

func (*MockTxn) EXPECT

func (m *MockTxn) EXPECT() *MockTxnMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTxn) Mutate

func (m *MockTxn) Mutate(ctx context.Context, mu *api.Mutation) (*api.Response, error)

Mutate mocks base method.

func (*MockTxn) Query

func (m *MockTxn) Query(ctx context.Context, q string) (*api.Response, error)

Query mocks base method.

func (*MockTxn) QueryRDF

func (m *MockTxn) QueryRDF(ctx context.Context, q string) (*api.Response, error)

QueryRDF mocks base method.

func (*MockTxn) QueryRDFWithVars

func (m *MockTxn) QueryRDFWithVars(ctx context.Context, q string, vars map[string]string) (*api.Response, error)

QueryRDFWithVars mocks base method.

func (*MockTxn) QueryWithVars

func (m *MockTxn) QueryWithVars(ctx context.Context, q string, vars map[string]string) (*api.Response, error)

QueryWithVars mocks base method.

type MockTxnMockRecorder

type MockTxnMockRecorder struct {
	// contains filtered or unexported fields
}

MockTxnMockRecorder is the mock recorder for MockTxn.

func (*MockTxnMockRecorder) BestEffort

func (mr *MockTxnMockRecorder) BestEffort() *gomock.Call

BestEffort indicates an expected call of BestEffort.

func (*MockTxnMockRecorder) Commit

func (mr *MockTxnMockRecorder) Commit(ctx any) *gomock.Call

Commit indicates an expected call of Commit.

func (*MockTxnMockRecorder) Discard

func (mr *MockTxnMockRecorder) Discard(ctx any) *gomock.Call

Discard indicates an expected call of Discard.

func (*MockTxnMockRecorder) Do

func (mr *MockTxnMockRecorder) Do(ctx, req any) *gomock.Call

Do indicates an expected call of Do.

func (*MockTxnMockRecorder) Mutate

func (mr *MockTxnMockRecorder) Mutate(ctx, mu any) *gomock.Call

Mutate indicates an expected call of Mutate.

func (*MockTxnMockRecorder) Query

func (mr *MockTxnMockRecorder) Query(ctx, q any) *gomock.Call

Query indicates an expected call of Query.

func (*MockTxnMockRecorder) QueryRDF

func (mr *MockTxnMockRecorder) QueryRDF(ctx, q any) *gomock.Call

QueryRDF indicates an expected call of QueryRDF.

func (*MockTxnMockRecorder) QueryRDFWithVars

func (mr *MockTxnMockRecorder) QueryRDFWithVars(ctx, q, vars any) *gomock.Call

QueryRDFWithVars indicates an expected call of QueryRDFWithVars.

func (*MockTxnMockRecorder) QueryWithVars

func (mr *MockTxnMockRecorder) QueryWithVars(ctx, q, vars any) *gomock.Call

QueryWithVars indicates an expected call of QueryWithVars.

type Mutation

type Mutation = api.Mutation

type Operation

type Operation = api.Operation

type PrometheusMetrics

type PrometheusMetrics struct {
	// contains filtered or unexported fields
}

func (*PrometheusMetrics) NewHistogram

func (p *PrometheusMetrics) NewHistogram(name, desc string, buckets ...float64)

NewHistogram creates a new histogram metric with the given name, description, and optional bucket sizes.

func (*PrometheusMetrics) RecordHistogram

func (p *PrometheusMetrics) RecordHistogram(_ context.Context, name string, value float64, labels ...string)

RecordHistogram records a value to the specified histogram metric with optional labels.

type QueryLog

type QueryLog struct {
	Type     string `json:"type"`
	URL      string `json:"url"`
	Duration int64  `json:"duration"` // Duration in microseconds
}

QueryLog represents the structure for query logging.

func (*QueryLog) PrettyPrint

func (ql *QueryLog) PrettyPrint(logger Logger)

PrettyPrint logs the QueryLog in a structured format to the given writer.

type Txn

type Txn interface {
	// BestEffort sets the transaction to best-effort mode.
	BestEffort() Txn

	// Query executes a query against the transaction.
	Query(ctx context.Context, q string) (*api.Response, error)

	// QueryRDF executes an RDF query against the transaction.
	QueryRDF(ctx context.Context, q string) (*api.Response, error)

	// QueryWithVars executes a query with variables against the transaction.
	QueryWithVars(ctx context.Context, q string, vars map[string]string) (*api.Response, error)

	// QueryRDFWithVars executes an RDF query with variables against the transaction.
	QueryRDFWithVars(ctx context.Context, q string, vars map[string]string) (*api.Response, error)

	// Mutate applies a mutation to the transaction.
	Mutate(ctx context.Context, mu *api.Mutation) (*api.Response, error)

	// Do performs a raw request against the transaction.
	Do(ctx context.Context, req *api.Request) (*api.Response, error)

	// Commit commits the transaction.
	Commit(ctx context.Context) error

	// Discard discards the transaction.
	Discard(ctx context.Context) error
}

Txn is an interface for Dgraph transactions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL