Last active
June 4, 2020 11:32
-
-
Save sharonovd/fd4df5e683c71653812d133f1dea7abd to your computer and use it in GitHub Desktop.
TDG demo-data
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
[ | |
{ | |
"name": "Account", | |
"type": "record", | |
"logicalType": "Aggregate", | |
"fields": [ | |
{"name": "id", "type": "int"}, | |
{"name": "name", "type": ["null", "string"], "default": null} | |
], | |
"indexes": ["id", "name"], | |
"relations": [ | |
{ "name": "transactions", "to": "Transaction", "count": "many", "from_fields": "id", "to_fields": "account_id" } | |
] | |
}, | |
{ | |
"name": "Transaction", | |
"type": "record", | |
"logicalType": "Aggregate", | |
"fields": [ | |
{"name": "id", "type": "int"}, | |
{"name": "account_id", "type": "int"}, | |
{"name": "description", "type": "string"}, | |
{"name": "amount", "type": "double", "default": 0} | |
], | |
"indexes": [ | |
"id", | |
"account_id" | |
], | |
"relations": [ | |
{ "name": "account", "to": "Account", "count": "one", "from_fields": "account_id", "to_fields": "id" } | |
] | |
} | |
] | |
mutation { | |
Account(insert:{id: 1, name:"Депозит Петров В. И."}){id} | |
} | |
mutation { | |
Transaction(insert:{ | |
id: 1, | |
account_id:1, | |
amount:15.43, | |
description:"Открытие счета" | |
}){id} | |
} | |
mutation { | |
Transaction(insert:{ | |
id: 2, | |
account_id:1, | |
amount:0.57, | |
description:"Пополнение счета" | |
}){id} | |
} | |
{ | |
Account(name_like:"%Петров%"){ | |
id, | |
name, | |
transactions{ | |
id, | |
description, | |
amount | |
} | |
} | |
} | |
functions.yml: | |
operations_volume: {__file: operations_volume.lua} | |
services.yml: | |
operations_volume: | |
function: operations_volume | |
return_type: double | |
args: | |
account_id: int | |
operations_volume.lua: | |
local param = ... | |
local account_id = param.account_id | |
local transactions, err = repository.find('Transaction', {{'$account_id', '==', account_id}}) | |
if err ~= nil then return error(err) end | |
local total = 0 | |
for _, transaction in pairs(transactions) do | |
total = total + math.abs(transaction.amount) | |
end | |
return total | |
{ | |
operations_volume(account_id:1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment