ucampostgresvro 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

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.
ucampostgresvro/DBA.py CHANGED
@@ -34,7 +34,7 @@ class DB:
34
34
 
35
35
  def insert_vrauser(
36
36
  self, crsid: str, name: str, table_name: str = DEFAULT_TABLES.get("user")
37
- ) -> bool:
37
+ ) -> int:
38
38
  """Insertion of the vrauser detail.
39
39
 
40
40
  Args:
@@ -46,21 +46,21 @@ class DB:
46
46
  DbException: Exception for the provided inputs.
47
47
 
48
48
  Returns:
49
- bool: True for the success and False for the failure.
49
+ int: Primary key of the user.
50
50
  """
51
51
  with self.connection:
52
52
  if crsid and name:
53
53
  try:
54
54
  self.cursor.execute(
55
- f"INSERT INTO {table_name} (crsid, name) VALUES ('{crsid}', '{name}');"
55
+ f"INSERT INTO {table_name} (crsid, name) VALUES ('{crsid}', '{name}') RETURNING id;"
56
56
  )
57
57
  LOG.info(
58
58
  f"INFO: {table_name} insersion successful: CRSID {crsid} and Name {name}"
59
59
  )
60
- return True
60
+ return self.cursor.fetchone()[0]
61
61
  except Exception as e:
62
62
  LOG.error(f"Error: {table_name} insertion : {e}")
63
- return False
63
+ raise DbException(f"Error: {table_name} insertion fail")
64
64
  else:
65
65
  LOG.error(
66
66
  f"Error: Please provide both crid and name for {table_name} insertion"
@@ -73,7 +73,7 @@ class DB:
73
73
  new_crsid: str,
74
74
  name: str,
75
75
  table_name: str = DEFAULT_TABLES.get("user"),
76
- ) -> bool:
76
+ ) -> int:
77
77
  """Updation of the vrauser.
78
78
 
79
79
  Args:
@@ -83,18 +83,18 @@ class DB:
83
83
  table_name (str): table name of the user.
84
84
 
85
85
  Returns:
86
- bool: True for the success and False for the failure.
86
+ int: primary key of the user which is updated.
87
87
  """
88
88
  with self.connection:
89
89
  try:
90
90
  self.cursor.execute(
91
- f"UPDATE {table_name} SET crsid ='{new_crsid}' , name='{name}' WHERE crsid='{old_crsid}';"
91
+ f"UPDATE {table_name} SET crsid ='{new_crsid}' , name='{name}' WHERE crsid='{old_crsid}' RETURNING id;"
92
92
  )
93
93
  LOG.info(f"INFO: {table_name} update successful for CRSID {old_crsid}")
94
- return True
94
+ return self.cursor.fetchone()[0]
95
95
  except Exception as e:
96
96
  LOG.error(f"Error: {table_name} Updating : {e}")
97
- return False
97
+ raise DbException(f"Error: {table_name} Updating : {e}")
98
98
 
99
99
  def remove_vrauser(
100
100
  self, crsid: str, table_name: str = DEFAULT_TABLES.get("user")
@@ -204,7 +204,7 @@ class DB:
204
204
 
205
205
  def insert_deployment_id(
206
206
  self, deployment_id: str, table_name: str = DEFAULT_TABLES.get("deploymentid")
207
- ) -> bool:
207
+ ) -> int:
208
208
  """Insertion of the deployment detail.
209
209
 
210
210
  Args:
@@ -215,21 +215,23 @@ class DB:
215
215
  DbException: Exception for the provided inputs.
216
216
 
217
217
  Returns:
218
- bool: True for the success and False for the failure.
218
+ int: primary key of the deployment.
219
219
  """
220
220
  with self.connection:
221
221
  if deployment_id:
222
222
  try:
223
223
  self.cursor.execute(
224
- f"INSERT INTO {table_name} (deploymentID) VALUES ('{deployment_id}');"
224
+ f"INSERT INTO {table_name} (deploymentID) VALUES ('{deployment_id}') RETURNING id;"
225
225
  )
226
226
  LOG.info(
227
227
  f"INFO: deployment ID {deployment_id} inserted successfully"
228
228
  )
