55from pydantic import Field
66from typing_extensions import Literal
77
8+ from llmstack .base .models import Profile
89from llmstack .common .blocks .base .schema import BaseSchema as _Schema
910from llmstack .common .blocks .data .store .database .constants import DatabaseEngineType
1011from llmstack .common .blocks .data .store .database .database_reader import (
1617)
1718from llmstack .common .blocks .data .store .vectorstore import Document
1819from llmstack .common .utils .models import Config
20+ from llmstack .connections .models import ConnectionType
1921from llmstack .datasources .handlers .datasource_processor import (
2022 DataSourceEntryItem ,
2123 DataSourceProcessor ,
@@ -33,8 +35,6 @@ class PostgreSQLConnection(_Schema):
3335 description = "Port number to connect to the PostgreSQL instance" ,
3436 )
3537 database_name : str = Field (description = "PostgreSQL database name" )
36- username : str = Field (description = "PostgreSQL database username" )
37- password : Optional [str ] = Field (description = "PostgreSQL database password" )
3838
3939 class Config :
4040 title = "PostgreSQL"
@@ -47,16 +47,14 @@ class MySQLConnection(_Schema):
4747 description = "Port number to connect to the MySQL instance" ,
4848 )
4949 database_name : str = Field (description = "MySQL database name" )
50- username : str = Field (description = "MySQL database username" )
51- password : Optional [str ] = Field (description = "MySQL database password" )
5250
5351 class Config :
5452 title = "MySQL"
5553
5654
5755class SQLiteConnection (_Schema ):
5856 engine : Literal [DatabaseEngineType .SQLITE ] = DatabaseEngineType .SQLITE
59- database_path : str = Field (description = "MySQL database name " )
57+ database_path : str = Field (description = "SQLite database file path " )
6058
6159 class Config :
6260 title = "SQLite"
@@ -68,7 +66,12 @@ class Config:
6866class SQLDatabaseSchema (DataSourceSchema ):
6967 connection : Optional [SQLConnection ] = Field (
7068 title = "Database" ,
71- description = "Database details" ,
69+ # description="Database details",
70+ )
71+ connection_id : Optional [str ] = Field (
72+ widget = "connection" ,
73+ advanced_parameter = False ,
74+ description = "Use your authenticated connection to the database" ,
7275 )
7376
7477
@@ -84,6 +87,8 @@ class SQLDataSource(DataSourceProcessor[SQLDatabaseSchema]):
8487 # configuration, and sets up Weaviate Database Configuration.
8588 def __init__ (self , datasource : DataSource ):
8689 self .datasource = datasource
90+ self .profile = Profile .objects .get (user = self .datasource .owner )
91+ self ._env = self .profile .get_vendor_env ()
8792
8893 if self .datasource .config and "data" in self .datasource .config :
8994 config_dict = SQLConnectionConfiguration ().from_dict (
@@ -103,10 +108,24 @@ def __init__(self, datasource: DataSource):
103108 dbpath = self ._configuration .connection .database_path ,
104109 )
105110 else :
111+ username = password = None
112+
113+ connection = (
114+ self ._env ["connections" ].get (
115+ self ._configuration .connection_id ,
116+ None ,
117+ )
118+ if self ._configuration .connection_id
119+ else None
120+ )
121+ if connection and connection ["base_connection_type" ] == ConnectionType .CREDENTIALS :
122+ username = connection ["configuration" ]["username" ]
123+ password = connection ["configuration" ]["password" ]
124+
106125 self ._reader_configuration = database_configuration_class (
107126 engine = self ._configuration .connection .engine ,
108- user = self . _configuration . connection . username ,
109- password = self . _configuration . connection . password ,
127+ user = username ,
128+ password = password ,
110129 host = self ._configuration .connection .host ,
111130 port = self ._configuration .connection .port ,
112131 dbname = self ._configuration .connection .database_name ,
0 commit comments