Skip to main content

Scenarios

Working with Abacus usually starts with CreateObjects and CreateAttributes, which set up the tables and columns you'll write to. From there, CreateObjectEvents records what happened, SelectObjectEvents queries it, and ExplainSelectObjectEvents shows the plan Postgres would follow for that query.

Objects​

Create Objects​

Create an Object with only an Id and a Label.

Request
mutation {
CreateObjects {
Id(Is: {In: "customers"})
Label(Is: {In: "Customers"})
}
}
Response
{
"data": {
"CreateObjects": [
{
"Id": "customers",
"Label": "Customers"
}
]
}
}

Select Objects​

Select one Object by its Id, with its Label.

Request
query {
SelectObjects {
Id(Is: {In: "customers"})
Label
}
}
Response
{
"data": {
"SelectObjects": [
{
"Id": "customers",
"Label": "Customers"
}
]
}
}

Update Objects​

Update the Label of one Object by its Id.

Request
mutation {
UpdateObjects {
Id
Label(Is: {In: "Clients"})
Where {
... on SelectObject {
Id(Is: {In: "customers"})
}
}
}
}
Response
{
"data": {
"UpdateObjects": [
{
"Id": "customers",
"Label": "Clients",
"Where": [
{
"Id": "customers"
}
]
}
]
}
}

Delete Objects​

Delete one Object by its Id.

Request
mutation {
DeleteObjects {
Where {
... on SelectObject {
Id(Is: {In: "customers"})
}
}
}
}
Response
{
"data": {
"DeleteObjects": [
{
"Where": [
{
"Id": "customers"
}
]
}
]
}
}

Attributes​

Create Attributes​

Create a String Attribute of one Object, with an Id, a Label and a ValueProvider.

Request
mutation {
CreateAttributes {
Id(Is: {In: "name"})
Label(Is: {In: "Name"})
ScalarTypeId(Is: {In: String})
ValueProvider(Is: {In: "crm.name"})
Object {
... on SelectObject {
Id(Is: {In: "customers"})
}
}
}
}
Response
{
"data": {
"CreateAttributes": [
{
"Id": "name",
"Label": "Name",
"ScalarTypeId": "String",
"ValueProvider": "crm.name",
"Object": {
"Id": "customers"
}
}
]
}
}

Select Attributes​

Select one Attribute by its Id, with the Id and Label of its Object.

Request
query {
SelectAttributes {
Id(Is: {In: "name"})
Object {
... on SelectObject {
Id
Label
}
}
}
}
Response
{
"data": {
"SelectAttributes": [
{
"Id": "name",
"Object": {
"Id": "customers",
"Label": "Customers"
}
}
]
}
}

Update Attributes​

Update the ValueProvider of one Attribute by its Id, with its Scalar Type set to String.

Request
mutation {
UpdateAttributes {
Id
ValueProvider(Is: {In: "crm.full_name"})
ScalarTypeId(Is: {In: String})
Where {
... on SelectAttribute {
Id(Is: {In: "name"})
}
}
}
}
Response
{
"data": {
"UpdateAttributes": [
{
"Id": "name",
"ValueProvider": "crm.full_name",
"ScalarTypeId": "String",
"Where": [
{
"Id": "name"
}
]
}
]
}
}

Copy Attributes​

Copy every Attribute of one Object to another Object.

Request
mutation {
CopyAttributes {
Id
Label
ScalarTypeId
ValueProvider
From {
... on SelectAttribute {
Object {
... on SelectObject {
Id(Is: {In: "customers"})
}
}
}
}
To {
... on SelectObject {
Id(Is: {In: "prospects"})
}
}
}
}
Response
{
"data": {
"CopyAttributes": [
{
"Id": "age",
"Label": "Age",
"ScalarTypeId": "Int",
"ValueProvider": "crm.age",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "balance",
"Label": "Balance",
"ScalarTypeId": "Float",
"ValueProvider": "crm.balance",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "city",
"Label": "City",
"ScalarTypeId": "String",
"ValueProvider": "crm.city",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "notes",
"Label": "Notes",
"ScalarTypeId": "String",
"ValueProvider": "crm.notes",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "subscribed",
"Label": "Subscribed",
"ScalarTypeId": "Boolean",
"ValueProvider": "crm.subscribed",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "joined",
"Label": "Joined",
"ScalarTypeId": "DateTime",
"ValueProvider": "crm.joined",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "preferences",
"Label": "Preferences",
"ScalarTypeId": "Json",
"ValueProvider": "crm.preferences",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "external_id",
"Label": "External Id",
"ScalarTypeId": "UuidV7",
"ValueProvider": "crm.external_id",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "lifetime_value",
"Label": "Lifetime Value",
"ScalarTypeId": "Numeric",
"ValueProvider": "crm.lifetime_value",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
},
{
"Id": "name",
"Label": "Name",
"ScalarTypeId": "String",
"ValueProvider": "crm.full_name",
"From": [
{
"Object": {
"Id": "customers"
}
}
],
"To": [
{
"Id": "prospects"
}
]
}
]
}
}

