diff --git a/modus/sdk/assemblyscript/dgraph.mdx b/modus/sdk/assemblyscript/dgraph.mdx index e3084c9b..5d29d099 100644 --- a/modus/sdk/assemblyscript/dgraph.mdx +++ b/modus/sdk/assemblyscript/dgraph.mdx @@ -79,12 +79,35 @@ function dropAttr(connection: string, attr: string): string The attribute to drop from the Dgraph schema. -#### execute +#### escapeRDF -Execute a Dgraph query or mutation using a Dgraph Request object. +Ensures proper escaping of RDF string literals. ```ts -function execute(connection: string, request: Request): Response +function escapeRDF(value: string): string +``` + + + The RDF string literal to escape. + + +#### executeMutations + +Execute one or more mutations, without a filtering query. + + + +If you need to filter the mutations based on a query, use the +[`executeQuery`](#executequery) function instead, and pass the mutations after +the query. + + + +```ts +function executeMutations( + connection: string, + ...mutations: Mutation[] +): Response ``` @@ -92,9 +115,44 @@ function execute(connection: string, request: Request): Response manifest](/modus/app-manifest#connections). - - A Dgraph [`Request`](#request) object, describing the query or mutation to - execute. + + One or more [`Mutation`](#mutation) objects to execute. + + +#### executeQuery + +Execute a DQL query to retrieve data from a Dgraph database. + +Also used to execute a filtering query and apply one or more mutations to the +result of the query. + + + +If you need apply mutations _without_ a filtering query, use the +[`executeMutations`](#executemutations) function instead. + + + +```ts +function executeQuery( + connection: string, + query: Query, + ...mutations: Mutation[] +): Response +``` + + + Name of the connection, as [defined in the + manifest](/modus/app-manifest#connections). + + + + A [`Query`](#query) object describing the DQL query to execute. + + + + Optional parameters specifying one or more [`Mutation`](#mutation) objects to + execute on the nodes matched by the query. ### Types @@ -105,11 +163,16 @@ A Dgraph mutation object, used to execute mutations. ```ts class Mutation { - setJson: string, - delJson: string, - setNquads: string, - delNquads: string, - condition: string, + setJson: string + delJson: string + setNquads: string + delNquads: string + condition: string + withSetJson(json: string): Mutation + withDelJson(json: string): Mutation + withSetNquads(nquads: string): Mutation + withDelNquads(nquads: string): Mutation + withCondition(cond: string): Mutation } ``` @@ -127,15 +190,43 @@ class Mutation { - A string representing the data to set in the mutation in NQuads format. + A string representing the data to set in the mutation in RDF N-Quads format. - A string representing the data to delete in the mutation in NQuads format. + A string representing the data to delete in the mutation in RDF N-Quads + format. - A string representing the condition query for the mutation. + A string representing the condition query for the mutation, as a DQL `@if` + directive. + + + + Sets the `setJson` field of the mutation to the given `json` string. Returns + the `Mutation` object to allow for method chaining. + + + + Sets the `delJson` field of the mutation to the given `json` string. Returns + the `Mutation` object to allow for method chaining. + + + + Sets the `setNquads` field of the mutation to the given `nquads` string. + Returns the `Mutation` object to allow for method chaining. + + + + Sets the `delNquads` field of the mutation to the given `nquads` string. + Returns the `Mutation` object to allow for method chaining. + + + + Sets the `condition` field of the mutation to the given `cond` string, which + should be a DQL `@if` directive. Returns the `Mutation` object to allow for + method chaining. #### Query @@ -146,12 +237,13 @@ A Dgraph query object, used to execute queries. class Query { query: string = "" variables: Map = new Map() + withVariable(name: string, value: T): this } ``` Creates a new `Query` object with the given `query` and `variables`. `query` - is a Dgraph Query Language (DQL) query string, and `variables` is a + is a Dgraph Query Language (DQL) query string, and `variables` is an optional [`Variables`](#variables) object. @@ -160,13 +252,57 @@ class Query { - A map of query variables. + A map of query variables, with values encoded as JSON strings. + + + + +Sets a query variable with the given `name` and `value`. `name` is of type +`string`, and `value` can be a string, number, or boolean. + +Returns the `Query` object to allow for method chaining. + + + +The `withVariable` method is the preferred way to set query variables in a +`Query` object, and allows for fluent method chaining to add multiple variables. +For example: + +```ts +const query = new Query(` + query all($name: string, $age: int) { + all(func: eq(name, $name)) { + name + age + } + } +`) + .withVariable("name", "Alice") + .withVariable("age", 30) + +const response = dgraph.executeQuery("my-dgraph-connection", query) +``` + + + #### Request A Dgraph request object, used to execute queries and mutations. + + +{/* vale Google.Passive = NO */} + +This object was used by the `execute` function, which has been replaced by the +[`executeQuery`](#executequery) and [`executeMutations`](#executemutations) +functions. You should no longer need to create a `Request` object directly. + +{/* vale Google.Passive = YES */} + + + ```ts class Request { query: Query = new Query() @@ -195,6 +331,14 @@ default to `null`. A Variables object used to set query variables in a Dgraph query. + + +As of SDK version 0.17.1, it's no longer necessary to explicitly create a +`Variables` object. Instead, use the `withVariable` method on the +[`Query`](#query) object to set query variables. + + + ```ts class Variables { set(name: string, value: T): void @@ -204,9 +348,10 @@ class Variables { Sets a query variable with the given `name` and `value`. `name` is of type - `string`, and `value` can be of any type. + `string`, and `value` can be a string, number, or boolean. - Returns a map of all query variables set in the `Variables` object. + Returns a map of all query variables set in the `Variables` object, with + values encoded as strings. diff --git a/modus/sdk/assemblyscript/http.mdx b/modus/sdk/assemblyscript/http.mdx index 75e0be8d..444f72f7 100644 --- a/modus/sdk/assemblyscript/http.mdx +++ b/modus/sdk/assemblyscript/http.mdx @@ -108,8 +108,8 @@ The value can be of any type that's JSON serializable, including strings, numbers, boolean values, arrays, maps, and custom objects decorated with `@json`. -If the value is a `string` or an `ArrayBuffer` it's sent as-is, without JSON -serialization. +If the value is a `string`, an `ArrayBuffer`, or a `Uint8Array` it's sent as-is, +without JSON serialization. diff --git a/modus/sdk/go/dgraph.mdx b/modus/sdk/go/dgraph.mdx index bd78d649..5d3349fa 100644 --- a/modus/sdk/go/dgraph.mdx +++ b/modus/sdk/go/dgraph.mdx @@ -79,12 +79,66 @@ func DropAttr(connection, attr string) error The attribute to drop from the Dgraph schema. -#### Execute +#### EscapeRDF -Execute a Dgraph query or mutation using a Dgraph Request object. +Ensures proper escaping of RDF string literals. ```go -func Execute(connection string, request *Request) (*Response, error) +func EscapeRDF(value string) string +``` + + + The RDF string literal to escape. + + +#### ExecuteMutations + +Execute one or more mutations, without a filtering query. + + + +If you need to filter the mutations based on a query, use the +[`ExecuteQuery`](#executequery) function instead, and pass the mutations after +the query. + + + +```go +func ExecuteMutations( + connection string, + mutations ...*Mutation +) (*Response, error) +``` + + + Name of the connection, as [defined in the + manifest](/modus/app-manifest#connections). + + + + One or more pointers to [`Mutation`](#mutation) objects to execute. + + +#### ExecuteQuery + +Execute a DQL query to retrieve data from a Dgraph database. + +Also used to execute a filtering query and apply one or more mutations to the +result of the query. + + + +If you need apply mutations _without_ a filtering query, use the +[`ExecuteMutations`](#executemutations) function instead. + + + +```go +func ExecuteQuery( + connection string, + query *Query, + mutations ...*Mutation +) (*Response, error) ``` @@ -92,9 +146,33 @@ func Execute(connection string, request *Request) (*Response, error) manifest](/modus/app-manifest#connections). - - A pointer to a Dgraph [`Request`](#request) object, describing the query or - mutation to execute. + + A pointer to a [`Query`](#query) object describing the DQL query to execute. + + + + Optional parameters specifying pointers to one or more [`Mutation`](#mutation) + objects to execute on the nodes matched by the query. + + +#### NewMutation + +Creates a new [`Mutation`](#mutation) object. + +```go +func NewMutation() *Mutation +``` + +#### NewQuery + +Creates a new [`Query`](#query) object from a DQL query string. + +```go +func NewQuery(query string) *Query +``` + + + The DQL query to execute. ### Types @@ -111,6 +189,13 @@ type Mutation struct { DelNquads string Condition string } + +// methods +func (*Mutation) WithSetJson(json string) *Mutation +func (*Mutation) WithDelJson(json string) *Mutation +func (*Mutation) WithSetNquads(nquads string) *Mutation +func (*Mutation) WithDelNquads(nquads string) *Mutation +func (*Mutation) WithCondition(cond string) *Mutation ``` @@ -122,15 +207,48 @@ type Mutation struct { - A string representing the data to set in the mutation in NQuads format. + A string representing the data to set in the mutation in RDF N-Quads format. - A string representing the data to delete in the mutation in NQuads format. + A string representing the data to delete in the mutation in RDF N-Quads + format. - A string representing the condition query for the mutation. + A string representing the condition query for the mutation, as a DQL `@if` + directive. + + + + A string representing the condition query for the mutation, as a DQL `@if` + directive. + + + + Sets the `SetJson` field of the mutation to the given `json` string. Returns + the `Mutation` object to allow for method chaining. + + + + Sets the `DelJson` field of the mutation to the given `json` string. Returns + the `Mutation` object to allow for method chaining. + + + + Sets the `SetNquads` field of the mutation to the given `nquads` string. + Returns the `Mutation` object to allow for method chaining. + + + + Sets the `DelNquads` field of the mutation to the given `nquads` string. + Returns the `Mutation` object to allow for method chaining. + + + + Sets the `condition` field of the mutation to the given `cond` string, which + should be a DQL `@if` directive. Returns the `Mutation` object to allow for + method chaining. #### Query @@ -142,6 +260,9 @@ type Query struct { Query string Variables map[string]string } + +// methods +func (*Query) WithVariable(key string, value any) *Query ``` @@ -149,13 +270,57 @@ type Query struct { - A map of query variables. + A map of query variables, with values encoded as strings. + + + + +Sets a query variable with the given `name` and `value`. `name` is of type +`string`, and `value` can be a string, number, or boolean. + +Returns the `*Query` object to allow for method chaining. + + + +The `WithVariable` method is the preferred way to set query variables in a +`Query` object, and allows for fluent method chaining to add multiple variables. +For example: + +```go +query := NewQuery(` + query all($name: string, $age: int) { + all(func: eq(name, $name)) { + name + age + } + } +`). + WithVariable("name", "Alice"). + WithVariable("age", 30) + +response := dgraph.ExecuteQuery("my-dgraph-connection", query) +``` + + + #### Request A Dgraph request object, used to execute queries and mutations. + + +{/* vale Google.Passive = NO */} + +This object was used by the `Execute` function, which has been replaced by the +[`ExecuteQuery`](#executequery) and [`ExecuteMutations`](#executemutations) +functions. You should no longer need to create a `Request` object directly. + +{/* vale Google.Passive = YES */} + + + ```go type Request struct { Query *Query diff --git a/modus/sdk/go/http.mdx b/modus/sdk/go/http.mdx index 2070b733..4c98ad59 100644 --- a/modus/sdk/go/http.mdx +++ b/modus/sdk/go/http.mdx @@ -106,6 +106,8 @@ types: - A [`Content`](#content) object, or a pointer to one. - A `[]byte` of binary content, or a pointer to one. - A `string` of text content. +- Any other object that's JSON serializable. The content then becomes the JSON + representation of the object. diff --git a/styles/config/vocabularies/general/accept.txt b/styles/config/vocabularies/general/accept.txt index 872936f5..138d294f 100644 --- a/styles/config/vocabularies/general/accept.txt +++ b/styles/config/vocabularies/general/accept.txt @@ -10,6 +10,7 @@ [Dd]ropAll [Dd]ropAttr [Ee]mbedder +[Ee]xecuteMutations [Ee]xecuteQuery [Ff]etch [Gg]etLabels @@ -64,10 +65,11 @@ LLM Logf MySQL|mysql NPM|npm -NQuads +NQuads|nquads PostgreSQL|postgresql PUT repo +RDF REST|[Rr]est Scattergories SDK|sdk