ucampostgresvro 0.1.2__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ucampostgresvro
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: To connect with postgresql for the billing report
5
5
  Author: Ishan Mahajan
6
6
  Author-email: mahanishanmahajan@gmail.com
@@ -55,6 +55,8 @@ pre_setupconfig(db_params)
55
55
  - To perform CRUD operation
56
56
  ```
57
57
  from ucampostgresvro.DBA import DB
58
+ from datetime import datetime
59
+
58
60
  db_params = {
59
61
  "dbname": "vrapricing",
60
62
  "user": "postgres",
@@ -74,6 +76,15 @@ db.insert_vrauser("ll220", "Ling-Yan Lau")
74
76
  # read user
75
77
  print(db.get_vrauser())
76
78
 
79
+ # read user specific user by crsid
80
+ print(db.get_vrauser("ll220"))
81
+
82
+ # read user specific user by user id
83
+ print(db.get_vrauser_by_id(1))
84
+
85
+ # get the primary key of user using crsid
86
+ print(db.get_vrauser_primary_key("ll220"))
87
+
77
88
  # update user
78
89
  db.update_vrauser("ll220", "bda20", 'Ben Argyle')
79
90
 
@@ -83,9 +94,18 @@ db.remove_vrauser('bda20')
83
94
  # create vra deploymentid
84
95
  db.insert_deployment_id("1231ee112ad11212")
85
96
 
86
- # read vra deployment id
97
+ # read all the vra deployment ids
98
+ print(db.get_deployment_id())
99
+
100
+ # read specific specific deploymentid by deploymentid
87
101
  print(db.get_deployment_id("1231a"))
88
102
 
103
+ # read specific deploymentid by primary key
104
+ print(db.get_deployment_id_by_id(1))
105
+
106
+ # read primary key of specific deploymentid
107
+ print(db.get_deployment_id_primary_key("1231a"))
108
+
89
109
  # update vra deployment id
90
110
  db.update_deployment_id("1231ee112ad1", "1231a")
91
111
 
@@ -95,38 +115,77 @@ db.remove_deployment_id('1231a')
95
115
  # create project
96
116
  db.insert_project("0001",1,100.0)
97
117
 
98
- # read project
118
+ # read all the projects
99
119
  print(db.get_project())
100
120
 
101
- # update project
102
- db.update_project("0001", "0002", 4, 200)
121
+ # read specific project
122
+ print(db.get_project("0001"))
123
+
124
+ # read project from the ID
125
+ print(db.get_project_by_id(1))
126
+
127
+ # get the primary key of the project
128
+ print(db.get_project_primary_key("001"))
129
+
130
+ # get the primary key of the project if more than 1 entites using date of insertion.
131
+ print(db.get_project_primary_key("001", datetime(2025, 1, 22, 15, 55, 25, 95698)))
132
+
133
+ # update project with new information 1 is the primary key
134
+ db.update_project(1, "0002", 4, 200)
103
135
 
104
- # delete project
105
- # db.remove_project("0002")
136
+ # delete project using primary key of project
137
+ # db.remove_project(1)
106
138
 
107
139
  # create grant
108
140
  db.insert_grant("0001",1,100.0)
109
141
 
110
- # read grant
142
+ # read all the grants
111
143
  print(db.get_grant())
112
144
 
113
- # update grant
114
- db.update_grant("0001", "0002", 4, 200)
145
+ # read specific grant
146
+ print(db.get_grant("0001"))
115
147
 
116
- # delete grant
117
- db.remove_grant("0002")
148
+ # read grant from the ID
149
+ print(db.get_grant_by_id(1))
150
+
151
+ # get the primary key of the grant
152
+ print(db.get_grant_primary_key("001"))
153
+
154
+ # get the primary key of the grant if more than 1 entites using date of insertion.
155
+ print(db.get_grant_primary_key("001", datetime(2025, 1, 22, 15, 55, 25, 95698)))
156
+
157
+ # update grant with new information 1 is the primary key of grant
158
+ db.update_grant(1, "2002", 4, 200)
159
+
160
+ # delete grant 1 is the primary key of the grant
161
+ db.remove_grant(1)
118
162
 
119
163
  # create costing
120
164
  db.insert_costing(2, "Initial Resource", project_id=4, grant_id=None)
121
165
 
122
- # read costing
166
+ # read all the costing
123
167
  print(db.get_costing())
124
168
 
125
- # update costing
126
- db.update_costing(2, "Duration Expansion", old_grant_id=4, old_project_id=None, grant_id=4, project_id=None)
169
+ # read specific costing using primary key of the costing
170
+ print(db.get_costing_by_id(1))
171
+
172
+ # read specific costing for the project
173
+ print(db.get_costing(2, "Initial Resource", 2))
127
174
 
128
- # delete costing
129
- db.remove_costing(2, "Duration Expansion", 4, None)
175
+ # read specific costing for the grant
176
+ print(db.get_costing(2, "Initial Resource", None, 2))
177
+
178
+ # get primary key for the specific costing for the project
179
+ print(db.get_costing_primary_key(2, "Initial Resource", 2))
180
+
181
+ # get primary key for the specific costing for the grant
182
+ print(db.get_costing_primary_key(2, "Initial Resource", None, 2))
183
+
184
+ # update costing where 3 is the primary key of the costing.
185
+ db.update_costing(3, 2, "Duration Expansion", new_grant_id=None, new_project_id=2)
186
+
187
+ # delete costing where 3 is the primary key
188
+ db.remove_costing(3)
130
189
 
131
190
  # to close db connection
132
191
  db.closedb()
@@ -173,39 +232,40 @@ Referenced by:
173
232
 
174
233
  ## - project table
175
234
  ```
