ExAliyunOts.DSL.condition

You're seeing just the macro condition, go back to ExAliyunOts.DSL module for more information.
Link to this macro

condition(row_existence)

View Source (macro)

Specs

condition(row_existence()) :: map()

Official document in Chinese | English

Example

import MyApp.TableStore

update_row "table", [{"pk", "pk1"}],
  delete_all: ["attr1", "attr2"],
  return_type: :pk,
  condition: condition(:expect_exist)

The available existence options: :expect_exist | :expect_not_exist | :ignore, here are some use cases for your reference:

Use condition(:expect_exist), expect the primary keys to row is existed.

  • for put_row/5, if the primary keys have auto increment column type, meanwhile the target primary keys row is existed, only use condition(:expect_exist) can successfully overwrite the row.
  • for update_row/4, if the primary keys have auto increment column type, meanwhile the target primary keys row is existed, only use condition(:expect_exist) can successfully update the row.
  • for delete_row/4, no matter what primary keys type are, use condition(:expect_exist) can successfully delete the row.

Use condition(:expect_not_exist), expect the primary_keys to row is not existed.

  • for put_row/5, if the primary keys have auto increment type,
    • while the target primary keys row is existed, only use condition(:expect_exist) can successfully put the row;
    • while the target primary keys row is not existed, only use condition(:ignore) can successfully put the row.

Use condition(:ignore), ignore the row existence check

  • for put_row/5, if the primary keys have auto increment column type, meanwhile the target primary keys row is not existed, only use condition(:ignore) can successfully put the row.
  • for update_row/4, if the primary keys have auto increment column type, meanwhile the target primary keys row is not existed, only use condition(:ignore) can successfully update the row.
  • for delete_row/4, no matter what primary keys type are, use condition(:ignore) can successfully delete the row if existed.

The batch_write/3 operation is a collection of put_row / update_row / delete_row operations.

Link to this macro

condition(row_existence, filter_expr)

View Source (macro)

Similar to condition/1 and support use filter expression (please see filter/1) as well, please refer them for details.

Example

import MyApp.TableStore

delete_row "table",
  [{"key", "key1"}, {"key2", "key2"}],
  condition: condition(:expect_exist, "attr_column" == "value2")