Socket
Socket
Sign inDemoInstall

dgraph-js-extras

Package Overview
Dependencies
174
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dgraph-js-extras

Functions to use with dgraph


Version published
Maintainers
1
Install size
901 kB
Created

Changelog

Source

0.8.1 (2019-04-27)

Bug Fixes

  • upsert-edge-list: await the transaction.commit (55b4286)

<a name="0.8.0"></a>

Features

  • src/*: change now in function names to commit (2f66e99), closes #11

BREAKING CHANGES

  • src/*: Any function that previously had the word now, has the word commit in it instead.

<a name="0.7.0"></a>

Readme

Source

DGraph JS Extras

A library of helper functions to accompany the dgraph-js library.
  • 0 dependencies just dgraph-js and grpc are needed as peer dependencies.
  • 100% test coverage.
  • Written in Typescript just like the DGraph library so you get IntelliSense.
  • Write one line statements to persist data that would take multiple lines with the base library.

Functions including "commit" indicate they will be set to "commitNow" Functions including "txn" indicate they create their own transactions and can be directly awaited.

This library is pre 1.0 and there might be some small API changes, that said everything is a small function so you could always ctrl-c ctrl-v it out of the repo if things change.

Example: persist two new nodes, return the node ids

 const users = [
    { username: 'foo' }
    { username: 'bar' }
 ]
 
 const id1 = await xExtractUids(xSetJSONCommitTxn(users, dgraphClient));

Example: upsert helper function

const updateJunior = {
    skill: 'Javascript',
    level: 10,
    x: 'y',
    y: 'y',
    z: 'y'
};

// If you already had a node in the db that looks like:
const existingNode = {
    skill: 'Javascript',
    level: 10,
    x: 'foo',
    y: 'foo',
    z: 'foo'
};

// You can pass an array of values to update, or just an object.
const updates = [updateJunior];

// The basicEqualityUpsertFn below will find any nodes that has both skill and level predicates.
const upsertFn = basicEqualityUpsertFn(['skill', 'level']);

// x, y and z will be updated from 'foo' to 'y', because both skill and level match.

// If no node matched both skill 'Javascript' and level '10' a new node would be created.
// We can await this direclty as it includes commit and txn postfix. 
const [uid] = await xUpsertCommitTxn(upsertFn, updates, dgraphClient);

// It returns the uids of the found or created nodes.
// If you want it as part of a bigger transaction there is also a xUpsertObject function you could use. 

Checkout all the functions in API documentation

Contribute?

Please do feel free to submit a PR.

Testing

Install docker then run yarn run dgraph-test-db-up Now just call yarn run test

You can also setup Wallaby JS as a test runner. I am a fan.

Deploy workflow
  1. Make changes
  2. Commit those changes yarn run commit
  3. Test yarn run test
  4. Bump version in package.json
  5. Generate changelog yarn run generate-changelog
  6. Publish yarn publish
  7. Commit package.json, CHANGELOG.md and lib files
  8. Git tag - needed by changelog to know what version to attribute the commits to
  9. Push

FAQs

Last updated on 27 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc