Query Guide
Learn how to search effectively with MygramDB.
WARNING
Before executing queries, ensure your IP is registered in allow_cidrs in the configuration. Without CIDR registration, all connections are denied. See Network Security.
Connecting with mygram-cli
bash
mygram-cli -h localhost -p 11016Once connected, you can execute queries interactively.
Basic Search
mygram> SEARCH articles hello world
OK RESULTS 3 101 205 387Boolean Operators
AND - All terms must match
mygram> SEARCH articles golang AND tutorialOR - Any term matches
mygram> SEARCH articles golang OR python OR rustNOT - Exclude terms
mygram> SEARCH articles tutorial NOT beginnerCombined
mygram> SEARCH articles (golang OR python) AND tutorial NOT beginnerPhrase Search
Use quotes for exact phrases:
mygram> SEARCH articles "machine learning"
mygram> SEARCH articles 'web framework'Combine with operators:
mygram> SEARCH articles "web framework" AND (golang OR python)Filtering
Filter by column values:
mygram> SEARCH articles tech FILTER status = 1
mygram> SEARCH articles tech FILTER views > 1000
mygram> SEARCH articles tech FILTER created_at >= 2024-01-01Multiple filters (AND logic):
mygram> SEARCH articles tech FILTER status = 1 FILTER category_id = 5Filter Operators
| Operator | Alias | Description |
|---|---|---|
= | EQ | Equal |
!= | NE | Not equal |
> | GT | Greater than |
>= | GTE | Greater or equal |
< | LT | Less than |
<= | LTE | Less or equal |
Sorting
Sort by primary key:
mygram> SEARCH articles golang SORT ASC
mygram> SEARCH articles golang SORT DESCSort by column:
mygram> SEARCH articles golang SORT created_at DESC
mygram> SEARCH articles golang SORT score ASCPagination
mygram> SEARCH articles golang LIMIT 10
mygram> SEARCH articles golang LIMIT 10 OFFSET 20Count Query
Get count without IDs:
mygram> COUNT articles golang AND tutorial
OK COUNT 42Complete Examples
Find recent Go tutorials
mygram> SEARCH articles golang AND tutorial FILTER status = 1 SORT created_at DESC LIMIT 20Find popular posts about databases
mygram> SEARCH posts (mysql OR postgresql) AND performance FILTER views > 1000 SORT score DESC LIMIT 10Count active users in category
mygram> COUNT users tech FILTER status = 1 FILTER category_id = 5HTTP API
All queries are also available via HTTP:
bash
curl "http://localhost:8080/search?table=articles&q=golang+tutorial&limit=10"bash
curl "http://localhost:8080/count?table=articles&q=golang"Operator Precedence
Without parentheses, operators are evaluated in this order:
- NOT (highest)
- AND
- OR (lowest)
Example: a OR b AND c is parsed as a OR (b AND c)
TIP
Use parentheses to make your intent clear and avoid unexpected results.
Performance Tips
- Use LIMIT - Enables faster partial sorting
- Add specific filters - Reduces result set early
- Use AND over OR - AND queries are typically faster
- Index filter columns - Configure frequently filtered columns in config
Next Steps
- Configuration - Configure filter columns
- Getting Started - Quick start guide