Giter VIP home page Giter VIP logo

feathers-test-populate-etc's People

Contributors

eddyystop avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

feathers-test-populate-etc's Issues

Amazing populate hook! several questions:

  1. I like the following powerful population syntax very much:
include: { // Which child items to join to the parent item
        post: { // This name is only used for some defaults
          service: 'posts', // The service to populate from
          parentField: 'postId', // The matching field in the parent. Supports dot notation a.b.c
          childField: 'id', // The matching field in the child. Supports dot notation a.b.c
          include: {
            author: {
              service: 'users',
              parentField: 'author',
              childField: 'id' // Would convert a.b.c to find({'a.b.c':value}). Use .query or .select for something else.
            },
            comment: {
              service: 'comments',
              parentField: 'id',
              childField: 'postId',
              select: (hook, parent) => ({ something: { $exists: false }}), // add to query using runtime data
              nameAs: 'comments', // Parent prop name where to place the populated items
              asArray: true, // store as an array if result has just 1 element
              query: { // Normal feathers query syntax. Get selected fields from the last 5 comments
                $limit: 5,
                $select: ['title', 'content', 'postId'],
                $sort: { createdAt: -1 }
              },
            },
            readers: {
              service: 'users',
              parentField: 'readers', // This is an array, so id: { $in: { readers } } will be used.
              childField: 'id'
            }
          }
        }
      }

But just one question: when nameAs is absent, where to place the populated items in the parent? Say:

include: {
            author: {
              service: 'users',
              parentField: 'author',
              childField: 'id' // Would convert a.b.c to find({'a.b.c':value}). Use .query or .select for something else.
            },

Here we get from service users an item whose id is the parent's author, and in which field do we put this item in the parent? The doc didn't seem to make this clear.

  1. What's the relationship between select and query in the following part?
comment: {
              service: 'comments',
              parentField: 'id',
              childField: 'postId',
              select: (hook, parent) => ({ something: { $exists: false }}), // add to query using runtime data
              nameAs: 'comments', // Parent prop name where to place the populated items
              asArray: true, // store as an array if result has just 1 element
              query: { // Normal feathers query syntax. Get selected fields from the last 5 comments
                $limit: 5,
                $select: ['title', 'content', 'postId'],
                $sort: { createdAt: -1 }
              },
            },

I understand the select function returns an object that would be added into the query object, so basically the two are one thing, only that select is a function that accepting hook and parent as parameters so it is dynamic, but query is static. Is this right?

If so, I don't think it's necessary to make it into two different settings. We could only have one setting, say, query, and allow query to be either a static object or a function that dynamically returns an object using runtime data.

  1. BTW, what does parent mean in select: (hook, parent) => ({ something: { $exists: false }})? the parent service in the poplulation schema?

  2. I am not familiar with feathers-permissions so I didn't get how the permissions work. Any more examples?

  3. I am not very sure what serialize means here, either, since this term is never officially introduced in feathers docs. I found serializers are excluding things from the result but populaters are adding things into the result. Is that right?

  4. It's wonderful that the client side could determine which popluation schema should be used in a find opeartion. But the folloing syntax seems not very pretty:

  favorites.find({
    query: {
      _clientParams: { // how client passes params to server
        populate: 'standard', // Client wants favorites.standard populate. Supports dot notation a.b.c
        serialize: 'standard', // Client wants favorites.standard serialize. Supports dot notation a.b.c
      }
    }
  })

The _clientParams doesn't look nice with an underscore ahead. Maybe better to use something like $params. I understand currently only query is sent back to server, so it is a pity that we are not able to make it look nice like this:

  favorites.find({
    query: { ...},
    populate: 'standard', // Client wants favorites.standard populate. Supports dot notation a.b.c
    serialize: 'standard', // Client wants favorites.standard serialize. Supports dot notation a.b.c
  })

But even embedded in query we still be able to make it look nicer like this:

  favorites.find({
    query: {
      $populate: 'standard', // Client wants favorites.standard populate. Supports dot notation a.b.c
      $serialize: 'standard', // Client wants favorites.standard serialize. Supports dot notation a.b.c
    }
  })

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.