Overview
Thequery-db command provides tools for querying the TikTok Miner PostgreSQL database. It supports raw SQL queries for direct database access.
Command Syntax
Arguments
[sql]- Raw SQL query to execute directly against the database
Options
The query-db command accepts various options for structured queries:-u, --username <username>- Filter by username-r, --repo <repo>- Repository or profile identifier-j, --jd <id>- Job description or category ID-t, --tag <tag>- Filter by tag-l, --limit <number>- Limit number of results--repos- Include additional profile data--contributions- Include contribution metrics--contributors- Include contributor information
Database Schema
The TikTok Miner database uses PostgreSQL with Prisma ORM. Key tables include:Creator Profiles
Platform Metrics
Time-Series Data
Usage Examples
Raw SQL Query
Execute a direct SQL query against the database:Query TikTok Profiles
Get Engagement Analytics
Budget and Cost Tracking
Common Queries
Top Creators by Engagement
Platform Distribution
Recent Discoveries
Budget Status
Output Formats
The CLI supports different output formats for query results:- Table (default): Pretty-printed table with borders
- JSON: Machine-readable JSON output
- CSV: Comma-separated values for spreadsheets
Database Schema Reference
For complete schema documentation, see the Database Setup page which includes:- Full Prisma schema
- Table relationships
- Index definitions
- TimescaleDB hypertables
Related Documentation
Database Setup
Complete database schema and setup guide
API Monitoring
Monitor database queries and performance
Troubleshooting
Connection errors
Connection errors
Ensure your
DATABASE_URL environment variable is correctly set and the PostgreSQL server is running.Permission denied errors
Permission denied errors
The database user needs appropriate permissions. Check the user has SELECT, INSERT, UPDATE permissions on the required tables.
Query timeout
Query timeout
For large datasets, consider adding a
LIMIT clause or creating appropriate indexes. See the database setup guide for performance optimization tips.