Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
48e1356e
Unverified
Commit
48e1356e
authored
Jun 17, 2024
by
perf3ct
Browse files
add logging for user upon db connection
parent
5c655f29
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
backend/apps/webui/internal/wrappers.py
backend/apps/webui/internal/wrappers.py
+10
-4
No files found.
backend/apps/webui/internal/wrappers.py
View file @
48e1356e
from
contextvars
import
ContextVar
from
peewee
import
*
import
logging
from
playhouse.db_url
import
connect
from
playhouse.pool
import
PooledPostgresqlExtDatabase
from
playhouse.pool
import
PooledSqliteDatabase
from
config
import
SRC_LOG_LEVELS
log
=
logging
.
getLogger
(
__name__
)
log
.
setLevel
(
SRC_LOG_LEVELS
[
"DB"
])
db_state_default
=
{
"closed"
:
None
,
"conn"
:
None
,
"ctx"
:
None
,
"transactions"
:
None
}
db_state
=
ContextVar
(
"db_state"
,
default
=
db_state_default
.
copy
())
...
...
@@ -22,11 +26,13 @@ class PeeweeConnectionState(object):
def
register_connection
(
db_url
):
db
=
connect
(
db_url
)
if
isinstance
(
db
,
PostgresqlDatabase
):
#
Directly use PostgresqlDatabase without pooling
#
Enable autoconnect for SQLite databases, managed by Peewee
db
.
autoconnect
=
True
log
.
info
(
"Connected to PostgreSQL database"
)
elif
isinstance
(
db
,
SqliteDatabase
):
#
Directly use Sql
ite
D
atabase
without pooling
#
Enable autoconnect for SQL
ite
d
atabase
s, managed by Peewee
db
.
autoconnect
=
True
log
.
info
(
"Connected to SQLite database"
)
else
:
raise
ValueError
(
'Unsupported database connection'
)
return
db
\ 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