mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-08 12:30:14 +00:00
feat: Add examples and modify deploy documents
This commit is contained in:
68
scripts/examples/load_examples.bat
Normal file
68
scripts/examples/load_examples.bat
Normal file
@@ -0,0 +1,68 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
:: Get script location and set working directory
|
||||
for %%i in (%0) do set SCRIPT_LOCATION=%%~dpi
|
||||
cd %SCRIPT_LOCATION%
|
||||
cd ..
|
||||
cd ..
|
||||
set WORK_DIR=%CD%
|
||||
|
||||
:: Check if sqlite3 is installed
|
||||
where sqlite3 >nul 2>nul
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo sqlite3 not found, please install sqlite3
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: Default file paths
|
||||
set DEFAULT_DB_FILE=DB-GPT\pilot\data\default_sqlite.db
|
||||
set DEFAULT_SQL_FILE=DB-GPT\docker\examples\sqls\*_sqlite.sql
|
||||
set DB_FILE=%WORK_DIR%\pilot\data\default_sqlite.db
|
||||
set SQL_FILE=
|
||||
|
||||
:argLoop
|
||||
if "%1"=="" goto argDone
|
||||
if "%1"=="-d" goto setDBFile
|
||||
if "%1"=="--db-file" goto setDBFile
|
||||
if "%1"=="-f" goto setSQLFile
|
||||
if "%1"=="--sql-file" goto setSQLFile
|
||||
if "%1"=="-h" goto printUsage
|
||||
if "%1"=="--help" goto printUsage
|
||||
goto argError
|
||||
|
||||
:setDBFile
|
||||
shift
|
||||
set DB_FILE=%1
|
||||
shift
|
||||
goto argLoop
|
||||
|
||||
:setSQLFile
|
||||
shift
|
||||
set SQL_FILE=%1
|
||||
shift
|
||||
goto argLoop
|
||||
|
||||
:argError
|
||||
echo Invalid argument: %1
|
||||
goto printUsage
|
||||
|
||||
:printUsage
|
||||
echo USAGE: %0 [--db-file sqlite db file] [--sql-file sql file path to run]
|
||||
echo [-d|--db-file sqlite db file path] default: %DEFAULT_DB_FILE%
|
||||
echo [-f|--sql-file sqlite file to run] default: %DEFAULT_SQL_FILE%
|
||||
echo [-h|--help] Usage message
|
||||
exit /b 0
|
||||
|
||||
:argDone
|
||||
|
||||
if "%SQL_FILE%"=="" (
|
||||
if not exist "%WORK_DIR%\pilot\data" mkdir "%WORK_DIR%\pilot\data"
|
||||
for %%f in (%WORK_DIR%\docker\examples\sqls\*_sqlite.sql) do (
|
||||
echo execute sql file: %%f
|
||||
sqlite3 "%DB_FILE%" < "%%f"
|
||||
)
|
||||
) else (
|
||||
echo Execute SQL file %SQL_FILE%
|
||||
sqlite3 "%DB_FILE%" < "%SQL_FILE%"
|
||||
)
|
69
scripts/examples/load_examples.sh
Executable file
69
scripts/examples/load_examples.sh
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
# Only support SQLite now
|
||||
|
||||
SCRIPT_LOCATION=$0
|
||||
cd "$(dirname "$SCRIPT_LOCATION")"
|
||||
WORK_DIR=$(pwd)
|
||||
WORK_DIR="$WORK_DIR/../.."
|
||||
|
||||
if ! command -v sqlite3 > /dev/null 2>&1
|
||||
then
|
||||
echo "sqlite3 not found, please install sqlite3"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DEFAULT_DB_FILE="DB-GPT/pilot/data/default_sqlite.db"
|
||||
DEFAULT_SQL_FILE="DB-GPT/docker/examples/sqls/*_sqlite.sql"
|
||||
DB_FILE="$WORK_DIR/pilot/data/default_sqlite.db"
|
||||
SQL_FILE=""
|
||||
|
||||
usage () {
|
||||
echo "USAGE: $0 [--db-file sqlite db file] [--sql-file sql file path to run]"
|
||||
echo " [-d|--db-file sqlite db file path] default: ${DEFAULT_DB_FILE}"
|
||||
echo " [-f|--sql-file sqlte file to run] default: ${DEFAULT_SQL_FILE}"
|
||||
echo " [-h|--help] Usage message"
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case $key in
|
||||
-d|--db-file)
|
||||
DB_FILE="$2"
|
||||
shift # past argument
|
||||
shift # past value
|
||||
;;
|
||||
-f|--sql-file)
|
||||
SQL_FILE="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
help="true"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $help ]]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -n $SQL_FILE ];then
|
||||
mkdir -p $WORK_DIR/pilot/data
|
||||
for file in $WORK_DIR/docker/examples/sqls/*_sqlite.sql
|
||||
do
|
||||
echo "execute sql file: $file"
|
||||
sqlite3 $DB_FILE < "$file"
|
||||
done
|
||||
|
||||
else
|
||||
echo "Execute SQL file ${SQL_FILE}"
|
||||
sqlite3 $DB_FILE < $SQL_FILE
|
||||
fi
|
||||
|
||||
|
Reference in New Issue
Block a user