Now, this is not the end. It is not even the beginning of the end. But it is, perhaps, the end of the beginning. — Winston Churchill

Updating data is usually not the end, but usually a progress of a workflow.  Shipping follows ordering; inventory update follows shipping; adjusting credit follows returning;  The next step in the process is required to act to keep the workflow going. The workflows can be simple with few steps or complex with hundreds of steps.  Business Process Management (BPM) is an industry by itself.

Couchbase 5.5 introduced Evening service. Developers can write a Javascript function to execute upon a change to the data. We refer inserts, Updates, Merges, and Deletions together as mutations. Multiple specific use cases have been documented for developing these 이벤트 함수.

JSON 카우치베이스의 데이터 모델은 자바스크립트.  N1QL is SQL for JSON. The eventing functions are written in Javascript and has integrated N1QL. Using the Eventing functions, writing procedural business logic with instant access to data easy.

Here’s the lifecycle of the functions from a developer perspective. For every mutation, you can define any number of these functions to be executed. It’s the developer responsibility to size the execution times of the functions, depending on the number of mutations.

Here’s the lifecycle of the Eventing functions:

 

For every insert, update or delete (direct or expiry), you can execute one or more javascript functions.  These functions can read the new data and type of action and then execute the subsequent action. This functionality is well described in Couchbase blogs, and articles.

Statement Type Eventing Function Invoked
선택 없음
삽입 OnUpdate().  The function is invoked once per document inserted. Simple insert inserts a single document. Inserts can have multiple documents using multiple documents in the VALUES clause or can insert multiple documents via INSERT INTO…SELECT statement.
업데이트 OnUpdate() is invoked once per document updated, except when multiple updates on the same document is deduped into a single update. Update statement can update multiple documents.
UPSERT OnUpdate().  The behavior is similar to INSERT.
삭제 OnDelete(). Invoked once per documented deleted.
MERGE OnUpdate() and/or OnDelete() depending on the insert, update, and delete actions.
CREATE INDEX, DROP INDEX, EXPLAIN, PREPARE, GRANT, REVOKE No eventing function is invoked.
실행 Depends on the type of the statement executed.

These functions can also execute N1QL statements.  Rest of the article looks at all aspects of N1QL executed in Eventing Functions.

N1QL Statements in Eventing functions.

성명서 Use cases for N1QL statements in Eventing Functions
인덱스 생성 Since the schema is flexible, you could potentially inspect the data often/periodically to detect new fields and then create indexes on it.
삭제 Cascade deletes.
DROP INDEX A corollary to the CREATE INDEX use case.
INFER Periodic introspection of the bucket for the structure.  Then take action (validate, create index, update the data model) if necessary.
삽입 Maintaining referential data (eventually).

Updating other documents with references to this data.  E.g Data from a new zip, state, etc.

Data copy (fully or partially) to secondary/tertiary documents. Similar to post-trigger action.

MERGE Keep the secondary data in sync.
선택 Fetch any data, run any reports periodically, etc.

Check for various things like data quality, data validity,

When you do know the target document key, use the built-in direct document references. See examples at: https://docs.couchbase.com/server/5.5/eventing/eventing-examples.html

UPSERT Keeping secondary/tertiary data in sync.

Similar to post-trigger action.

업데이트 Keeping secondary/tertiary data in sync.

Similar to post-trigger action.

Examples:  Let’s try some eventing functions with N1QL.

  1. Simple N1QL in Functions for logging and cascade delete.

Save away every deleted document in a separate bucket.

  1. OnUpdate() function to keep the aggregate information ready periodically.

참조:

  1. Couchbase documentation: https://docs.couchbase.com/server/5.5/eventing/eventing-overview.html
  2. Couchbase blogs on eventing: https://www.couchbase.com/blog/tag/eventing/

작성자

게시자 케샤브 머시

케샤브 머시는 Couchbase R&D의 부사장입니다. 이전에는 MapR, IBM, Informix, Sybase에서 근무했으며 데이터베이스 설계 및 개발 분야에서 20년 이상의 경력을 쌓았습니다. IBM Informix에서 SQL 및 NoSQL R&D 팀을 이끌었습니다. Couchbase에서 두 번의 President's Club 상을, IBM에서 두 번의 우수 기술 업적상을 수상했습니다. 인도 마이소르 대학교에서 컴퓨터 과학 및 공학 학사 학위를 받았으며, 10개의 미국 특허를 보유하고 있고 3개의 미국 특허를 출원 중입니다.

댓글 남기기