229
- return True
229
+ return self.cursor.fetchone()[0]
230
230
  except Exception as e:
231
231
  LOG.error(f"Error: deployment ID insertion in {table_name}: {e}")
232
- return False
232
+ raise DbException(
233
+ f"Error: deployment ID insertion in {table_name}: {e}"
234
+ )
233
235
  else:
234
236
  LOG.error(
235
237
  f"Error: Please provide deployment ID for {table_name} insertion"
@@ -243,7 +245,7 @@ class DB:
243
245
  old_deployment_id: str,
244
246
  new_deployment_id: str,
245
247
  table_name: str = DEFAULT_TABLES.get("deploymentid"),
246
- ) -> bool:
248
+ ) -> int:
247
249
  """Updation of the the deployment ID in deployment table.
248
250
 
249
251
  Args:
@@ -252,22 +254,22 @@ class DB:
252
254
  table_name (str): table name of the deploymentid.
253
255
 
254
256
  Returns:
255
- bool: True for the success and False for the failure.
257
+ int: primary key of the deployment.
256
258
  """
257
259
  with self.connection:
258
260
  try:
259
261
  self.cursor.execute(
260
262
  f"UPDATE {table_name} SET deploymentID ='{new_deployment_id}' \
261
- WHERE deploymentID='{old_deployment_id}';"
263
+ WHERE deploymentID='{old_deployment_id}' RETURNING id;"
262
264
  )
263
265
  LOG.info(
264
266
  f"INFO: deployment ID of {old_deployment_id} updated successfully with \
265
267
  {new_deployment_id} in table {table_name} ."
266
268
  )
267
- return True
269
+ return self.cursor.fetchone()[0]
268
270
  except Exception as e:
269
271
  LOG.error(f"Error: deployment ID update for table {table_name}: {e}")
270
- return False
272
+ raise DbException(f"Error: deployment ID update for table {table_name}: {e}")
271
273
 
272
274
  def remove_deployment_id(
273
275
  self, deployment_id: str, table_name: str = DEFAULT_TABLES.get("deploymentid")
@@ -380,7 +382,7 @@ class DB:
380
382
  paid_by: int,
381
383
  amount: float,
382
384
  table_name: str = DEFAULT_TABLES.get("proj"),
383
- ) -> bool:
385
+ ) -> int:
384
386
  """Insertion of the project table.
385
387
 
386
388
  Args:
@@ -393,24 +395,26 @@ class DB:
393
395
  DbException: Exception for the provided inputs.
394
396
 
395
397
  Returns:
396
- bool: True for the success and False for the failure.
398
+ int: primary key of the project.
397
399
  """
398
400
  with self.connection:
399
401
  if project_number:
400
402
  try:
401
403
  self.cursor.execute(
402
404
  f"INSERT INTO {table_name} (project_number, paid_by, amount) VALUES \
403
- ('{project_number}', '{paid_by}', '{amount}');"
405
+ ('{project_number}', '{paid_by}', '{amount}') RETURNING id;"
404
406
  )
405
407
  LOG.info(
406
408
  f"INFO: Insertion of {project_number} and {amount} by {paid_by} is performed successfully"
407
409
  )
408
- return True
410
+ return self.cursor.fetchone()[0]
409
411
  except Exception as e:
410
412
  LOG.error(
411
413
  f"Error: project insertion in a table '{table_name}':\n {e}"
412
414
  )
413
- return False
415
+ raise DbException(
416
+ f"Error: project insertion in a table '{table_name}':\n {e}"
417
+ )
414
418
  else:
415
419
  LOG.error(
416
420
  "Error: Please provide project_number, paid_by, amount for Payment Oder"
@@ -426,7 +430,7 @@ class DB:
426
430
  new_paid_by: int,
427
431
  new_amount: float,
428
432
  table_name: str = DEFAULT_TABLES.get("proj"),
429
- ) -> bool:
433
+ ) -> int:
430
434
  """Updation of the the project detail in project table
431
435
 
432
436
  Args:
@@ -437,22 +441,22 @@ class DB:
437
441
  table_name (str): table name of the project.
438
442
 
439
443
  Returns:
440
- bool: True for the success and False for the failure.
444
+ int: Primary key of the project.
441
445
  """
