Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
logbook-hfe
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
harshavardhan.c
logbook-hfe
Commits
4994078b
Commit
4994078b
authored
Mar 09, 2021
by
harshavardhan.c
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added sqlalchemy utils file
parent
6e3b40f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
scripts/utils/sql_db_utils.py
scripts/utils/sql_db_utils.py
+66
-0
No files found.
scripts/utils/sql_db_utils.py
0 → 100644
View file @
4994078b
from
sqlalchemy
import
String
,
JSON
,
Float
,
Integer
from
sqlalchemy
import
create_engine
,
MetaData
,
Column
,
Table
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy.orm
import
sessionmaker
from
scripts.logging.logging
import
logger
as
LOG
from
scripts.utils.common_utils
import
CommonUtils
Base
=
declarative_base
()
class
TableAudits
(
Base
):
__tablename__
=
"table_user_entry"
template_id
=
Column
(
String
)
template_json
=
Column
(
JSON
)
user_id
=
Column
(
String
)
last_updated
=
Column
(
Float
(
precision
=
20
,
decimal_return_scale
=
True
))
id
=
Column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
@
staticmethod
def
column_template_id
():
return
'template_id'
@
staticmethod
def
column_audit_type
():
return
'audit_type'
@
staticmethod
def
column_audit_time
():
return
'audit_time'
@
staticmethod
def
column_audit_mapping_id
():
return
'audit_mapping_id'
@
staticmethod
def
column_audit_message
():
return
'audit_message'
def
table_def_audits
(
self
,
meta
=
MetaData
()):
return
Table
(
self
.
__tablename__
,
meta
,
Column
(
self
.
column_audit_id
(),
String
(
64
),
primary_key
=
True
),
Column
(
self
.
column_audit_type
(),
String
(
64
)),
Column
(
self
.
column_audit_time
(),
BigInteger
),
Column
(
self
.
column_audit_mapping_id
(),
String
(
64
)),
Column
(
self
.
column_audit_message
(),
String
(
2048
)),
extend_existing
=
True
)
class
SQLDBUtils
(
CommonUtils
):
def
__init__
(
self
,
create_tables
=
False
):
self
.
filter
=
None
super
()
.
__init__
()
self
.
engine
=
create_engine
(
self
.
db_endpoint
(),
echo
=
self
.
sqlalchemy_echo
())
if
create_tables
:
self
.
meta
=
MetaData
()
session
=
sessionmaker
()
session
.
configure
(
bind
=
self
.
engine
)
self
.
session
=
session
()
def
__del__
(
self
):
LOG
.
trace
(
"SQL Session closed"
)
self
.
session
.
close
()
def
close
(
self
):
LOG
.
trace
(
"SQL Session closed"
)
self
.
session
.
close
()
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