Delete Attributes​

Delete one Attribute by its Id.

Request
mutation {
DeleteAttributes {
Where {
... on SelectAttribute {
Id(Is: {In: "name"})
}
}
}
}
Response
{
"data": {
"DeleteAttributes": [
{
"Where": [
{
"Id": "name"
}
]
},
{
"Where": [
{
"Id": "name"
}
]
}
]
}
}

Object Events​

Create Object Events​

Create four Grades at 5, 10, 20 and 40 Points, one carrying a multibyte key in its Payload.

Request
mutation {
CreateObjectEvents {
ObjectEvents(Is: {In: ["[{\"1\": 5, \"2\": \"E\", \"3\": {\"Tags\": [\"retake\"], \"Level\": 1}}, {\"1\": 10, \"2\": \"D\", \"3\": {\"Tags\": [\"pass\"], \"Level\": 2}}, {\"1\": 20, \"2\": \"C\", \"3\": {\"Tags\": [\"pass\", \"merit\"], \"Level\": 3, \"straße\": true}}, {\"1\": 40, \"2\": \"A\", \"3\": {\"Tags\": [\"pass\", \"merit\", \"distinction\"], \"Level\": 5}}]"]})
Object {
... on SelectObject {
Id(Is: {In: "grades"})
}
}
}
}
Response
{
"data": {
"CreateObjectEvents": {
"ObjectEvents": [
{
"ObjectIndex": 8,
"Staged": 4,
"Events": 4,
"Strings": 4,
"Jsons": 4,
"Aliases": 0,
"ValueAliases": 0
}
],
"Object": null
}
}
}

Select Object Events​

Select the two teams with the highest counts of points, with ties ordered by team ascending.

Request
query {
SelectObjectEvents {
Columns
Rows(
Is: {
Select: {
Expression: { Attribute: { Id: { In: "team" }, ObjectReference: "R" } }
As: "Team"
Next: { Expression: { Call: { Function: Count, Args: { Attribute: { Id: { In: "points" }, ObjectReference: "R" } } } }, As: "Events" }
}
From: { Object: { Id: { In: "rankings" } }, As: "R" }
GroupBy: { Attribute: { Id: { In: "team" }, ObjectReference: "R" } }
Order: {
By: { Call: { Function: Count, Args: { Attribute: { Id: { In: "points" }, ObjectReference: "R" } } } }
Direction: "DESC"
Next: { By: { Attribute: { Id: { In: "team" }, ObjectReference: "R" } }, Direction: "ASC" }
}
Limit: { Limit: { BigInt: 2 } }
}
)
}
}
Response
{
"data": {
"SelectObjectEvents": {
"Columns": ["Team", "Events"],
"Rows": [
["Alpha", 3],
["Beta", 2]
]
}
}
}

Explain Select Object Events​

Explain the plan for selecting the Int of every Object Event of one Object.

Request
query { ExplainSelectObjectEvents { Plan( Is: {
Select: { Expression: { Attribute: { Id: { In: "quantity" }, ObjectReference: "E" } }, As: "Int" }
From: { Object: { Id: { In: "orders" } }, As: "E" }
} ) } }
Response
{
"data": {
"ExplainSelectObjectEvents": {
"Plan": [
{
"Plan": {
"Alias": "T0",
"Disabled": false,
"Node Type": "Seq Scan",
"Async Capable": false,
"Relation Name": "Events",
"Parallel Aware": false
}
}
]
}
}
}