Skip to content

Instantly share code, notes, and snippets.

@lynaghk
Last active April 5, 2025 10:19
Show Gist options
  • Save lynaghk/7b0747f86efe2756908144f503cd4834 to your computer and use it in GitHub Desktop.
Save lynaghk/7b0747f86efe2756908144f503cd4834 to your computer and use it in GitHub Desktop.
download jlcpcb stock into a sqlite database for easy local viewing via DB Browser for SQLite.
#!/usr/bin/env bash
set -euo pipefail
DB_FILE=$(ls *.db 2>/dev/null | grep "JLCPCB" | head -n 1 || echo "")
if [ -n "$DB_FILE" ]; then
echo "Already downloaded, exiting: $DB_FILE"
exit 0
fi
echo "Downloading JLCPCB parts database..."
DOWNLOAD_URL="https://cdfer.github.io/jlcpcb-parts-database/jlcpcb-components.sqlite3"
CURRENT_DATE=$(date +"%Y_%m_%d")
OUTPUT_FILE="JLCPCB_${CURRENT_DATE}.db"
curl -L -o "$OUTPUT_FILE" "$DOWNLOAD_URL"
echo "Creating optimized table for easier querying..."
sqlite3 "$OUTPUT_FILE" <<EOF
DROP TABLE IF EXISTS aaa;
CREATE TABLE aaa AS
SELECT lcsc, basic, stock, ROUND(json_extract(price, '\$[0].price'), 3) AS price, mfr, category, subcategory, joints, description, datasheet
FROM components
INNER JOIN categories ON components.category_id = categories.id
EOF
echo "Database processing complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment