Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

How to handle database locking #3

Open
markwylde opened this issue Nov 14, 2019 · 0 comments
Open

How to handle database locking #3

markwylde opened this issue Nov 14, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@markwylde
Copy link
Collaborator

markwylde commented Nov 14, 2019

I feel like locking won't be implemented until later on in the project, but a potential solution could be this:

{
  "name": "orders",

  "schema": {
    "productId": ["required", "number"],
    "customerId": ["required", "number"],
    "timestamp": ["required", "number"]
  },

  "hooks": {
    "POST": {
      "before": [
        "collection('products').get(body.productId).lock()"
      ],
      "after": [
        "collection('products').get(body.productId).pluck('stock').subtract(1)"
      ],
      "finally": [
        "collection('products').get(body.productId).unlock()"
      ]
    }
  }
}
@markwylde markwylde added the enhancement New feature or request label Nov 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant