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
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
vidya.m
PostgreSQL_CRUD
Commits
fcaf3309
Commit
fcaf3309
authored
Mar 27, 2023
by
vidya.m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
7c159053
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
utils/pos_util.py
utils/pos_util.py
+67
-0
No files found.
utils/pos_util.py
0 → 100644
View file @
fcaf3309
from
sqlalchemy
import
Column
,
Integer
,
String
,
MetaData
,
text
from
sqlalchemy
import
Table
from
scripts.core.db.database
import
session
from
scripts.core.schema.pos_agg
import
student
metadata
=
MetaData
()
class
PosUtility
:
@
staticmethod
def
create_table
():
try
:
student_table
=
Table
(
'student_data'
,
metadata
,
Column
(
'student_id'
,
Integer
,
primary_key
=
True
,
index
=
True
),
Column
(
'student_name'
,
String
),
Column
(
'description'
,
String
),
Column
(
'address'
,
String
)
)
return
student_table
except
Exception
as
e
:
print
(
e
,
"Failed to create table"
)
@
staticmethod
def
insert_data
(
request_data
):
try
:
new_student_data
=
student
(
student_name
=
request_data
.
student_name
,
description
=
request_data
.
description
,
address
=
request_data
.
address
)
return
new_student_data
except
Exception
as
e
:
print
(
e
,
"Failed to Insert data"
)
@
staticmethod
def
delete_data
(
student_id
):
try
:
data
=
session
.
query
(
student
)
.
filter_by
(
stuent_id
=
student_id
)
.
first
()
return
data
except
Exception
as
e
:
print
(
e
,
"Failed to delete data"
)
@
staticmethod
def
update_data
(
request_data
,
student_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
(
student
)
.
filter
(
text
(
str
(
f
"student_id={student_id}"
))
)
.
update
(
get_update
)
return
update_data
except
Exception
as
e
:
print
(
e
,
"failed to update the data"
)
@
staticmethod
def
fetch_data
():
try
:
student_data
=
session
.
query
(
student
)
.
all
()
list_
=
[]
for
data
in
student_data
:
list_
.
append
(
{
"student_id"
:
data
.
student_id
,
"student_name"
:
data
.
student_name
,
"desciption"
:
data
.
description
,
"address"
:
data
.
address
})
return
list_
except
Exception
as
e
:
print
(
e
,
"Failed to Find the data"
)
\ No newline at end of file
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