feat: implement dynamic database connection service with MySQL driver and API schema endpoints
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import axios from 'axios';
|
||||
import { useAppStore } from '../store/useAppStore';
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: 'http://localhost:8000/api',
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const connection = useAppStore.getState().connection;
|
||||
if (connection) {
|
||||
config.params = {
|
||||
...config.params,
|
||||
host: connection.host,
|
||||
username: connection.username,
|
||||
password: connection.password,
|
||||
port: connection.port,
|
||||
database: connection.database || config.params?.database,
|
||||
};
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export default api;
|
||||
|
||||
export const SchemaService = {
|
||||
getDatabases: () => api.get('/schema/databases'),
|
||||
getTables: (db: string) => api.get(`/schema/tables/${db}`),
|
||||
getTableSchema: (table: string) => api.get(`/schema/${table}`),
|
||||
getTableData: (table: string, database?: string) => api.get(`/schema/${table}/data`, { params: { database } }),
|
||||
};
|
||||
Reference in New Issue
Block a user