Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify unique identifier uuid in a property #104

Closed
1 task done
jannyHou opened this issue Apr 24, 2017 · 3 comments
Closed
1 task done

specify unique identifier uuid in a property #104

jannyHou opened this issue Apr 24, 2017 · 3 comments

Comments

@jannyHou
Copy link
Contributor

jannyHou commented Apr 24, 2017

Feature

  • Feature request

Background of feature

After triaging/helping solve some user's problem, I feel people use cloudant connector are not aware of couchdb is not designed to change same document frequently and multiple times, couchdb stores status change by creating different documents and including the same unique id to tell that they are attached to the same item, not updating the same document.

Take the following scenario as an example:

  • A customer places an order, when he/she selects all items and clicks button place order, a purchase document is created as:

    {
    "_id": "023f7a21dbe8a4177a2816e4ad1ea27e",
    "model": "purchase",
    "order_id": "320afa89017426b994162ab004ce3383",
    "basket": [
       {
         "product_id": "A56"
        },
        {
          "product_id": "B32"
        }
     ]
    }

    Please note the purchase document has a property called order_id to refer to a specific order, and the model property represents its loopback model name

  • And then clicks button checkout to make payment, two payment documents(since there are two items in the order), with same order_id as the purchase document, are created as:

    {
    "_id": "bf70c30ea5d8c3cd088fef98ad678e9e",
    "model": "payment",
    "account_id": "985522332",
    "order_id": "320afa89017426b994162ab004ce3383",
    "value": 6.46,
    "method": "credit card",
    "payment_reference": "AB9977G244FF2F667"
    }
    {
     "_id": "12c0ea6cd3d2c6e3b1d34442aea6a2d9",
     "type": "payment",
     "account_id": "985522332",
     "order_id": "320afa89017426b994162ab004ce3383",
     "value": 20.00,
     "method": "voucher",
     "payment_reference": "Q88775662377224"
    }

    So in this case, we use purchase and payment as loopback models to represent the events of an order, and an unique identifier(uuid) order_id to make sure related events refer to a certain order.
    User can see the status of an order by creating a view of everything you know about an order_id as a ledger containing necessary informations.
    How to define those informations are beyond the topic of this issue, and well documented in Cloudant#transaction's doc(check the following link):

Additional information (Node.js version, LoopBack version, etc)

The example above is from Cloudant#transaction doc, for details, please refer to https://docs.cloudant.com/transactions.html

Proposal of implementation

loopback model supports defining a property as uuid, see https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#general-property-properties
While I am not sure does it treat uuid the same way as what cloudant does with endpoint GET _uuids, will investigate more on that.

  • If there is difference between them, we need a function in lib/cloudant.js to generate an uuid.
  • If they are same, then this story would be a doc story.
@jannyHou
Copy link
Contributor Author

jannyHou commented May 3, 2017

cc @kjdelisle this is the issue that discuss uuid.

@kjdelisle kjdelisle removed the apex label Jul 5, 2017
@stale stale bot added the stale label Sep 9, 2017
@stale
Copy link

stale bot commented Sep 9, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Sep 23, 2017

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Sep 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants