Skip to content

specify unique identifier uuid in a property #104

@jannyHou

Description

@jannyHou

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions