jacksontj / dataman

MIT License
9 stars 4 forks source link

Allow user to specify constraint for Set operation #2

Open jstarw opened 6 years ago

jstarw commented 6 years ago

Currently when performing a Set operation on a collection, the constraint automatically defaults to the primary key. For example, the query generated would be something like this:

INSERT INTO <collection> (<columns>) VALUES (<values>) ON CONFLICT (_id) DO UPDATE SET ...

It would be great to have the ability to specify which constraint to use for set operation. If the collection has a unique constraint, the user should be able to do set operations for those cases:

INSERT INTO <collection> (<columns>) VALUES (<values>) ON CONFLICT (<constraint>) DO UPDATE SET ...

This can be implemented by accepting an additional argument, constraint, when calling the operation. It can be either a list of column names corresponding to the constraint, or just the constrain name itself.

{
  "Type": "set",
  "Args": {
    "db": "event_sum",
    "collection": "event_base",
    "record": {
      "service_id":          evt.ServiceId,
      "event_type":          evt.EventType,
      "event_name":          evt.EventName,
      "processed_data":      evt.ProcessedData,
      "processed_data_hash": evt.ProcessedDataHash
    },
    "constraint": ["service_id", "event_type", "processed_data_hash"]
  }
}
zelin-l commented 6 years ago

Seconded. This would be very useful