-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphDB.querries
135 lines (85 loc) · 3.79 KB
/
graphDB.querries
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
LOAD CSV WITH HEADERS FROM "file:///C:/Users/rraina/Desktop/acc.csv" AS csvLine
MERGE (providerName:ProviderName { name: csvLine.providerName })
CREATE (acc:Acc { id: csvLine.id, accountName: csvLine.accountName, container:csvLine.CONTAINER})
CREATE (acc)-[:ACCOUNTS_IN]->(providerName)
-----------------------------------------------------------------------------------
//accounts
LOAD CSV WITH HEADERS FROM "file:///C:/Users/rraina/Desktop/acc.csv" AS csvLine
MERGE (providerName:ProviderName { name: csvLine.providerName })
MERGE (container:Container { name: csvLine.CONTAINER })
MERGE (asset:Asset { name: csvLine.isAsset })
CREATE (account:Account { accountName: csvLine.accountName, id: csvLine.id , balance:csvLine.balance, accountNumber:csvLine.accountNumber})
CREATE (account)-[:ACCOUNTS_IN]->(providerName)
CREATE (account)-[:ACCOUNT_TYPE]->(container)
CREATE (account)-[:IS_ASSET]->(asset)
--------------------------------------------------------------------------
CREATE CONSTRAINT ON (account:Account) ASSERT account.id IS UNIQUE
CREATE INDEX ON :Transaction()
--------------------------------------------------------------------------
//transactions
CREATE CONSTRAINT ON (transaction:Transaction) ASSERT transaction.id IS UNIQUE
USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM "file:///C:/Users/rraina/Desktop/trans.csv" AS row
MERGE (baseType:BaseType { name: row.baseType })
MERGE (category:Category { name: row.category })
MERGE (merchantName:MerchantName { name: row.merchantName })
WITH baseType, category, merchantName,row
CREATE (transaction:Transaction { description: row.description, postedDate: row.date,transactionDate: row.transactionDate ,id: row.id ,accountId : row.accountId})
CREATE (transaction)-[:CATEGORY_IN]->(category)
CREATE (transaction)-[:TRANSACTED_AT]->(merchantName)
CREATE (transaction)-[:BASETYPE_OF]->(baseType)
LOAD CSV WITH HEADERS FROM "file:///C:/Users/rraina/Desktop/acc.csv" AS row
MATCH (n:Transaction)
SET
return n;
MATCH (account:Account), (transaction:Transaction)
WHERE account.id = transaction.accountId
CREATE (transaction)-[:TRANSACTION_OF_ACCOUNT]->(account)
---------------------------------------------------------------
--------------Queries to pull data from front end--------------
---------------------------------------------------------------
//to pull accounts of type <container_type>
@Params = <container_type>
MATCH (account:Account)-[r:ACCOUNT_TYPE]->(container:Container)
WHERE container.name =~ '(?i).*<container_type>.*'
RETURN account
//to pull transactions at a particular merchant.
@Params : <merchant_name>
MATCH (transaction:Transaction)-[r:TRANSACTED_AT]->(merchantName:MerchantName)
where merchantName.name =~ '(?i).*<mercant_name>.*'
RETURN transaction
//to pull assets
@Params: null
MATCH (account:Account)-[r:IS_ASSET]->(asset:Asset)
where asset.name='TRUE'
RETURN r
//to pull liabilities
@Params: null
MATCH (account:Account)-[r:IS_ASSET]->(asset:Asset)
where asset.name='FALSE'
RETURN r
//to pull sum of assets
@Params : null
MATCH (account:Account)-[r:IS_ASSET]->(asset:Asset)
WHERE asset.name='TRUE'
RETURN sum(toFloat(account.balance))
//to pull all the sum of liabilities
@Params : null
MATCH (account:Account)-[r:IS_ASSET]->(asset:Asset)
WHERE asset.name='FALSE'
RETURN sum(toFloat(account.balance))
//to pull what all banks do I have accounts in
@Params : null
MATCH (account:Account)-[r:ACCOUNTS_IN]->(provider:ProviderName)
RETURN provider
//to pull spending categories
@Params : <category_name>
MATCH (transaction:Transaction)-[r:CATEGORY_IN]->(category:Category)
where category.name =~ '(?i).*<category_name>.*'
RETURN r
//to pull transactions of a particular BaseType
@Params : <basetype_name>
MATCH (transaction:Transaction)-[r:BASETYPE_OF]->(baseType:BaseType)
WHERE baseType.name=~ '(?i).*<basetype_name>.*'
RETURN r