mirror of
https://github.com/ershisan99/db-studio.git
synced 2025-12-18 12:33:07 +00:00
add login support (wonky still)
This commit is contained in:
@@ -9,9 +9,14 @@ import type {
|
||||
GetTableForeignKeysArgs,
|
||||
GetTableIndexesArgs,
|
||||
GetTablesListArgs,
|
||||
QueryRawSqlArgs,
|
||||
} from "./db.types";
|
||||
|
||||
export const useLoginMutation = () => {
|
||||
return useMutation({
|
||||
mutationFn: dbService.login,
|
||||
});
|
||||
};
|
||||
|
||||
export const useDatabasesListQuery = () => {
|
||||
return useQuery({
|
||||
queryKey: [DB_QUERY_KEYS.DATABASES.ALL],
|
||||
@@ -90,7 +95,6 @@ export const useQueryRawSqlMutation = () => {
|
||||
}
|
||||
toast.error(error.message);
|
||||
},
|
||||
mutationFn: ({ query }: QueryRawSqlArgs) =>
|
||||
dbService.queryRawSql({ query }),
|
||||
mutationFn: dbService.queryRawSql,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import ky from 'ky'
|
||||
import ky from "ky";
|
||||
|
||||
export const dbInstance = ky.create({
|
||||
prefixUrl: 'http://localhost:3000'
|
||||
})
|
||||
credentials: "include",
|
||||
prefixUrl: "http://localhost:3000",
|
||||
});
|
||||
|
||||
@@ -9,6 +9,8 @@ import type {
|
||||
GetTableIndexesArgs,
|
||||
GetTablesListArgs,
|
||||
GetTablesListResponse,
|
||||
LoginArgs,
|
||||
LoginResponse,
|
||||
QueryRawSqlArgs,
|
||||
QueryRawSqlResponse,
|
||||
TableColumns,
|
||||
@@ -17,6 +19,12 @@ import type {
|
||||
} from "@/services/db/db.types";
|
||||
|
||||
class DbService {
|
||||
login(data: LoginArgs) {
|
||||
return dbInstance
|
||||
.post("api/auth/login", { json: data })
|
||||
.json<LoginResponse>();
|
||||
}
|
||||
|
||||
getDatabasesList() {
|
||||
return dbInstance.get("api/databases").json<DatabasesResponse>();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
export type LoginArgs =
|
||||
| {
|
||||
username: string;
|
||||
password: string;
|
||||
host: string;
|
||||
type: string;
|
||||
port: string;
|
||||
ssl: string;
|
||||
database: string;
|
||||
}
|
||||
| {
|
||||
connectionString: string;
|
||||
};
|
||||
|
||||
export type LoginResponse = {
|
||||
success: boolean;
|
||||
};
|
||||
|
||||
export type DatabasesResponse = Array<string>;
|
||||
|
||||
// Tables List
|
||||
|
||||
Reference in New Issue
Block a user