Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Not everything can fit in rows and columns - GD...

Not everything can fit in rows and columns - GDE Summit 2019

A quick presentation on Dgraph and its ORM Dgraph-ORM given at the Google Developer Experts Summit 2019.

Francesc Campoy Flores

October 26, 2019
Tweet

More Decks by Francesc Campoy Flores

Other Decks in Programming

Transcript

  1. Not everything can fit in rows and columns Ashok Vishwakarma

    GDE India @_avishwakarma Dgraph and draph-orm GDE Summit 2019 Francesc Campoy GDE / VP Product at Dgraph Labs @francesc
  2. Graphs Graph in RDBMS Graph in NoSQL Graph Databases Dgraph

    Architecture Query Language DgraphORM Agenda
  3. name: Steven Spielberg name: Jaws year: 1975 name: Jurassic Park

    year: 1993 name: Thriller name: Science Fiction name: Comedy directed directed genre genre genre genre Node Relationship A Movie Graph
  4. Complex Mapping Process one-to-one: foreign keys one-to-many: repeated foreign keys

    many-to-many: seperate table Traversals require joins Graphs in RDBMS
  5. ID int Name string Movie ID int Name string Year

    int … DirectorID int FK Director Fetching all the movies directed by a director requires an index for performance. Movie - Director in RDBMS
  6. Twilight Zone - The Movie Directed By Steven Spielberg John

    Landis Joe Dante George Miller Good luck migrating that table :) Movies can have multiple director
  7. MovieID int DirectorID Movie ID int Name string Year int

    MovieDirector We had to modify our logical model to fit the technology, bringing in unnecessary complexity. ID int Name string Director Movie - Director in RDBMS
  8. No foreign keys Many copies of information Keep them all

    up to date Seriously are you kidding? Traversals require multiple queries Graphs in NoSQL
  9. Universal Identifiers (UIDs) 0x1 <name> “Jaws” 0x1 <recorded_year> 1975 0x1

    <directed_by> 0x2 0x2 <name> “Steven Spielberg” 0x1 and 0x2 are UIDs (Universal IDentifiers). <name>, <recorded_year>, etc. are predicates. “Jaws”, “Steven Spielberg”, and 1975 are values. Dgraph Data Modeling
  10. GraphQL +- Inspired by GraphQL Modified for better support Pure

    GraphQL Native support (coming soon) Playground - https://play.dgraph.io/ Dgraph Query Language
  11. Mutation Dgraph Query Language { “set”: { “name”: "Alice" }

    } Creates a new UID and associate its value “Alice” with predicate <name> { "data": { "code": "Success", "message": "Done", "uids": { "alice": "0x1" } }, "extensions": {...} }
  12. Mutation Dgraph Query Language { “set”: { “name”: "Bob", “knows”:

    [ “uid”: “0x1” ] } } Creates a new UID and associate its value “Bob” with predicate <name> and associate predicate <knows> with 0x1 UID { "data": { "code": "Success", "message": "Done", "uids": { "bob": "0x2" } }, "extensions": {...} } https://play.dgraph.io/
  13. Query Dgraph Query Language { q(func: uid(0x1, 0x2)) { uid

    name } } { "data": { "q": [ { "uid": "0x1", "name": "Alice" }, { "uid": "0x2", "name": "Bob" }] }, "extensions": {...} } 0x1 0x2 Alice Bob name name Fetches uid and name of nodes of UIDs 0x1 and 0x2 https://play.dgraph.io/
  14. { q(func: uid(0x2)) { uid name knows { uid name

    } } } Query Dgraph Query Language { "data": { "q": [{ "uid": "0x2", "name": "Bob", "knows": [{ "uid": "0x1", "name": "Alice" }] }] }, "extensions": {...} } 0x1 0x2 Alice Bob name name knows https://play.dgraph.io/
  15. Simplified Schema creation, queries and mutations for Dgraph Inspired by

    Mongoose and Sequelize Built on top of dgraph-js http://bit.ly/dgraph-orm-docs Introducing Dgraph ORM
  16. Schema creation // User.js import { Schema, model, Types }

    from ‘dgraph-orm’; const UserSchema = new Schema(‘user’, { name: { type: Types.STRING }, ... knows: { Type: Types.UID, model: ‘user’ } }); export default const User = model(UserSchema) http://bit.ly/dgraph-orm-docs user.name: string . ... user.knows [uid] .
  17. Schema creation import User from ‘./User’; // Create User Alice

    const alice = await User.create({ name: ‘Alice’ }); // Create User bob const bob = await User.create({ name: ‘Bob’, knows: alice.uid }); http://bit.ly/dgraph-orm-docs // Querying const users = await User.uid(‘0x2’, { include: { knows: { as: ‘knows’ } } }); console.log(users); { "data": { "user": [{ "uid": "0x2", "name": "Bob", "knows": [{ "uid": "0x1", "name": "Alice" }] }] }, "extensions": {...} }
  18. Thank You! GDE Summit 2019 Ashok Vishwakarma GDE India @_avishwakarma

    Francesc Campoy GDE / VP Product at Dgraph Labs @francesc