442
446
  with self.connection:
443
447
  try:
444
448
  self.cursor.execute(
445
449
  f"UPDATE {table_name} SET \
446
450
  project_number ='{new_project_number}', paid_by='{new_paid_by}', amount='{new_amount}' \
447
- WHERE id='{project_id}';"
451
+ WHERE id='{project_id}' RETURNING id;"
448
452
  )
449
453
  LOG.info(
450
454
  f"INFO: Updation of the project {project_id} has been peformed successfully"
451
455
  )
452
- return True
456
+ return self.cursor.fetchone()[0]
453
457
  except Exception as e:
454
458
  LOG.error(f"Error: Project Updating in table {table_name} : {e}")
455
- return False
459
+ raise DbException(f"Error: Project Updating in table {table_name} : {e}")
456
460
 
457
461
  def remove_project(
458
462
  self, project_id: int, table_name: str = DEFAULT_TABLES.get("proj")
@@ -561,7 +565,7 @@ class DB:
561
565
  paid_by: int,
562
566
  amount: float,
563
567
  table_name: str = DEFAULT_TABLES.get("grant"),
564
- ) -> bool:
568
+ ) -> int:
565
569
  """Insertion of the grant detail.
566
570
 
567
571
  Args:
@@ -575,23 +579,23 @@ class DB:
575
579
  DbException: Exception for the provided inputs.
576
580
 
577
581
  Returns:
578
- bool: True for the success and False for the failure.
582
+ int: Primary key of the grant.
579
583
  """
580
584
  with self.connection:
581
585
  if grant_number:
582
586
  try:
583
587
  self.cursor.execute(
584
588
  f"INSERT INTO {table_name} (grant_number, paid_by, amount) \
585
- VALUES ('{grant_number}', '{paid_by}', '{amount}');"
589
+ VALUES ('{grant_number}', '{paid_by}', '{amount}') RETURNING id;"
586
590
  )
587
591
  LOG.info(
588
592
  f"INFO: Insertion of the grant {grant_number} and {amount} by \
589
593
  {paid_by} has been performed successfully."
590
594
  )
591
- return True
595
+ return self.cursor.fetchone()[0]
592
596
  except Exception as e:
593
597
  LOG.error(f"Error: grant Insert in table '{table_name}': {e}")
594
- return False
598
+ raise DbException(f"Error: grant Insert in table '{table_name}': {e}")
595
599
  else:
596
600
  LOG.error(
597
601
  "Error: Please provide grant_number, paid_by, amount for grants"
@@ -605,7 +609,7 @@ class DB:
605
609
  new_paid_by: int,
606
610
  new_amount: float,
607
611
  table_name: str = DEFAULT_TABLES.get("grant"),
608
- ) -> bool:
612
+ ) -> int:
609
613
  """ "Updation of the the grant detail in grant table
610
614
 
611
615
  Args:
@@ -616,23 +620,26 @@ class DB:
616
620
  table_name (str): table name of the grant.
617
621
 
618
622
  Returns:
619
- bool: True for the success and False for the failure.
623
+ int: Primary key of the Grant.
620
624
  """
621
625
  with self.connection:
622
626
  try:
623
627
  self.cursor.execute(
624
628
  f"UPDATE {table_name} SET grant_number ='{new_grant}', paid_by='{new_paid_by}', \
625
- amount='{new_amount}' WHERE id='{grant_id}';"
629
+ amount='{new_amount}' WHERE id='{grant_id}' RETURNING id;"
626
630
  )
627
631
  LOG.info(
628
632
  f"INFO: Updation of the grant {grant_id} has been performed successfully."
629
633
  )
630
- return True
634
+ return self.cursor.fetchone()[0]
631
635
  except Exception as e:
632
636
  LOG.error(
633
637
  f"Error: grant Updating of '{grant_id}' in table '{table_name}': {e}"
634
638
  )
