For each touch of a record in the source
table the fibonacci number corresponding to the count of touches is recorded in the derived
table.
Last active
May 12, 2022 15:37
-
-
Save louisbuchbinder/5fa7a8b009ad29847bb8c5d16a5d79e9 to your computer and use it in GitHub Desktop.
Twisp Trigger Fibonacci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a contrived example to demonstrate transaction triggers in Twisp. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Transform: AWS::Serverless-2016-10-31 | |
Resources: | |
Source: | |
Type: Twisp::Database::Ledger | |
Properties: | |
Name: source | |
Document: | |
id: uuid | |
Indexes: | |
id: | |
Partition: | |
- id: document.id | |
Properties: | |
Unique: true | |
Triggers: | |
init: | |
Events: | |
- ON_INSERT | |
Execute: | |
- Name: insert_derived | |
Action: DO_INSERT | |
Where: | |
Table: derived | |
Document: | |
id: context.source.id | |
a: '1' | |
fibonacci: | |
Events: | |
- ON_UPDATE | |
Execute: | |
- Name: update_derived | |
Action: DO_UPDATE | |
Where: | |
Table: derived | |
Index: derived.indexes.id | |
Partition: | |
id: context.source.id | |
Document: | |
a: 'document.fibonacci' | |
fibonacci: 'document.a + document.fibonacci' | |
index: 'document.index + 1' | |
Derived: | |
Type: Twisp::Database::Ledger | |
Properties: | |
Name: derived | |
Document: | |
id: uuid | |
a: int | |
fibonacci: int | |
index: int | |
Indexes: | |
id: | |
Partition: | |
- id: document.id | |
Properties: | |
Unique: true | |
References: | |
source: | |
Index: source.indexes.id | |
Partition: | |
id: document.id | |
Properties: | |
Unique: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutation insert { | |
source { | |
insert ( | |
input: { | |
document: { | |
id:"uuid(context.vars.uuid)" | |
} | |
} | |
) { | |
record { id } | |
} | |
} | |
} | |
mutation update($uuid:String!) { | |
source { | |
update ( | |
input: { | |
index: id | |
where: { | |
partition: [ $uuid ] | |
} | |
document: {} | |
} | |
) { | |
records { id } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query get($uuid:String!) { | |
derived ( | |
index: id | |
where: { | |
partition: [ $uuid ] | |
} | |
) { | |
history { | |
fibonacci | |
index | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"uuid": "00000000-0000-0000-0000-000000000000" | |
} |
Author
louisbuchbinder
commented
May 11, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment