Documentation
¶
Index ¶
- Constants
- Variables
- func Create[T any](ctx context.Context, engine *Engine, object T, nsId ...uint64) (uint64, T, error)
- func Delete[T any, R UniqueField](ctx context.Context, engine *Engine, uniqueField R, nsId ...uint64) (uint64, T, error)
- func Get[T any, R UniqueField](ctx context.Context, engine *Engine, uniqueField R, nsId ...uint64) (uint64, T, error)
- func Query[T any](ctx context.Context, engine *Engine, queryParams QueryParams, nsId ...uint64) ([]uint64, []T, error)
- func ResetSingleton()
- func Upsert[T any](ctx context.Context, engine *Engine, object T, nsId ...uint64) (uint64, T, bool, error)
- type Client
- type ClientOpt
- type Config
- type ConstrainedField
- type Engine
- func (engine *Engine) Close()
- func (engine *Engine) CreateNamespace() (*Namespace, error)
- func (engine *Engine) DropAll(ctx context.Context) error
- func (engine *Engine) GetClient() (*dgo.Dgraph, error)
- func (engine *Engine) GetDefaultNamespace() *Namespace
- func (engine *Engine) GetNamespace(nsID uint64) (*Namespace, error)
- func (ns *Engine) LeaseUIDs(numUIDs uint64) (*pb.AssignedIds, error)
- func (engine *Engine) Load(ctx context.Context, schemaPath, dataPath string) error
- func (engine *Engine) LoadData(inCtx context.Context, dataDir string) error
- type Filter
- type ModusDbOption
- type Namespace
- func (ns *Namespace) AlterSchema(ctx context.Context, sch string) error
- func (ns *Namespace) DropAll(ctx context.Context) error
- func (ns *Namespace) DropData(ctx context.Context) error
- func (ns *Namespace) ID() uint64
- func (n *Namespace) Load(ctx context.Context, schemaPath, dataPath string) error
- func (n *Namespace) LoadData(inCtx context.Context, dataDir string) error
- func (ns *Namespace) Mutate(ctx context.Context, ms []*api.Mutation) (map[string]uint64, error)
- func (ns *Namespace) Query(ctx context.Context, query string) (*api.Response, error)
- func (ns *Namespace) QueryWithVars(ctx context.Context, query string, vars map[string]string) (*api.Response, error)
- type Pagination
- type QueryParams
- type Sorting
- type StringPredicate
- type UniqueField
- type VectorPredicate
Constants ¶
const ( // DgraphURIPrefix is the prefix for Dgraph server connections DgraphURIPrefix = "dgraph://" // FileURIPrefix is the prefix for file-based local connections FileURIPrefix = "file://" )
Variables ¶
Functions ¶
func ResetSingleton ¶
func ResetSingleton()
ResetSingleton resets the singleton state for testing purposes. This should ONLY be called during testing, typically in cleanup functions.
Types ¶
type Client ¶
type Client interface {
Insert(context.Context, any) error
Upsert(context.Context, any) error
Update(context.Context, any) error
Get(context.Context, any, string) error
Query(context.Context, any) *dg.Query
Delete(context.Context, []string) error
Close()
UpdateSchema(context.Context, ...any) error
GetSchema(context.Context) (string, error)
DropAll(context.Context) error
DropData(context.Context) error
// QueryRaw executes a raw Dgraph query with optional query variables.
// The `query` parameter is the Dgraph query string.
// The `vars` parameter is a map of variable names to their values, used to parameterize the query.
QueryRaw(context.Context, string, map[string]string) ([]byte, error)
DgraphClient() (*dgo.Dgraph, func(), error)
}
Client provides an interface for Dgraph operations
func NewClient ¶
NewClient creates a new graph database client instance based on the provided URI.
The function supports two URI schemes:
- dgraph://host:port - Connects to a remote Dgraph instance
- file:///path/to/db - Creates or opens a local file-based database
Optional configuration can be provided via the opts parameter:
- WithAutoSchema(bool) - Enable/disable automatic schema creation for inserted objects
- WithPoolSize(int) - Set the connection pool size for better performance under load
- WithNamespace(string) - Set the database namespace for multi-tenant installations
- WithLogger(logr.Logger) - Configure structured logging with custom verbosity levels
The returned Client provides a consistent interface regardless of whether you're connected to a remote Dgraph cluster or a local embedded database. This abstraction helps prevent the connection issues that can occur with raw gRPC/bufconn setups.
For file-based URIs, the client maintains a singleton Engine instance to ensure data consistency across multiple client connections to the same database.
type ClientOpt ¶
type ClientOpt func(*clientOptions)
ClientOpt is a function that configures a client
func WithAutoSchema ¶
WithAutoSchema enables automatic schema management
func WithLogger ¶
WithLogger sets a structured logger for the client
func WithNamespace ¶
WithNamespace sets the namespace for the client
func WithPoolSize ¶
WithPoolSize sets the size of the dgo client connection pool
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func NewDefaultConfig ¶
func (Config) WithLimitNormalizeNode ¶
type ConstrainedField ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is an instance of modusDB. For now, we only support one instance of modusDB per process.
func (*Engine) CreateNamespace ¶
func (*Engine) GetDefaultNamespace ¶
type Filter ¶
type Filter struct {
Field string
String StringPredicate
Vector VectorPredicate
And *Filter
Or *Filter
Not *Filter
}
type ModusDbOption ¶
type ModusDbOption func(*modusDbOptions)
func WithNamespaceOLD ¶
func WithNamespaceOLD(ns uint64) ModusDbOption
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace is one of the namespaces in modusDB.
func (*Namespace) AlterSchema ¶
type Pagination ¶
type QueryParams ¶
type QueryParams struct {
Filter *Filter
Pagination *Pagination
Sorting *Sorting
}
type StringPredicate ¶
type UniqueField ¶
type UniqueField interface {
uint64 | ConstrainedField
}