Categorygithub.com/fenos/dqlx
modulepackage
0.2.0
Repository: https://github.com/fenos/dqlx.git
Documentation: pkg.go.dev

# README

dqlx

dqlx is a fully featured DGraph Schema and Query Builder for Go. It aims to simplify the interaction with the awesome Dgraph database allowing you to fluently compose any queries and mutations of any complexity. It also comes with a rich Schema builder to easily develop and maintain your Dgraph schema.


Status

The project is getting close to its first official release

Why?

The DGraph query language is awesome! it is really powerful, and you can achieve a lot with it. However, as you start trying to add dynamicity (like any other declarative query language) you soon starts fiddling with a lot strings concatenations and can quickly get messy.

dqlx tries to simplify the interaction with DGraph by helping to construct Queries and mutations with a fluent API.

Features

  • Schema Builder (Types, Predicates, Indexes)
  • Filtering - Connecting Filters (AND / OR)
  • Nested Selection / Filters
  • Functions
  • Pagination
  • Aggregation
  • Sorting
  • GroupBy
  • Multiple Query Block
  • Query Variables
  • Values Variables
  • Facets
  • Mutations

Documentation

You can find the documentation here: https://fenos.github.io/dqlx


Installation

go get github.com/fenos/dqlx

Quick Overview

func main() {
    // Connect to Dgraph cluster
    db, err := dqlx.Connect("localhost:9080")

    if err != nil {
        log.Fatal()
    }

    ctx := context.Background()

    var animals []map[string]interface{}

    // Query for animals
    _, err = db.
        QueryType("Animal").
        Select(`
            uid
            name
            species
            age
        `).
        Filter(
            dqlx.Eq{"species": "Cat"},
            dqlx.Lt{"age": 5},
        ).
        UnmarshalInto(&animals).
        Execute(ctx)

    if err != nil { panic(err) }

    println(fmt.Sprintf("The animals are: %v", animals))
}

Licence

MIT

# Functions

Alias allows to alias a field.
AllOfTermsFn represents the allofterms expression, Expression: allofterms(predicate, value).
AllOfTextFn represents the match expression, Expression: alloftext(predicate, value).
AnyOfTermsFn represents the anyofterms expression, Expression: anyofterms(predicate, value).
AnyOfTextFn represents the anyoftext expression, Expression: anyoftext(predicate, value).
As makes a field a variable Example: dqlx.Query(...).Select(dqlx.As("C", "a")).
Avg represent the 'avg' expression Expression: avg(val(predicate)).
Between represents the between expression, Expression: between(predicate, from, to).
Condition returns a condition statement.
Connect connects to a DGraph Cluster.
Count represent the 'count' expression Expression: count(predicate).
EdgePath returns the abstract representation of an edge Example: dqlx.EdgePath("field1", "field2") Returns: "field1->field2".
EqFn represents the eq expression, Expression: eq(predicate, value).
EscapePredicate safely escape a predicate Example: dqlx.EscapePredicate("predicate").
ExactFn represents the exact expression, Expression: exact(predicate, value).
Expr returns a RawExpression.
Facets returns the expression for representing facets.
Fields alias of Select @Deprecated use Select() instead.
FromClient creates a DB instance from a raw dgraph client.
FullTextFn represents the term expression, Expression: fulltext(predicate, value).
GeFn represents the ge expression, Expression: ge(predicate, value).
GenerateTypes given a schema it generates Go structs definitions.
GroupBy returns an expression for grouping.
GtFn represents the gt expression, Expression: gt(predicate, value).
Has alias of HasFn, Expression: has(predicate).
HasFn represents the has expression, Expression: has(predicate).
IsEmptyQuery determine if a given query is an empty generated query.
LeFn represents the le expression, Expression: le(predicate, value).
LtFn represents the lt expression, Expression: lt(predicate, value).
MatchFn represents the match expression, Expression: match(predicate, value).
Max represent the 'max' expression Expression: max(val(predicate)).
Min represent the 'min' expression Expression: min(val(predicate)).
Minify minifies a dql query.
Mutation creates a new MutationBuilder.
NewDGoExecutor creates a new OperationExecutor.
NewSchema creates a new SchemaBuilder.
NewSchemaExecutor creates a new schema executor.
NewTypeBuilder creates a new TypeBuilder.
OrderAsc returns an orderasc expression.
OrderDesc returns an orderdesc expression.
P represent a predicate expression Expression: <predicate>.
ParseEdge parses the abstract representation of an edge Example: dqlx.ParseEdge("field1->field2") Returns: []string{"field1", "field2"}.
Predicate returns an escaped predicate.
QueriesToDQL returns the DQL statement for 1 or more queries Example: dqlx.QueriesToDQL(query1,query2,query3).
Query initialises the query builder with the provided root filter example: dqlx.Query(dqlx.EqFn(..,..)).
QueryEdge initialise a query builder with a specific name for the edge.
QueryType alias to initialise a query with the root function type() Example: dqlx.QueryType("User") Equivalent of: dqlx.Query(dqlx.TypeFn("User")).
RegexpFn represents the regexp expression, Expression: regexp(predicate, /pattern/).
Select adds nodeAttributes to selection set.
Sum represent the 'sum' expression Expression: sum(val(predicate)).
TermFn represents the term expression, Expression: term(predicate, value).
Type alias of TypeFn, Expression: type(predicate).
TypeFn represents the type expression, Expression: type(predicate).
UID returns uid expression Expression: uid(predicate).
UIDFn returns uid expression Expression: uid(predicate).
UIDInFn represents the uid_in expression, Expression: uid_in(predicate, value).
Val returns val expression Expression: val(predicate).
Variable initialise a variable query builder Example: dqlx.Variable(dqlx.EqFn(..,..)).
WithBestEffort sets the best effort flag for the current execution.
WithClient configures a client for the current execution.
No description provided by the author
WithReadOnly marks the execution as a read-only operation you can use this only on queries.
WithRunInBackground instructs Dgraph to run indexes in the background.
WithTnx configures a transaction to be used for the current execution.
WithTypePrefix option modifier to prevent fields to be prefixed.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Cursor represents pagination parameters.
No description provided by the author
FilterFn represents a filter function.
GeneratorOption options for the generator.
MutationBuilder used to construct mutations in a fluent way.
OperationExecutor represents a Dgraph executor for operations such as Queries and Mutations using the official dgo client.
No description provided by the author
No description provided by the author
No description provided by the author
QueryBuilder represents the public API for building a secure dynamic Dgraph query.
RawExpression represents a raw expression what you write what you get.
Response represents an operation response.
SchemaBuilder used to compose a Dgraph schema in a fluent manner.
SchemaExecutor executes schema operations.
TypeBuilder represents the public api to building Dgraph Compliant types.

