Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Postgresql crud operations
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vipul.v
Postgresql crud operations
Commits
2a1e6c47
Commit
2a1e6c47
authored
Mar 27, 2023
by
vipul.v
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crud operation second
parent
da93a39f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
35 deletions
+41
-35
.idea/sonarlint/issuestore/index.pb
.idea/sonarlint/issuestore/index.pb
+11
-0
.idea/sonarlint/securityhotspotstore/index.pb
.idea/sonarlint/securityhotspotstore/index.pb
+11
-0
script/core/errors/__init__.py
script/core/errors/__init__.py
+1
-1
script/core/handlers/inventory.py
script/core/handlers/inventory.py
+16
-32
script/service/inventory.py
script/service/inventory.py
+2
-2
No files found.
.idea/sonarlint/issuestore/index.pb
View file @
2a1e6c47
N
script/core/schema/__init__.py,8\4\84b7e789bb411a2f2e44fa4f79362bae15a9ca5e
\
,.idea/inspectionProfiles/Project_Default.xml,4\9\496a238a6afa168dbaf6efd37bb459331589579c
^
..idea/inspectionProfiles/profiles_settings.xml,1\e\1e9075f5bf079c01ef2c910709e91a497d262080
4
.env,3\c\3c84dcdc6bbe3d7817c49dcdc327b926fea1808a
E
conf/application.conf,6\4\644f59db746795ef1538ef95c4cbc0eab6663e28
\ No newline at end of file
.idea/sonarlint/securityhotspotstore/index.pb
View file @
2a1e6c47
N
script/core/schema/__init__.py,8\4\84b7e789bb411a2f2e44fa4f79362bae15a9ca5e
\
,.idea/inspectionProfiles/Project_Default.xml,4\9\496a238a6afa168dbaf6efd37bb459331589579c
^
..idea/inspectionProfiles/profiles_settings.xml,1\e\1e9075f5bf079c01ef2c910709e91a497d262080
4
.env,3\c\3c84dcdc6bbe3d7817c49dcdc327b926fea1808a
E
conf/application.conf,6\4\644f59db746795ef1538ef95c4cbc0eab6663e28
\ No newline at end of file
script/core/errors/__init__.py
View file @
2a1e6c47
...
...
@@ -2,5 +2,5 @@ class ErrorMessage(Exception):
ERRORS_INSERT
=
"Due to value error in insertion"
ERRORS_FETCH
=
"Due to value error in fetch"
ERRORS_UPDATE
=
"Due to value error in update"
ERRORS_DELETE
=
"Due to value error in deletion"
ERRORS_DELETE
=
"Due to value error in deletion"
script/core/handlers/inventory.py
View file @
2a1e6c47
from
sqlalchemy
import
Column
,
Integer
,
String
,
MetaData
,
text
from
sqlalchemy
import
Table
from
sqlalchemy
import
MetaData
from
script.core.db.postgresql_connector
import
session
from
script.
core.schema.inventory
import
Inventor
y
from
script.
utils.inventory_utils
import
SqlUtilit
y
metadata
=
MetaData
()
SqlUtility
=
SqlUtility
()
class
PostgresqlCollectRecords
:
@
staticmethod
def
create_table
():
try
:
inventory_table
=
Table
(
'inventory_data'
,
metadata
,
Column
(
'order_id'
,
Integer
,
primary_key
=
True
,
index
=
True
),
Column
(
'customer_name'
,
String
),
Column
(
'status'
,
String
),
Column
(
'sales_order'
,
Integer
,
index
=
True
)
)
return
inventory_table
data
=
SqlUtility
.
create_file
()
return
data
except
Exception
as
e
:
print
(
e
,
"Error detected in creating the table"
)
@
staticmethod
def
insert_data
(
request_data
):
try
:
new_inventory_data
=
Inventory
(
customer_name
=
request_data
.
customer_name
,
status
=
request_data
.
status
,
sales_order
=
request_data
.
sales_order
)
session
.
add
(
new_inventory_data
)
data
=
SqlUtility
.
insert_file
(
request_data
)
session
.
add
(
data
)
session
.
commit
()
return
{
"order_id"
:
new_inventory_data
.
order_id
,
"customer_name"
:
new_inventory_
data
.
customer_name
,
"status"
:
new_inventory_
data
.
status
,
"sales_order"
:
new_inventory_
data
.
sales_order
}
return
{
"order_id"
:
data
.
order_id
,
"customer_name"
:
data
.
customer_name
,
"status"
:
data
.
status
,
"sales_order"
:
data
.
sales_order
}
except
Exception
as
e
:
print
(
e
,
"Error detected in inserting"
)
@
staticmethod
def
fetch_records
():
try
:
inventory_data
=
session
.
query
(
Inventory
)
.
all
()
list_
=
[]
for
data
in
inventory_data
:
list_
.
append
({
"order_id"
:
data
.
order_id
,
"customer_name"
:
data
.
customer_name
,
"status"
:
data
.
status
,
"sales_order"
:
data
.
sales_order
})
return
list_
data
=
SqlUtility
.
fetch_file
()
return
data
except
Exception
as
e
:
print
(
e
,
"Error detected in fetching the data"
)
@
staticmethod
def
update_records
(
request_data
,
order_id
):
try
:
get_update
=
{
key
:
value
for
key
,
value
in
request_data
if
value
is
not
None
and
value
!=
'string'
and
value
!=
0
}
update_data
=
session
.
query
(
Inventory
)
.
filter
(
text
(
str
(
f
"order_id={order_id}"
))
)
.
update
(
get_update
)
data
=
SqlUtility
.
update_file
(
request_data
,
order_id
)
session
.
commit
()
print
(
update_data
)
return
update_data
return
data
except
Exception
as
e
:
print
(
e
,
"Error detected in updating"
)
@
staticmethod
def
delete_records
(
order_id
):
try
:
data
=
session
.
query
(
Inventory
)
.
filter_by
(
order_id
=
order_id
)
.
first
(
)
data
=
SqlUtility
.
delete_file
(
order_id
)
session
.
delete
(
data
)
session
.
commit
()
return
data
...
...
script/service/inventory.py
View file @
2a1e6c47
...
...
@@ -5,7 +5,7 @@ from fastapi import APIRouter
from
script.constants
import
APIEndpoints
from
script.core.errors
import
ErrorMessage
from
script.core.handlers.inventory
import
PostgresqlCollectRecords
from
script.core.schema.inventory
import
Inventory
,
Inventory
Data
,
UpdateInventoryData
from
script.core.schema.inventory
import
InventoryData
,
UpdateInventoryData
from
script.core.schema.responses
import
DefaultResponse
router
=
APIRouter
(
prefix
=
APIEndpoints
.
inventory_base
)
...
...
@@ -16,7 +16,7 @@ handler = PostgresqlCollectRecords()
async
def
insert_item
(
request_data
:
InventoryData
):
try
:
data
=
handler
.
insert_data
(
request_data
)
return
DefaultResponse
(
message
=
"Successfully inserted"
,
status
=
"success"
,
data
=
data
)
return
DefaultResponse
(
message
=
"Successfully inserted"
,
status
=
"success"
,
data
=
data
)
except
ValueError
:
return
DefaultResponse
(
message
=
ErrorMessage
.
ERRORS_INSERT
)
except
Exception
as
e
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment