gomog/test_persist.sh

30 lines
982 B
Bash
Executable File

#!/bin/bash
echo "=== 启动服务器 ==="
rm -f gomog.db
./bin/gomog -config config.yaml &
SERVER_PID=$!
sleep 3
echo -e "\n=== 插入数据 ==="
curl -s -X POST http://localhost:8080/api/v1/testdb/users/insert \
-H "Content-Type: application/json" \
-d '{"documents": [{"name": "Alice", "age": 30}]}'
echo -e "\n\n=== 等待 5 秒让异步持久化完成 ==="
sleep 5
echo -e "\n=== 查询内存中的数据 ==="
curl -s -X POST http://localhost:8080/api/v1/testdb/users/find \
-H "Content-Type: application/json" \
-d '{}' | python3 -c "import sys,json; d=json.load(sys.stdin); print(f'内存中有 {len(d.get(\"cursor\",{}).get(\"firstBatch\",[]))} 条数据')"
echo -e "\n=== 检查数据库表 ==="
sqlite3 gomog.db ".tables" 2>/dev/null || echo "无表"
echo -e "\n=== 检查数据库数据 ==="
sqlite3 gomog.db "SELECT COUNT(*) FROM 'testdb.users';" 2>/dev/null || echo "无法查询"
echo -e "\n=== 停止服务器 ==="
kill $SERVER_PID 2>/dev/null || true