176
- vrapricing=# \d projects;
177
- Table "public.projects"
178
- Column | Type | Collation | Nullable | Default
179
- ----------------+------------------------+-----------+----------+--------------------------------------
180
- id | integer | | not null | nextval('projects_id_seq'::regclass)
181
- project_number | character varying(255) | | |
182
- paid_by | integer | | |
183
- amount | double precision | | not null |
235
+ vrapricing=# \d projects
236
+ Table "public.projects"
237
+ Column | Type | Collation | Nullable | Default
238
+ ----------------+-----------------------------+-----------+----------+--------------------------------------
239
+ id | integer | | not null | nextval('projects_id_seq'::regclass)
240
+ date | timestamp without time zone | | | CURRENT_TIMESTAMP
241
+ project_number | character varying(255) | | |
242
+ paid_by | integer | | |
243
+ amount | double precision | | not null |
184
244
  Indexes:
185
245
  "projects_pkey" PRIMARY KEY, btree (id)
186
246
  Foreign-key constraints:
187
247
  "projects_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
188
248
  Referenced by:
189
249
  TABLE "costing" CONSTRAINT "costing_project_id_fkey" FOREIGN KEY (project_id) REFERENCES projects(id)
190
-
191
250
  ```
192
251
 
193
252
  ## - grants table
194
253
  ```
195
- vrapricing=# \d grant;
196
- Table "public.grant"
197
- Column | Type | Collation | Nullable | Default
198
- ----------------+------------------------+-----------+----------+--------------------------------------
199
- id | integer | | not null | nextval('grant_id_seq'::regclass)
200
- voucher_number | character varying(255) | | |
201
- paid_by | integer | | |
202
- amount | double precision | | not null |
254
+ vrapricing=# \d grants
255
+ Table "public.grants"
256
+ Column | Type | Collation | Nullable | Default
257
+ --------------+-----------------------------+-----------+----------+------------------------------------
258
+ id | integer | | not null | nextval('grants_id_seq'::regclass)
259
+ date | timestamp without time zone | | | CURRENT_TIMESTAMP
260
+ grant_number | character varying(255) | | |
261
+ paid_by | integer | | |
262
+ amount | double precision | | not null |
203
263
  Indexes:
204
- "grant_pkey" PRIMARY KEY, btree (id)
264
+ "grants_pkey" PRIMARY KEY, btree (id)
205
265
  Foreign-key constraints:
206
- "grant_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
266
+ "grants_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
207
267
  Referenced by:
208
- TABLE "costing" CONSTRAINT "costing_voucher_id_fkey" FOREIGN KEY (voucher_id) REFERENCES grant(id)
268
+ TABLE "costing" CONSTRAINT "costing_grant_id_fkey" FOREIGN KEY (grant_id) REFERENCES grants(id)
209
269
  ```
210
270
 
211
271
  ## - Costing table
@@ -40,6 +40,8 @@ pre_setupconfig(db_params)
40
40
  - To perform CRUD operation
41
41
  ```
42
42
  from ucampostgresvro.DBA import DB
