Venom - Executor couchbase
Step to execute actions on a couchbase database using github.com/couchbase/gocb/v2 sdk.
More information you can find here
Connection
To be possible use couchbase executor you need to specify at least the couchbase bucket (in case of no auth and running local).
A minimal couchbase configuration can be the following one:
- type: couchbase
dsn: "couchbase://localhost" # connection string to connect to couchbase.
username: "{{ .couchbase_username }}" # can be omitted
password: "{{ .couchbase_password }}" # can be omitted
bucket: "{{ .couchbase_bucket }}" # mandatory
A complete couchbase configuration can be the following one
- type: couchbase
dsn: "couchbase://localhost" # will use couchbase://localhost if omitted
username: "{{ .couchbase_username }}" # can be omitted
password: "{{ .couchbase_password }}" # can be omitted
bucket: "{{ .couchbase_bucket }}" # mandatory
scope: "_default" # can be omitted, default scope will be used
collection: "_default" # can be omitted, default collection will be used
transcoder: "json" # can be omitted, "legacy" will be used
expiry: 600 # in seconds, can be omitted (no expiration by default)
wait_until_ready_timeout: 5 # in seconds, can be 0 (means no wait until bucket is ready)
profile_wan_development: true # if true, will use high timeouts to avoid latency issues. default false.
The fields bucket, scope and collection are used as default values. Each action can define a different bucket, scope or collection to use locally.
For transcoder, you have the following options:
See also tests/couchbase.yml for executable examples.
Couchbase can be used to store json structured data, but can store also binary and string types.
Example:
airline_01: # entries are specified as map id => content
"id": 1
"type": "airline"
"name": "first airline"
"country": "Latveria"
Load fixtures
Not implemented yet.
Retrieve documents
Get will retrieve documents by id. If the id can't be found the flag found will be false.
By using flag with_expiry the expiration of the given entry will be returned (or will be zero if no expiration).
by using flag expiry the get operation became get and touch and the option with_expiry will be ignored.
- type: couchbase
dsn: "{{ .couchbase_dsn }}"
username: "{{ .couchbase_username }}"
password: "{{ .couchbase_password }}"
bucket: "travel-sample"
actions:
- type: get
with_expiry: true
ids: ["airline_10","airline_01"]
assertions:
- result.actions.actions0.airline_10.expiry ShouldBeZeroValue
- result.actions.actions0.airline_10.data ShouldJSONEqual {"id":10,"type":"airline","name":"40-Mile Air","iata":"Q5","icao":"MLA","callsign":"MILE-AIR","country":"United States"}
- result.actions.actions0.airline_01 ShouldNotBeNil
- result.actions.actions0.airline_01.found ShouldBeFalse
Insert documents
Insert will create documents by id. If the id already exists the operation is not executed and the flag inserted will be false.
An expiration, in seconds, can be defined via field expiry to override the default expiry (if any)
- type: couchbase
dsn: "{{ .couchbase_dsn }}"
username: "{{ .couchbase_username }}"
password: "{{ .couchbase_password }}"
bucket: "travel-sample"
actions:
- type: insert
entries:
airline_01:
"id": 1
"type": "airline"
"name": "first airline"
"country": "Latveria"
assertions:
- result.actions.actions0.airline_01.inserted ShouldBeTrue
Replace documents
Replace will update documents by id. If the id does not exist the operation is not executed and the flag replaced will be false.
It is possible to preserve the original expiration via boolean field preserve_expiry.
An expiration, in seconds, can be defined via field expiry to override the default expiry (if any).
- type: couchbase
dsn: "{{ .couchbase_dsn }}"
username: "{{ .couchbase_username }}"
password: "{{ .couchbase_password }}"
bucket: "travel-sample"
actions:
- type: replace
entries:
airline_01:
"id": 1
"type": "airline"
"name": "first airline"
"country": "Latveria"
assertions:
- result.actions.actions0.airline_01.replaced ShouldBeTrue
Upsert documents
Upsert will insert or documents by id. It will set the flag upserted to true
It is possible to preserve the original expiration (if any) via boolean field preserve_expiry.
- type: couchbase
dsn: "{{ .couchbase_dsn }}"
username: "{{ .couchbase_username }}"
password: "{{ .couchbase_password }}"
bucket: "travel-sample"
actions:
- type: upsert
entries:
airline_01:
"id": 1
"type": "airline"
"name": "first airline"
"country": "Latveria"
assertions:
- result.actions.actions0.airline_01.upserted ShouldBeTrue
### Remove documents
Delete will remove by id. It will set the flag deleted to true in case the id has been found.
- type: couchbase
dsn: "{{ .couchbase_dsn }}"
username: "{{ .couchbase_username }}"
password: "{{ .couchbase_password }}"
bucket: "travel-sample"
actions:
- type: delete
ids: ["airline_01"]
assertions:
- result.actions.actions0.airline_01.deleted ShouldBeTrue
Touch documents
Touch will update the object expiration for a given id. It will set the flag touch to true in case the id has been found.
An expiry in seconds can be specified to be used. Unless it will use the global expiry.
- type: couchbase
dsn: "{{ .couchbase_dsn }}"
username: "{{ .couchbase_username }}"
password: "{{ .couchbase_password }}"
bucket: "travel-sample"
actions:
- type: touch
expiry: 3600 # 1 hour
ids: ["airline_01"]
assertions:
- result.actions.actions0.airline_01.touched ShouldBeTrue
Check if document exists
The command exists check if the document id exists or not. It will set a boolean flag found with the status.
- type: couchbase
dsn: "{{ .couchbase_dsn }}"
username: "{{ .couchbase_username }}"
password: "{{ .couchbase_password }}"
bucket: "travel-sample"
actions:
- type: exists
ids: ["airline_10","airline_01"]
assertions:
- result.actions.actions0.airline_10.found ShouldBeTrue
- result.actions.actions0.airline_01.found ShouldBeFalse