635
- return False
639
+ raise DbException(
640
+ f"Error: grant Updating of '{grant_id}' in table '{table_name}': {e}"
641
+ )
642
+
636
643
 
637
644
  def remove_grant(
638
645
  self, grant_id: int, table_name: str = DEFAULT_TABLES.get("grant")
@@ -740,7 +747,7 @@ class DB:
740
747
  project_id: Optional[int] = None,
741
748
  grant_id: Optional[int] = None,
742
749
  table_name: str = DEFAULT_TABLES.get("costing"),
743
- ) -> bool:
750
+ ) -> int:
744
751
  """Insertion of the costing detail.
745
752
 
746
753
  Args:
@@ -755,7 +762,7 @@ class DB:
755
762
  DbException: Exception for the provided inputs.
756
763
 
757
764
  Returns:
758
- bool: True for the success and False for the failure.
765
+ int: Primary key of the costing.
759
766
  """
760
767
  with self.connection:
761
768
  if project_id and grant_id:
@@ -769,28 +776,32 @@ class DB:
769
776
  try:
770
777
  self.cursor.execute(
771
778
  f"INSERT INTO {table_name} (deployment_id, type, project_id) VALUES \
772
- ('{deployment_id}', '{typee}', '{project_id}');"
779
+ ('{deployment_id}', '{typee}', '{project_id}') RETURNING id;"
773
780
  )
774
781
  LOG.info("INFO: Costing insertion has been performed successfully")
775
- return True
782
+ return self.cursor.fetchone()[0]
776
783
  except Exception as e:
777
784
  LOG.error(
778
785
  f"Error: cost removal failed in table '{table_name}': {e}"
779
786
  )
780
- return False
787
+ raise DbException(
788
+ f"Error: cost removal failed in table '{table_name}': {e}"
789
+ )
781
790
  elif deployment_id and grant_id and typee:
782
791
  try:
783
792
  self.cursor.execute(
784
793
  f"INSERT INTO {table_name} (deployment_id, type, grant_id) VALUES \
785
- ('{deployment_id}', '{typee}', '{grant_id}');"
794
+ ('{deployment_id}', '{typee}', '{grant_id}') RETURNING id;"
786
795
  )
787
796
  LOG.info("INFO: Insertion of costing has been successfully")
788
- return True
797
+ return self.cursor.fetchone()[0]
789
798
  except Exception as e:
790
799
  LOG.error(
791
800
  f"Error: cost removal failed in table '{table_name}': {e}"
792
801
  )
793
- return False
802
+ raise DbException(
803
+ f"Error: cost removal failed in table '{table_name}': {e}"
804
+ )
794
805
  else:
795
806
  LOG.error(
796
807
  "Error: Please provide correct deployment_id, type, and, (project_id/grant_id) for costing"
@@ -807,7 +818,7 @@ class DB:
807
818
  new_grant_id: Optional[int] = None,
808
819
  new_project_id: Optional[int] = None,
809
820
  table_name: str = DEFAULT_TABLES.get("costing"),
810
- ) -> bool:
821
+ ) -> int:
811
822
  """Updation of the costing database entry.
812
823
 
813
824
  Args:
@@ -822,7 +833,7 @@ class DB:
822
833
  DbException: Exception for the provided inputs.
823
834
 
824
835
  Returns:
825
- bool: True for the success and False for the failure.
836
+ int: Primary key of the costing.
826
837
  """
827
838
  if new_grant_id and new_project_id:
