-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from zilliztech/database
Support database
- Loading branch information
Showing
19 changed files
with
181 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createContext, useEffect, useState } from 'react'; | ||
import { DatabaseHttp } from '@/http/Database'; | ||
import { DatabaseContextType } from './Types'; | ||
|
||
export const databaseContext = createContext<DatabaseContextType>({ | ||
database: 'default', | ||
databases: ['default'], | ||
setDatabase: () => {}, | ||
}); | ||
|
||
const { Provider } = databaseContext; | ||
export const DatabaseProvider = (props: { children: React.ReactNode }) => { | ||
const [database, setDatabase] = useState<string>('default'); | ||
const [databases, setDatabases] = useState<string[]>(['default']); | ||
|
||
const fetchDatabases = async () => { | ||
const res = await DatabaseHttp.getDatabases(); | ||
setDatabases(res.db_names); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchDatabases(); | ||
}, []); | ||
|
||
return ( | ||
<Provider | ||
value={{ | ||
database, | ||
databases, | ||
setDatabase, | ||
}} | ||
> | ||
{props.children} | ||
</Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.