# Interfaces

DB represents the public API for interacting with a DGraph Database.
DQLizer implementors are able to define a custom dql statement.
Executor implementors are able to define a custom way of executing queries and mutations.

# Type aliases

AllOfTerms syntactic sugar for the AllOfTerms expression, Expression: allofterms(predicate, value) Example: dql.AllOfTerms{"predicate": "value"}.
AllOfText syntactic sugar for the AllOfText expression, Expression: alloftext(predicate, value) Example: dql.AllOfText{"predicate": "value"}.
And represents a AND conjunction statement Example: dqlx.And{ dql.Eq{} }.
AnyOfTerms syntactic sugar for the AnyOfTerms expression, Expression: anyOfTerms(predicate, value) Example: dql.AnyOfTerms{"predicate": "value"}.
AnyOfText syntactic sugar for the AnyOfText expression, Expression: anyoftext(predicate, value) Example: dql.AnyOfText{"predicate": "value"}.
No description provided by the author
No description provided by the author
Eq syntactic sugar for the Eq expression, Expression: eq(predicate, value) Example: dql.Eq{"predicate": "value"}.
Exact syntactic sugar for the Exact expression, Expression: exact(predicate, value) Example: dql.Exact{"predicate": "value"}.
FullText syntactic sugar for the FullText expression, Expression: fulltext(predicate, value) Example: dql.FullText{"predicate": "value"}.
FuncType represents a function type.
Ge syntactic sugar for the Ge expression, Expression: ge(predicate, value) Example: dql.Ge{"predicate": "value"}.
Gt syntactic sugar for the Gt expression, Expression: gt(predicate, value) Example: dql.Gt{"predicate": "value"}.
Le syntactic sugar for the Le expression, Expression: le(predicate, value) Example: dql.Le{"predicate": "value"}.
Lt syntactic sugar for the Lt expression, Expression: lt(predicate, value) Example: dql.Lt{"predicate": "value"}.
Match syntactic sugar for the Match expression, Expression: match(predicate, value) Example: dql.Match{"predicate": "value"}.
OperationExecutorOptionFn used to modify options of the executor.
Or represents a OR conjunction statement Example: dqlx.Or{ dql.Eq{} }.
OrderDirection represent an order direction.
Regexp syntactic sugar for the Regexp expression, Expression: regexp(predicate, /pattern/) Example: dql.Regexp{"predicate": /pattern/}.
SchemaExecutorOptionFn represents an function modifier for the SchemaExecutor options.
No description provided by the author
Term syntactic sugar for the Term expression, Expression: term(predicate, value) Example: dql.Term{"predicate": "value"}.
TypeBuilderFn represents the closure function for the type builder.
TypeBuilderOptionModifier modifier option interface for a TypeBuilder.
UIDIn syntactic sugar for the UIDIn expression, Expression: uid_in(predicate, value) Example: dql.UIDIn{"predicate": "value"}.