fenos / dqlx Goto Github PK
View Code? Open in Web Editor NEWA DGraph Query Builder
Home Page: https://fenos.github.io/dqlx/
A DGraph Query Builder
Home Page: https://fenos.github.io/dqlx/
Hi,
I've not found any information about the @cascade directive in the library's documentation (I assume it's just not supported yet).
I was thinking about the "ugly" workaround:
Can you give me a solution on how to add @cascade for my query? It's crucial for one of my functions.
Also, it would be nice to be able to modify the query string more directly with function, which would allow adding custom parts to the query at the root level (next to filters etc.). For example, when Dgraph would release another part of the query, needed to be placed at the root level then it would be easy to implement that part without a specific function from the DQLX package (considering that there isn't a function meant to add that part)
with git main branch(8ff4e72) code and dgraph verion 23.1.0.
Conditional Upsert not work
data := []map[string]interface{}{
{
"uid": "uid(v)",
"email": "[email protected]",
"name": "first name"
},
}
userByEmailQuery := dqlx.Query(dqlx.EqFn("email", "[email protected]")).
.Select(v as uid name
)
condition := dqlx.Condition(dqlx.Eq("len(v)", "1"))
resp, err := db.Mutation().
Query(userByEmailQuery).
Condition(condition).
Set(data).
Execute(ctx)
but i user dgo api, it works
query = `
query {
user as var(func: eq(email, "[email protected]"))
}mu := &api.Mutation{ Cond:
@if(eq(len(user), 1)), // Only mutate if "[email protected]" belongs to single user. SetNquads: []byte(
uid(user) "first name" .`),
}
req := &api.Request{
Query: query,
Mutations: []*api.Mutation{mu},
CommitNow: true,
}
// Update email only if exactly one matching uid is found.
_, err = dg.NewTxn().Do(ctx, req)
This solves it, I don't know if it will introduce other problems
diff --git a/predicate.go b/predicate.go
index 96cd546..97c9031 100644
--- a/predicate.go
+++ b/predicate.go
@@ -221,22 +221,22 @@ func EscapePredicate(field string) string {
predicate, alias, directive = parsePredicate(predicate)
if alias != "" {
alias = fmt.Sprintf("<%s>:", alias)
alias = fmt.Sprintf("%s:", alias)
}
return fmt.Sprintf("%s %s %s<%s>%s", varName, asKeyword, alias, predicate, directive)
return fmt.Sprintf("%s %s %s%s%s", varName, asKeyword, alias, predicate, directive)
}
field, alias, directive = parsePredicate(field)
if alias != "" {
alias = fmt.Sprintf("<%s>:", alias)
alias = fmt.Sprintf("%s:", alias)
}
if strings.HasPrefix(field, "expand(") {
return fmt.Sprintf("%s%s%s", alias, field, directive)
}
return fmt.Sprintf("%s<%s>%s", alias, field, directive)
return fmt.Sprintf("%s%s%s", alias, field, directive)
}
Can someone help me understand this?
The following code generates the error result must be a pointer
.
var data []map[string]interface{}
client.Query(dqlx.HasFn("name")).
Filter(
dqlx.UID("0x12345"),
).Select(`
name
`).UnmarshalInto(data).Execute(ctx)
Currently, the response of any mutation returns a map of uids and an empty JSON. This is 100% wrong for the following reasons:
schema := db.Schema()
schema.Type("User", func(user *dqlx.TypeBuilder) {
user.String("name").IndexTerm()
user.String("phone")
})
err = schema.Alter(ctx, dqlx.WithDropAllSchema(true))
if err != nil {
panic(err)
}
schema index not work.
get chema from https://play.dgraph.io/?local :
: string .
: string .
Inserting 10,000 pieces of data in dgraph is very slow, but inserting 10,000 pieces of data at one time is very fast. Can dqlx add the function of combining query & mutation to improve performance?
hi, Thank you for your library:
bugs:
When will the new version be released?
Hey everyone,
First thank you for this amazing repo. My issue is about EdgeAS;
var output []map[string]interface{}
_, err := r.Conn.QueryType("User").
Filter(
dqlx.UID(uid),
).
EdgeAs("total", "friendship", dqlx.Facets(dqlx.And{
dqlx.GtFn("requested_at", util.BeginningOfDay().Unix()),
dqlx.LtFn("requested_at", util.EndOfDay().Unix()),
}), dqlx.Select("uid")).
EdgeAs("to", "friendship", dqlx.UID(otherUSER), dqlx.Facets(dqlx.And{
dqlx.GtFn("requested_at", util.BeginningOfWeek().Unix()),
dqlx.LtFn("requested_at", util.EndOfWeek().Unix()),
}), dqlx.Select("uid")).
UnmarshalInto(&output).
Execute(ctx)
log.Print(output)
when I run it, I'm getting an error as
"rpc error: code = Unknown desc = line 1 column 35: Expected Left round brackets. Got: lex.Item [9] \"func\" at 1:35",
And the generated DQL is
query Rootquery($0:string, $1:int, $2:int, $3:int, $4:int, $5:string) { to as(func: type(<User>)) @filter(uid($0)) { <hey> @facets((gt(<requested_at>,$1) AND lt(<requested_at>,$2))) { <uid> } <hey> @facets((gt(<requested_at>,$3) AND lt(<requested_at>,$4))) @filter(uid($5)) { <uid> } } }
map[$0:0x57 $1:1662760800 $2:1662847199 $3:1662242400 $4:1662847199 $5:0x56]
anyone can help me ?
@fenos Is there a way to .Select()
all of the fields instead? Also, is there a way to inject expand(_all_)
in the selection?
I've encountered an issue where I have an object that satisfies the json.Unmarshaler
interface which is not being respected by Response.Unmarshal
.
It would likely be a good idea to remove the dependency on a map[string]interface{}
and then mapstructure
here and instead make use of json.RawMessage
. This also solves issues with decoding time.Time
values as Time
already implements the json.Unmarshaler
interface for RFC 3339 formatted strings.
Hello,
Is there any way to dynamically construct a filter based on json data or a golang struct?
data := []map[string]interface{}{
{
"uid": "uid(v)",
"email": "[email protected]",
"name": "first name"
},
}
userByEmailQuery := dqlx.Query(dqlx.EqFn("email", "[email protected]")).
.Select(`
v as uid
name
`)
resp, err := db.Mutation().
Query(userByEmailQuery).
Set(data).
Execute(ctx)
The above example does not work, as userByEmailQuery
is of type dqlx.QueryBuilder
and Query() needs dqlx.DQLizer
@fenos Since there is no godoc, it is really hard to read the library. Are there any plans for creating documentation?
https://fenos.github.io/dqlx/docs/mutations/set
The example has a dot to much and does not work since the type does not fit
data := []map[string]interface{}{
{
"uid": "uid(v)",
"email": "[email protected]",
"name": "first name"
},
}
userByEmailQuery := dqlx.Query(dqlx.EqFn("email", "[email protected]")).
.Select(` // There shouldn't be a Dot here
v as uid
name
`)
resp, err := db.Mutation().
Query(userByEmailQuery). // Type does not implement 'DQLizer'
Set(data).
Execute(ctx)
Unfortunately due to lack of time and passion for Dgraph i'm unable to maintain the project as i'd like to.
If any of you would like to be a maintainer of dqlx please comment below
Hi, thank you for your library,
I was trying to make an upsert block https://dgraph.io/docs/mutations/upsert-block/#example-of-uid-function and I see in your documentation: https://fenos.github.io/dqlx/docs/mutations/set#logical-upsert the way to do it. But there is a type error.
In your example you add a Query in the mutation like this:
resp, err := db.Mutation().
Query(userByEmailQuery).
Set(data).
Execute(ctx)
but the query method has a dependency on an interface DQLizer which has the method signature: ToDQL() (query string, args []interface{}, err error)
Using the query builder in your example:
userByEmailQuery := dqlx.Query(dqlx.EqFn("email", "[email protected]")).
.Select(`
v as uid
name
`)
given us an instance of QueryBuilder which has the method ToDQL() (query string, args map[string]string, err error)
that is not match to the DQLizer method:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.