GithubHelp home page GithubHelp logo

bamanczak / 133-firestore-joins-custom-rx-operators Goto Github PK

View Code? Open in Web Editor NEW

This project forked from angularfirebase/133-firestore-joins-custom-rx-operators

0.0 1.0 0.0 108 KB

E133 - Join documents and collections in Firestore with custom RxJS operators

JavaScript 10.83% TypeScript 81.05% HTML 7.08% CSS 1.03%

133-firestore-joins-custom-rx-operators's Introduction

Firestore Join Queries with Custom RxJS Operators

Advanced RxJS Techniques to perform SQL-inspired joins with Firestore.

Document Joins

docJoin - Joins multiple docs together into a single unified object. Useful when you have multiple has-one relationships.

+users
    docId=jeff {
      car: 'subaru'
      pet: 'humphrey'
    }

+pets
    docId=humphrey {
        type: 'dog'
        food: 'kibble'
    }

+cars
    docId=subaru {
        model: 'Legacy'
        doors: 4
    }
afs.collection('users')
      .valueChanges()
      .pipe(
        docJoin(afs, { car: 'cars', pet: 'pets' } )
      )


// result

{
    ...userData
    pet: { type: 'dog', food: 'kibble' },
    car: { model: 'Legacy', doors: 4 }
}

Collection Joins

leftJoin - Joins two collections by a shared document field. Useful when you have a many-to-many relationship, such as Users have many Orders and Order belongs to User.

+users
    docId=jeff {
        userId: 'jeff'
        ...data
    }

+orders
    docId=a {
        orderNo: 'A'
        userId: 'jeff'
    }

    docId=b {
        orderNo: 'B'
        userId: 'jeff'
    }
afs.collection('users')
      .valueChanges()
      .pipe(
        leftJoin(afs, 'userId', 'orders')
      )


// result

[{
    ...userData
    orders: [{ orderNo: 'A', userId: 'jeff' }, { orderNo: 'B', userId: 'jeff' }]
}]

leftJoinDocument - Joins a related doc to each item in a collection. Useful when the documents each have a has-one relationship to some other document. i, e. user has_one country.

+users
    docId=jeff {
        ...data
        location: usa
    }

+countries
    docId=usa {
        name: 'USA'
        capital: 'Washington D.C.'
    }
afs.collection('users')
      .valueChanges()
      .pipe(
        innerJoinDocument(afs, 'location', 'countries')
      )


// result

[
    {
        ...userData
        location: { name: 'USA', capital: 'Washington D.C.' }
    },
]

133-firestore-joins-custom-rx-operators's People

Contributors

codediodeio avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.