ucampostgresvro 0.2.0__py3-none-any.whl → 0.2.1__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"
@@ -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"
@@ -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"
@@ -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"
@@ -740,7 +744,7 @@ class DB:
740
744
  project_id: Optional[int] = None,
741
745
  grant_id: Optional[int] = None,
742
746
  table_name: str = DEFAULT_TABLES.get("costing"),
743
- ) -> bool:
747
+ ) -> int:
744
748
  """Insertion of the costing detail.
745
749
 
746
750
  Args:
@@ -755,7 +759,7 @@ class DB:
755
759
  DbException: Exception for the provided inputs.
756
760
 
757
761
  Returns:
758
- bool: True for the success and False for the failure.
762
+ int: Primary key of the costing.
759
763
  """
760
764
  with self.connection:
761
765
  if project_id and grant_id:
@@ -769,28 +773,32 @@ class DB:
769
773
  try:
770
774
  self.cursor.execute(
771
775
  f"INSERT INTO {table_name} (deployment_id, type, project_id) VALUES \
772
- ('{deployment_id}', '{typee}', '{project_id}');"
776
+ ('{deployment_id}', '{typee}', '{project_id}') RETURNING id;"
773
777
  )
774
778
  LOG.info("INFO: Costing insertion has been performed successfully")
775
- return True
779
+ return self.cursor.fetchone()[0]
776
780
  except Exception as e:
777
781
  LOG.error(
778
782
  f"Error: cost removal failed in table '{table_name}': {e}"
779
783
  )
780
- return False
784
+ raise DbException(
785
+ f"Error: cost removal failed in table '{table_name}': {e}"
786
+ )
781
787
  elif deployment_id and grant_id and typee:
782
788
  try:
783
789
  self.cursor.execute(
784
790
  f"INSERT INTO {table_name} (deployment_id, type, grant_id) VALUES \
785
- ('{deployment_id}', '{typee}', '{grant_id}');"
791
+ ('{deployment_id}', '{typee}', '{grant_id}') RETURNING id;"
786
792
  )
787
793
  LOG.info("INFO: Insertion of costing has been successfully")
788
- return True
794
+ return self.cursor.fetchone()[0]
789
795
  except Exception as e:
790
796
  LOG.error(
791
797
  f"Error: cost removal failed in table '{table_name}': {e}"
792
798
  )
793
- return False
799
+ raise DbException(
800
+ f"Error: cost removal failed in table '{table_name}': {e}"
801
+ )
794
802
  else:
795
803
  LOG.error(
796
804
  "Error: Please provide correct deployment_id, type, and, (project_id/grant_id) for costing"
@@ -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.1
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
1
+ ucampostgresvro/DBA.py,sha256=x795bE2kUOiDc1274bFXO1dMlQlvGQXZayirE0TGlZM,38597
2
2
  ucampostgresvro/__init__.py,sha256=w9Iw7QVvd8lme2wKwEbCo5IgetVjSfFBOOYAcA_Q0Ns,18
3
- ucampostgresvro/__main__.py,sha256=RGTDhAAIoY-w6h64aKnsfv665DmdFf7cVwbX_Z16vWU,4122
3
+ ucampostgresvro/__main__.py,sha256=KzZTQ308dHN0OuvxObUhCdGJz2sbb8iFr-wOP6_iSMg,4128
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.1.dist-info/LICENSE,sha256=CVTj8C-BHEJjzYlYtHnfykxKkfmk-ImXOs5rcMgXebY,1094
14
+ ucampostgresvro-0.2.1.dist-info/METADATA,sha256=xQeFtb89nyd4YJuY7SKQONgjZBhM-1WJ3i3HFbejw0c,9791
15
+ ucampostgresvro-0.2.1.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
16
+ ucampostgresvro-0.2.1.dist-info/RECORD,,