828
839
  raise DbException(
@@ -835,12 +846,12 @@ class DB:
835
846
  self.cursor.execute(
836
847
  f"UPDATE {table_name} SET \
837
848
  deployment_id ='{new_deployment_id}', type='{new_typee}', project_id={project_id}, \
838
- grant_id={grant_id} WHERE id='{old_costing_id}';"
849
+ grant_id={grant_id} WHERE id='{old_costing_id}' RETURNING id;"
839
850
  )
840
851
  LOG.info(
841
852
  "INFO: updation of the costing has been performed successfully."
842
853
  )
843
- return True
854
+ return self.cursor.fetchone()[0]
844
855
  except Exception as e:
845
856
  LOG.error(
846
857
  f"Error: Updation of costing has failed in table '{table_name}': \n {e}"
@@ -1 +1 @@
1
- VERSION = "0.2.0"
1
+ VERSION = "0.2.2"
@@ -37,7 +37,7 @@ def main():
37
37
  if not utils.pre_setupconfig(db_params):
38
38
  raise DbException("ERROR: Tables are not created successfully")
39
39
 
40
- # db.insert_vrauser("ll220", "len")
40
+ # print(db.insert_vrauser("ll221", "leny"))
41
41
  # print(db.get_vrauser("ll220"))
42
42
  # print(db.get_vrauser_primary_key("ll220"))
43
43
  # db.update_vrauser("ll220", "bda20", 'Ben Argyle')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ucampostgresvro
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: To connect with postgresql for the billing report
5
5
  Author: Ishan Mahajan
6
6
  Author-email: mahanishanmahajan@gmail.com
@@ -1,6 +1,6 @@
1
- ucampostgresvro/DBA.py,sha256=t8un2LmoTnHczbYMWl4hO7MVDfGZJTFe7xUXKyD3Cbg,37961
2
- ucampostgresvro/__init__.py,sha256=w9Iw7QVvd8lme2wKwEbCo5IgetVjSfFBOOYAcA_Q0Ns,18
3
- ucampostgresvro/__main__.py,sha256=RGTDhAAIoY-w6h64aKnsfv665DmdFf7cVwbX_Z16vWU,4122
1
+ ucampostgresvro/DBA.py,sha256=Bz3Ql-LtM-BUiQTWGww-Gjl6S3geTzifiZVxjN2Pcb4,38957
2
+ ucampostgresvro/__init__.py,sha256=qleN2zQctO8stGYcfqFUyavqMP9pxdKBbwgZWyKxPWQ,18
3
+ ucampostgresvro/__main__.py,sha256=87ArORk2ViXoUWCK7zyGL-ly4jpbP_JqMMLKio4K4wY,4130
4
4
  ucampostgresvro/ca.crt,sha256=pVDr3AsvwCqJ36JTifsAzIiS2ve_fWC1CBfVI0cnVmY,1135
5
5
  ucampostgresvro/exceptions.py,sha256=XVi8Sk_gg3VE4ryTtiYOnGbmCPIsfFt2AE5sOoqQDuI,39
6
6
  ucampostgresvro/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -10,7 +10,7 @@ ucampostgresvro/tests/test_DB.py,sha256=lye6NLUS2k7W7Kr083fQ5HDUD5hMMUqvIXL2xbNo
10
10
  ucampostgresvro/tests/utils.py,sha256=lpcvf6HPOOtxAwSwvoAUhil1zQ6Qfr0ZILa0qDVdES0,3722
11
11
  ucampostgresvro/tools.py,sha256=Y8MUK1lIG10A-724yrhve8LfjQUmFwpqi19UIO5DeuI,153
12
12
  ucampostgresvro/utils.py,sha256=QYhWaBaxGn-yKEGm___3-7RitbIWwICTplbz7LyKgLE,8543
13
- ucampostgresvro-0.2.0.dist-info/LICENSE,sha256=CVTj8C-BHEJjzYlYtHnfykxKkfmk-ImXOs5rcMgXebY,1094
14
- ucampostgresvro-0.2.0.dist-info/METADATA,sha256=IQ303ShVE8nT0g5qF_G1o473KIopfYzSHvdVJNdeIjI,9791
15
- ucampostgresvro-0.2.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
16
- ucampostgresvro-0.2.0.dist-info/RECORD,,
13
+ ucampostgresvro-0.2.2.dist-info/LICENSE,sha256=CVTj8C-BHEJjzYlYtHnfykxKkfmk-ImXOs5rcMgXebY,1094
14
+ ucampostgresvro-0.2.2.dist-info/METADATA,sha256=NLZ5tNdr7nQfpzYR2cKjxWQGCndZZv32rY0f5rUDpRQ,9791
15
+ ucampostgresvro-0.2.2.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
16
+ ucampostgresvro-0.2.2.dist-info/RECORD,,