Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
663fbfb2
Commit
663fbfb2
authored
Nov 21, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
50a7f9c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
22 deletions
+27
-22
application/utils/dsn/sql.py
application/utils/dsn/sql.py
+27
-22
No files found.
application/utils/dsn/sql.py
View file @
663fbfb2
...
@@ -7,33 +7,25 @@
...
@@ -7,33 +7,25 @@
# @Email : StudentCWZ@outlook.com
# @Email : StudentCWZ@outlook.com
# @Date : 2023/10/29 00:36
# @Date : 2023/10/29 00:36
# @File : sql.py
# @File : sql.py
# @Description :
# @Description :
Defines the DatabaseUri class for generating SQLAlchemy database connection strings.
"""
"""
class
DatabaseUri
:
class
DatabaseUri
:
"""
"""
The DatabaseURI class is a utility for generating SQLAlchemy database
A utility class to generate SQLAlchemy database connection strings for various types of databases.
connection strings for various types of databases.
:param db_type: The type of the database. It could be "mysql", "postgresql", "oracle", "sqlite".
Args:
:param username: The username of the database. Not required for "sqlite".
db_type (str): The type of the database. It could be "mysql", "postgresql", "oracle", "sqlite".
:param password: The password of the database. Not required for "sqlite".
username (str, optional): The username of the database. Not required for "sqlite".
:param host: The host of the database. Not required for "sqlite".
password (str, optional): The password of the database. Not required for "sqlite".
:param port: The port of the database. Not required for "sqlite".
host (str, optional): The host of the database. Not required for "sqlite".
:param db: The database name. For "sqlite", it is the path to the database file.
port (str, optional): The port of the database. Not required for "sqlite".
:param driver: The python library to connect to the database. Not required but could be provided.
db (str, optional): The database name. For "sqlite", it is the path to the database file.
driver (str, optional): The python library to connect to the database. Not required but could be provided.
"""
"""
def
__init__
(
self
,
db_type
:
str
,
username
:
str
=
None
,
password
:
str
=
None
,
def
__init__
(
self
,
host
:
str
=
None
,
port
:
str
=
None
,
db
:
str
=
None
,
driver
:
str
=
None
)
->
None
:
db_type
:
str
,
username
:
str
=
None
,
password
:
str
=
None
,
host
:
str
=
None
,
port
:
str
=
None
,
db
:
str
=
None
,
driver
:
str
=
None
)
->
None
:
self
.
db_type
=
db_type
self
.
db_type
=
db_type
self
.
username
=
username
self
.
username
=
username
self
.
password
=
password
self
.
password
=
password
...
@@ -46,9 +38,10 @@ class DatabaseUri:
...
@@ -46,9 +38,10 @@ class DatabaseUri:
"""
"""
Creates a SQLAlchemy engine string for the specified database.
Creates a SQLAlchemy engine string for the specified database.
:return: A SQLAlchemy engine string.
Returns:
str: A SQLAlchemy engine string.
"""
"""
# SQLite database only require a path to the database file
# SQLite database only require
s
a path to the database file
if
self
.
db_type
==
'sqlite'
:
if
self
.
db_type
==
'sqlite'
:
return
f
'
{
self
.
db_type
}
:///
{
self
.
db
}
'
return
f
'
{
self
.
db_type
}
:///
{
self
.
db
}
'
else
:
else
:
...
@@ -60,7 +53,19 @@ class DatabaseUri:
...
@@ -60,7 +53,19 @@ class DatabaseUri:
return
f
'
{
self
.
db_type
}
://
{
self
.
username
}
:
{
self
.
password
}
@
{
self
.
host
}
:
{
self
.
port
}
/
{
self
.
db
}
'
return
f
'
{
self
.
db_type
}
://
{
self
.
username
}
:
{
self
.
password
}
@
{
self
.
host
}
:
{
self
.
port
}
/
{
self
.
db
}
'
def
__repr__
(
self
):
def
__repr__
(
self
):
"""
Returns a formal string representation of the DatabaseUri object.
Returns:
str: The formal string representation of the DatabaseUri object.
"""
return
f
'<DatabaseUri(
{
self
.
db_type
}
)>'
return
f
'<DatabaseUri(
{
self
.
db_type
}
)>'
def
__str__
(
self
):
def
__str__
(
self
):
"""
Returns a string representation of the DatabaseUri object, which is the SQLAlchemy engine string.
Returns:
str: The string representation of the DatabaseUri object.
"""
return
self
.
create
()
return
self
.
create
()
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