| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A NodeJS Dgraph client (created before the official Dgraph client was released). This library now uses the official Dgraph client, but remains mostly backwards compatible with the previous release (see migration notes below).
Install with:
npm install dgraph-node grpc
import DgraphClient from 'dgraph-node'
// const DgraphClient = require('dgraph-node').default
// Create a new client (these are the defaults - no need to pass these!)
let client = new DgraphClient({
url: ['localhost:9080'], // can provide multiple urls if you have a cluster
debug: false,
credentials: grpc.credentials.createInsecure()
})
// Set mutation
await client.mutate({
set: '<_:bob> <name> "Bob" .'
})
// Delete mutation
await client.mutate({
del: '<0x100> * * .',
})
// Query
await client.query(`
query {
q(func: uid(0xcceb)) {
name
}
}
`)
// Transactions
const txn = client.txn() // Just setting up instance (no call to Dgraph)
// Same API as above on the txn instance
await txn.mutate({
set: '<_:bob> <name> "Bob" .'
})
...
// Commit when you're done
// Dgraph will error if the transaction fails (due to another edit)
await txn.commit() // or txn.discard()Creates a new instance of the Dgraph client.
| Property | Default | Description |
|---|---|---|
| url | [localhost:9080] | List of IP and port of Dgraph - can be an array of URL for a cluster setup. |
| debug | false | Add additional console logs |
| credentials | grpc.credentials.createInsecure() | Valid grpc.credentials. See gPRC docs |
Set or delete nodes from Dgraph. Mutation is an object with set and del properties. By default, it will commit changes immediately to Dgraph.
mutation
options (set to true when not using a txn):
Query the Dgraph DB.
Update the schema.
let client = new DgraphClient()
client.alter(`name: string .`)Drop the entire Dgraph database. Removes all data (be careful!)
let client = new DgraphClient()
client.dropAll()Locally creates a transaction with query(queryStr, vars), mutate(mutation, options), commit() and abort() methods. These methods function the same as above.
Start a Dgraph instance:
docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 -p 9080:9080 -p 8000:8000 -p 8081:8081 dgraph/dgraph:v1.0.3 bash -c "dgraph -h & dgraph zero & dgraph server --memory_mb 2048 --zero localhost:5080 & dgraph-ratel"
Run (at project root):w yarn test
Dgraph Client - https://github.com/reicheltp/dgraph-client
| Back | FazBrowse Home | New Git URL |