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

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.

D8e5d79ca42edc07693b9c1aacaa7e5e?s=128

Francesc Campoy Flores

October 26, 2019
Tweet

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. A representation of objects and their relation called node and

    edges. Graphs
  4. 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
  5. 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
  6. 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
  7. Twilight Zone - The Movie Directed By Steven Spielberg John

    Landis Joe Dante George Miller Good luck migrating that table :) Movies can have multiple director
  8. 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
  9. No foreign keys Many copies of information Keep them all

    up to date Seriously are you kidding? Traversals require multiple queries Graphs in NoSQL
  10. No mapping No joins Traversals are fast Deep traversal are

    possible Graph Databases
  11. World’s most advanced Graph Database - written in Go https://dgraph.io/

    Meet Dgraph
  12. 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
  13. GraphQL +- Inspired by GraphQL Modified for better support Pure

    GraphQL Native support (coming soon) Playground - https://play.dgraph.io/ Dgraph Query Language
  14. Demo time!

  15. 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": {...} }
  16. 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/
  17. Current Dataset 0x1 0x2 knows Alice Bob name name https://play.dgraph.io/

  18. 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/
  19. { 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/
  20. 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
  21. 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] .
  22. 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": {...} }
  23. Demo time!

  24. Thank You! GDE Summit 2019 Ashok Vishwakarma GDE India @_avishwakarma

    Francesc Campoy GDE / VP Product at Dgraph Labs @francesc