wrangler D1 use
2025-09-27
- in the project directory
check table schema “users”
npx wrangler d1 execute note_book_db --env production --remote --command="PRAGMA table_info(users);"
check table “user”
npx wrangler d1 execute note_book_db --env production --remote --command="SELECT id, email, api_key FROM users;"
delete table “users”
npx wrangler d1 execute note_book_db --env production --remote --command="DELETE FROM users;"
delete the user “zhurx09@gmail.com” from the user list
npx wrangler d1 execute note_book_db --env production --remote --command="DELETE FROM users WHERE email = 'zhurx09@gmail.com';"
check all table
npx wrangler d1 execute note_book_db --env production --remote --command="SELECT name FROM sqlite_master WHERE type='table';"
Check indexes
npx wrangler d1 execute note_book_db --env production --remote --command="SELECT name FROM sqlite_master WHERE type='index'"
drop single table
npx wrangler d1 execute note_book_db --env production --remote --command="DROP TABLE IF EXISTS notes_zhurx09_at_gmail_com;"
Integration
npx wrangler d1 execute note_book_db --env production --remote --command="DELETE FROM users WHERE email = 'zhurx09@gmail.com'; DROP TABLE IF EXISTS notes_zhurx09_at_gmail_com;"
drop all starting “notes_” with table
- first extract
npx wrangler d1 execute note_book_db --env production --remote \ --command="SELECT 'DROP TABLE IF EXISTS ' || name || ';' FROM sqlite_master WHERE type='table' AND name LIKE 'notes_%';" --json > 1.json - Use the command to read 1.json operation
grep -o '"DROP TABLE IF EXISTS[^"]*"' 1.json | sed 's/"//g' > drop_notes.sql - Run directly against D1
npx wrangler d1 execute note_book_db --env production --remote --file=drop_notes.sql
query table content “frontend_notes”
npx wrangler d1 execute note_book_db --env production --remote --command="SELECT * FROM frontend_notes;"
view background loggind
npx wrangler tail --env production --format=pretty