43
+ from datetime import datetime
44
+
43
45
  db_params = {
44
46
  "dbname": "vrapricing",
45
47
  "user": "postgres",
@@ -59,6 +61,15 @@ db.insert_vrauser("ll220", "Ling-Yan Lau")
59
61
  # read user
60
62
  print(db.get_vrauser())
61
63
 
64
+ # read user specific user by crsid
65
+ print(db.get_vrauser("ll220"))
66
+
67
+ # read user specific user by user id
68
+ print(db.get_vrauser_by_id(1))
69
+
70
+ # get the primary key of user using crsid
71
+ print(db.get_vrauser_primary_key("ll220"))
72
+
62
73
  # update user
63
74
  db.update_vrauser("ll220", "bda20", 'Ben Argyle')
64
75
 
@@ -68,9 +79,18 @@ db.remove_vrauser('bda20')
68
79
  # create vra deploymentid
69
80
  db.insert_deployment_id("1231ee112ad11212")
70
81
 
71
- # read vra deployment id
82
+ # read all the vra deployment ids
83
+ print(db.get_deployment_id())
84
+
85
+ # read specific specific deploymentid by deploymentid
72
86
  print(db.get_deployment_id("1231a"))
73
87
 
88
+ # read specific deploymentid by primary key
89
+ print(db.get_deployment_id_by_id(1))
90
+
91
+ # read primary key of specific deploymentid
92
+ print(db.get_deployment_id_primary_key("1231a"))
93
+
74
94
  # update vra deployment id
75
95
  db.update_deployment_id("1231ee112ad1", "1231a")
76
96
 
@@ -80,38 +100,77 @@ db.remove_deployment_id('1231a')
80
100
  # create project
81
101
  db.insert_project("0001",1,100.0)
82
102
 
83
- # read project
103
+ # read all the projects
84
104
  print(db.get_project())
85
105
 
86
- # update project
87
- db.update_project("0001", "0002", 4, 200)
106
+ # read specific project
107
+ print(db.get_project("0001"))
108
+
109
+ # read project from the ID
110
+ print(db.get_project_by_id(1))
111
+
112
+ # get the primary key of the project
113
+ print(db.get_project_primary_key("001"))
114
+
115
+ # get the primary key of the project if more than 1 entites using date of insertion.
116
+ print(db.get_project_primary_key("001", datetime(2025, 1, 22, 15, 55, 25, 95698)))
117
+
118
+ # update project with new information 1 is the primary key
119
+ db.update_project(1, "0002", 4, 200)
88
120
 
89
- # delete project
90
- # db.remove_project("0002")
121
+ # delete project using primary key of project
122
+ # db.remove_project(1)
91
123
 
92
124
  # create grant
93
125
  db.insert_grant("0001",1,100.0)
94
126
 
95
- # read grant
127
+ # read all the grants
96
128
  print(db.get_grant())
97
129
 
98
- # update grant
99
- db.update_grant("0001", "0002", 4, 200)
130
+ # read specific grant
131
+ print(db.get_grant("0001"))
100
132
 
101
- # delete grant
102
- db.remove_grant("0002")
133
+ # read grant from the ID
134
+ print(db.get_grant_by_id(1))
135
+
136
+ # get the primary key of the grant
137
+ print(db.get_grant_primary_key("001"))
138
+
139
+ # get the primary key of the grant if more than 1 entites using date of insertion.
140
+ print(db.get_grant_primary_key("001", datetime(2025, 1, 22, 15, 55, 25, 95698)))
141
+
142
+ # update grant with new information 1 is the primary key of grant
143
+ db.update_grant(1, "2002", 4, 200)
144
+
145
+ # delete grant 1 is the primary key of the grant
146
+ db.remove_grant(1)
103
147
 
104
148
  # create costing
105
149
  db.insert_costing(2, "Initial Resource", project_id=4, grant_id=None)
106
150
 
107
- # read costing
151
+ # read all the costing
108
152
  print(db.get_costing())
109
153
 
110
- # update costing
111
- db.update_costing(2, "Duration Expansion", old_grant_id=4, old_project_id=None, grant_id=4, project_id=None)
154
+ # read specific costing using primary key of the costing
155
+ print(db.get_costing_by_id(1))
156
+
157
+ # read specific costing for the project
158
+ print(db.get_costing(2, "Initial Resource", 2))
112
159
 
113
- # delete costing
114
- db.remove_costing(2, "Duration Expansion", 4, None)
160
+ # read specific costing for the grant
161
+ print(db.get_costing(2, "Initial Resource", None, 2))
162
+
163
+ # get primary key for the specific costing for the project
164
+ print(db.get_costing_primary_key(2, "Initial Resource", 2))
165
+
166
+ # get primary key for the specific costing for the grant
167
+ print(db.get_costing_primary_key(2, "Initial Resource", None, 2))
168
+
169
+ # update costing where 3 is the primary key of the costing.
170
+ db.update_costing(3, 2, "Duration Expansion", new_grant_id=None, new_project_id=2)
171
+
172
+ # delete costing where 3 is the primary key
173
+ db.remove_costing(3)
115
174
 
116
175
  # to close db connection
117
176
  db.closedb()
@@ -158,39 +217,40 @@ Referenced by:
158
217
 
159
218
  ## - project table
160
219
  ```
161
- vrapricing=# \d projects;
162
- Table "public.projects"
163
- Column | Type | Collation | Nullable | Default
164
- ----------------+------------------------+-----------+----------+--------------------------------------
165
- id | integer | | not null | nextval('projects_id_seq'::regclass)
166
- project_number | character varying(255) | | |
167
- paid_by | integer | | |
168
- amount | double precision | | not null |
220
+ vrapricing=# \d projects
221
+ Table "public.projects"
222
+ Column | Type | Collation | Nullable | Default
223
+ ----------------+-----------------------------+-----------+----------+--------------------------------------
224
+ id | integer | | not null | nextval('projects_id_seq'::regclass)
225
+ date | timestamp without time zone | | | CURRENT_TIMESTAMP
226
+ project_number | character varying(255) | | |
227
+ paid_by | integer | | |
228
+ amount | double precision | | not null |
169
229
  Indexes:
170
230
  "projects_pkey" PRIMARY KEY, btree (id)
171
231
  Foreign-key constraints:
172
232
  "projects_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
173
233
  Referenced by:
174
234
  TABLE "costing" CONSTRAINT "costing_project_id_fkey" FOREIGN KEY (project_id) REFERENCES projects(id)
175
-
176
235
  ```
177
236
 
178
237
  ## - grants table
179
238
  ```
180
- vrapricing=# \d grant;
181
- Table "public.grant"
182
- Column | Type | Collation | Nullable | Default
183
- ----------------+------------------------+-----------+----------+--------------------------------------
184
- id | integer | | not null | nextval('grant_id_seq'::regclass)
185
- voucher_number | character varying(255) | | |
186
- paid_by | integer | | |
187
- amount | double precision | | not null |
239
+ vrapricing=# \d grants
240
+ Table "public.grants"
241
+ Column | Type | Collation | Nullable | Default
242
+ --------------+-----------------------------+-----------+----------+------------------------------------
243
+ id | integer | | not null | nextval('grants_id_seq'::regclass)
244
+ date | timestamp without time zone | | | CURRENT_TIMESTAMP
245
+ grant_number | character varying(255) | | |
246
+ paid_by | integer | | |
247
+ amount | double precision | | not null |
188
248
  Indexes:
189
- "grant_pkey" PRIMARY KEY, btree (id)
249
+ "grants_pkey" PRIMARY KEY, btree (id)
190
250
  Foreign-key constraints:
191
- "grant_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
251
+ "grants_paid_by_fkey" FOREIGN KEY (paid_by) REFERENCES vrauser(id)
192
252
  Referenced by:
193
- TABLE "costing" CONSTRAINT "costing_voucher_id_fkey" FOREIGN KEY (voucher_id) REFERENCES grant(id)
253
+ TABLE "costing" CONSTRAINT "costing_grant_id_fkey" FOREIGN KEY (grant_id) REFERENCES grants(id)
194
254
  ```
195
255
 
196
256
  ## - Costing table
@@ -1,11 +1,12 @@
1
1
  [project]
2
2
  name = "ucampostgresvro"
3
- version = "0.1.2"
3
+ version = "0.2.0"
4
4
  description = "To connect with postgresql for the billing report"
5
5
  authors = [
6
6
  {name = "Ishan Mahajan",email = "mahanishanmahajan@gmail.com"}
7
7
  ]
8
8
  readme = "README.md"
9
+ homepage = "https://gitlab.developers.cam.ac.uk/uis/infra/ucampostgresvro.git"
9
10
  requires-python = ">=3.10"
10
11
  dependencies = [
11
12
  "psycopg2-binary (>=2.9.10,<3.0.0)"