Skip to content

Commit 239c790

Browse files
committed
docs(internals/query_list): add usage context and lookup reference
why: Show how QueryList powers the Manager/Cmd pattern what: - Add overview explaining ls() returns QueryList - Document all available lookup operators - Show filter chaining examples
1 parent 5543321 commit 239c790

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

docs/internals/query_list.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,74 @@
11
# List querying - `libvcs._internal.query_list`
22

3+
`QueryList` is the backbone of the Manager/Cmd pattern. Every `ls()` method in
4+
libvcs returns a `QueryList`, enabling chainable filtering on the results.
5+
6+
## How It's Used
7+
8+
All Manager classes return `QueryList` from their `ls()` methods:
9+
10+
```python
11+
from libvcs.cmd.git import Git
12+
13+
git = Git(path='/path/to/repo')
14+
15+
# Each ls() returns a QueryList
16+
branches = git.branches.ls() # QueryList[GitBranchCmd]
17+
tags = git.tags.ls() # QueryList[GitTagCmd]
18+
remotes = git.remotes.ls() # QueryList[GitRemoteCmd]
19+
stashes = git.stashes.ls() # QueryList[GitStashEntryCmd]
20+
worktrees = git.worktrees.ls() # QueryList[GitWorktreeCmd]
21+
```
22+
23+
## Filtering
24+
25+
`QueryList` extends Python's built-in `list` with Django-style lookups:
26+
27+
```python
28+
# Exact match
29+
branches.filter(name='main')
30+
31+
# Case-insensitive contains
32+
branches.filter(name__icontains='feature')
33+
34+
# Nested attribute access
35+
branches.filter(commit__sha__startswith='abc123')
36+
```
37+
38+
### Available Lookups
39+
40+
| Lookup | Description |
41+
|--------|-------------|
42+
| `exact` | Exact match (default) |
43+
| `iexact` | Case-insensitive exact match |
44+
| `contains` | Substring match |
45+
| `icontains` | Case-insensitive substring |
46+
| `startswith` | Prefix match |
47+
| `istartswith` | Case-insensitive prefix |
48+
| `endswith` | Suffix match |
49+
| `iendswith` | Case-insensitive suffix |
50+
| `in` | Value in list |
51+
| `nin` | Value not in list |
52+
| `regex` | Regular expression match |
53+
| `iregex` | Case-insensitive regex |
54+
55+
### Chaining
56+
57+
Filters can be chained and combined:
58+
59+
```python
60+
# Multiple conditions (AND)
61+
branches.filter(name__startswith='feature', is_remote=False)
62+
63+
# Get single result
64+
branches.get(name='main')
65+
66+
# Chain filters
67+
branches.filter(is_remote=True).filter(name__contains='release')
68+
```
69+
70+
## API Reference
71+
372
```{eval-rst}
473
.. automodule:: libvcs._internal.query_list
574
:members:

0 commit comments

Comments
 (0)