@@ -60,6 +60,7 @@ Options:
6060 -o, --format <FORMAT> Output format (table, json, csv)
6161 -i, --interactive Start interactive SQL shell
6262 --verbose Show detailed error messages
63+ -b, --branch <BRANCH> Execute against specific branch or commit (SELECT queries only, requires clean status)
6364 -h, --help Print help
6465```
6566
@@ -109,6 +110,38 @@ In interactive mode:
109110- Type ` help ` for available commands
110111- Type ` exit ` or ` quit ` to leave the shell
111112
113+ ### 4. Historical Data Querying
114+
115+ Query data from specific branches or commits using the ` -b ` parameter:
116+
117+ ``` bash
118+ # Query data from main branch
119+ git prolly sql -b main " SELECT * FROM users"
120+
121+ # Query data from a specific commit
122+ git prolly sql -b a1b2c3d4 " SELECT COUNT(*) FROM products"
123+
124+ # Query data from a feature branch
125+ git prolly sql -b feature/new-schema " SELECT * FROM categories"
126+ ```
127+
128+ ** Important Requirements:**
129+ - Only ` SELECT ` statements are allowed when using ` -b ` parameter
130+ - Your working directory must have clean status (no uncommitted staging changes)
131+ - The branch/commit will be temporarily checked out and restored after execution
132+
133+ ** Example with staging changes:**
134+ ``` bash
135+ # This will be blocked if you have uncommitted changes
136+ git prolly set user:123 " John Doe" # Creates staging changes
137+ git prolly sql -b main " SELECT * FROM users"
138+ # Error: Cannot use -b/--branch parameter with uncommitted staging changes
139+
140+ # Commit your changes first
141+ git prolly commit -m " Add new user"
142+ git prolly sql -b main " SELECT * FROM users" # Now works
143+ ```
144+
112145## SQL Operations
113146
114147### Supported SQL Features
@@ -329,9 +362,66 @@ prolly-sql> exit
329362Goodbye!
330363```
331364
365+ ### Interactive Mode with Historical Data
366+
367+ Use interactive mode to explore historical data:
368+
369+ ``` bash
370+ # Start interactive mode against a specific branch
371+ git prolly sql -b feature/analytics -i
372+ ```
373+
374+ ```
375+ 🌟 ProllyTree SQL Interactive Shell
376+ ====================================
377+ Executing against branch/commit: feature/analytics
378+ ⚠️ Only SELECT statements are allowed in this mode
379+ Type 'exit' or 'quit' to exit
380+ Type 'help' for available commands
381+
382+ prolly-sql> SELECT COUNT(*) FROM new_analytics_table;
383+ │ COUNT(*) │
384+ ├──────────┤
385+ │ I64(150) │
386+
387+ prolly-sql> SELECT * FROM products WHERE price > 1000;
388+ │ id │ name │ price │
389+ ├────────┼─────────────────────┼───────────┤
390+ │ I64(1) │ Str("Gaming PC") │ I64(1500) │
391+ │ I64(2) │ Str("MacBook Pro") │ I64(2000) │
392+
393+ prolly-sql> INSERT INTO products VALUES (3, 'iPad', 800);
394+ Error: Only SELECT statements are allowed when using -b/--branch parameter
395+ Historical commits/branches are read-only for data integrity
396+
397+ prolly-sql> exit
398+ Goodbye!
399+ Restored to original branch: main
400+ ```
401+
332402## Advanced Examples
333403
334- ### 1. Complex Data Analysis
404+ ### 1. Historical Data Analysis
405+
406+ Compare data across different points in time:
407+
408+ ``` bash
409+ # Query current data
410+ git prolly sql " SELECT COUNT(*) as current_users FROM users"
411+
412+ # Query data from last week's commit
413+ git prolly sql -b 7d1a2b3c " SELECT COUNT(*) as users_last_week FROM users"
414+
415+ # Compare product prices between branches
416+ git prolly sql -b main " SELECT name, price FROM products WHERE category = 'Electronics'"
417+ git prolly sql -b feature/price-update " SELECT name, price FROM products WHERE category = 'Electronics'"
418+
419+ # Analyze data growth over time
420+ git prolly sql -b v1.0 " SELECT COUNT(*) as v1_orders FROM orders"
421+ git prolly sql -b v2.0 " SELECT COUNT(*) as v2_orders FROM orders"
422+ ```
423+
424+ ### 2. Complex Data Analysis
335425
336426``` sql
337427-- Create sales data
@@ -461,10 +551,34 @@ git checkout main
461551# The new tables don't exist on main branch
462552git prolly sql " SELECT * FROM categories" # Error: table not found
463553
554+ # Query the new schema without switching branches
555+ git prolly sql -b feature/new-schema " SELECT * FROM categories"
556+
464557# Merge when ready
465558git merge feature/new-schema
466559```
467560
561+ ### Cross-Branch Data Comparison
562+
563+ Compare data between branches without switching contexts:
564+
565+ ``` bash
566+ # Compare user counts between branches
567+ echo " Main branch users:"
568+ git prolly sql -b main " SELECT COUNT(*) FROM users"
569+
570+ echo " Feature branch users:"
571+ git prolly sql -b feature/user-management " SELECT COUNT(*) FROM users"
572+
573+ # Generate reports from different branches
574+ git prolly sql -b production -o json " SELECT * FROM daily_metrics WHERE date = '2024-01-15'" > prod_metrics.json
575+ git prolly sql -b staging -o json " SELECT * FROM daily_metrics WHERE date = '2024-01-15'" > staging_metrics.json
576+
577+ # Compare table schemas between versions
578+ git prolly sql -b v1.0 " SELECT name FROM sqlite_master WHERE type='table'"
579+ git prolly sql -b v2.0 " SELECT name FROM sqlite_master WHERE type='table'"
580+ ```
581+
468582## Best Practices
469583
470584### 1. Schema Design
@@ -497,6 +611,23 @@ git checkout -b migration-test
497611# If successful, merge to main
498612```
499613
614+ ### 5. Historical Data Querying
615+
616+ - ** Commit changes before using ` -b ` ** : Always commit your staging changes before querying historical data
617+ - ** Use for read-only analysis** : The ` -b ` parameter is perfect for generating reports without affecting current work
618+ - ** Branch-specific schemas** : Use ` -b ` to query data from branches with different table structures
619+ - ** Performance** : Historical queries access committed data, so they may be slower than current branch queries
620+
621+ ``` bash
622+ # Good practice: commit first
623+ git prolly commit -m " Save current work"
624+ git prolly sql -b production " SELECT * FROM metrics"
625+
626+ # Avoid: Don't leave uncommitted changes
627+ git prolly set user:new " data" # Uncommitted change
628+ git prolly sql -b main " SELECT * FROM users" # Will be blocked
629+ ```
630+
500631## Troubleshooting
501632
502633### Common Issues
@@ -515,6 +646,21 @@ git checkout -b migration-test
515646 - Check SQL syntax - the parser is strict about formatting
516647 - Ensure column names match exactly (case-sensitive)
517648
649+ 4 . ** "Cannot use -b/--branch parameter with uncommitted staging changes"**
650+ - Check staging status with ` git prolly status `
651+ - Commit your changes first: ` git prolly commit -m "Save changes" `
652+ - Or discard changes if not needed
653+
654+ 5 . ** "Only SELECT statements are allowed when using -b/--branch parameter"**
655+ - Historical data is read-only for safety
656+ - Use regular ` git prolly sql ` (without ` -b ` ) for data modifications
657+ - Switch to the target branch if you need to make changes there
658+
659+ 6 . ** "Failed to checkout branch/commit"**
660+ - Verify the branch/commit exists: ` git branch -a ` or ` git log --oneline `
661+ - Check branch name spelling (case-sensitive)
662+ - Ensure you have access to the specified commit
663+
518664### Performance Tips
519665
5206661 . ** Large Result Sets** : Use LIMIT to restrict output
0 commit comments