import React from 'react'; import Grid from '@material-ui/core/Grid'; import Box from '@material-ui/core/Box'; import Button from '@material-ui/core/Button'; import Typography from '@material-ui/core/Typography'; import TextField from '@material-ui/core/TextField'; import FormHelperText from '@material-ui/core/FormHelperText'; import Radio from '@material-ui/core/Radio'; import RadioGroup from '@material-ui/core/RadioGroup'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import FormControl from '@material-ui/core/FormControl'; import FormLabel from '@material-ui/core/FormLabel'; import Alert from '@material-ui/lab/Alert'; import {configureDatabase, testDatabaseConnection} from '../api/bbgo'; import {makeStyles} from '@material-ui/core/styles'; const useStyles = makeStyles((theme) => ({ formControl: { marginTop: theme.spacing(1), marginBottom: theme.spacing(1), minWidth: 120, }, buttons: { display: 'flex', justifyContent: 'flex-end', marginTop: theme.spacing(2), paddingTop: theme.spacing(2), paddingBottom: theme.spacing(2), '& > *': { marginLeft: theme.spacing(1), } }, })); export default function ConfigureDatabaseForm({onConfigured}) { const classes = useStyles(); const [mysqlURL, setMysqlURL] = React.useState("root@tcp(127.0.0.1:3306)/bbgo") const [driver, setDriver] = React.useState("sqlite3"); const [testing, setTesting] = React.useState(false); const [testResponse, setTestResponse] = React.useState(null); const [configured, setConfigured] = React.useState(false); const getDSN = () => driver === "sqlite3" ? "file:bbgo.sqlite3" : mysqlURL const resetTestResponse = () => { setTestResponse(null) } const handleConfigureDatabase = (event) => { const dsn = getDSN() configureDatabase({driver, dsn}, (response) => { console.log(response); setTesting(false); setTestResponse(response); if (onConfigured) { setConfigured(true); setTimeout(onConfigured, 3000); } }).catch((err) => { console.error(err); setTesting(false); setTestResponse(err.response.data); }) } const handleTestConnection = (event) => { const dsn = getDSN() setTesting(true); testDatabaseConnection({driver, dsn}, (response) => { console.log(response) setTesting(false) setTestResponse(response) }).catch((err) => { console.error(err) setTesting(false) setTestResponse(err.response.data) }) }; return ( Configure Database If you have database installed on your machine, you can enter the DSN string in the following field. Please note this is optional, you CAN SKIP this step. Database Driver { setDriver(event.target.value); }}> } label="Standard (Default)"/> } label="MySQL"/> {driver === "mysql" ? ( { setMysqlURL(event.target.value) resetTestResponse() }} /> MySQL DSN If you have database installed on your machine, you can enter the DSN string like the following format:
root:password@tcp(127.0.0.1:3306)/bbgo

Be sure to create your database before using it. You need to execute the following statement to create a database:
CREATE DATABASE bbgo CHARSET utf8;
) : ( If you don't know what to choose, just pick the standard driver (sqlite3).
For professionals, you can pick MySQL driver, BBGO works best with MySQL, especially for larger data scale.
)}
{ testResponse ? testResponse.error ? ( {testResponse.error} ) : testResponse.success ? ( Connection Test Succeeded ) : null : null }
); }