The Challenge of Dynamic Queries
Working with user-provided filtering in Go applications presents several challenges:
- Dynamically building SQL queries based on user input
- Preventing SQL injection while handling user filters
- Creating an approachable query interface for various users
- Validating input against defined schemas
- Maintaining consistency between database queries and in-memory filtering
How DumbQL Works
DumbQL implements a straightforward query syntax that’s converted to SQL or used for in-memory filtering:
status:pending and period_months < 4 and (title:"hello world" or name:"John Doe")
Core Functionality
Query Syntax
DumbQL supports various expressions:
- Field expressions:
age >= 18,name:"John" - Boolean expressions:
verified and premium - One-of expressions:
status:[active, pending] - Boolean field shorthand:
is_active(equivalent tois_active:true)
Schema Validation
DumbQL includes built-in schema validation:
schm := schema.Schema{
"status": schema.Field{
"type": "string",
"enum": []string{"pending", "approved", "rejected"},
},
"period_months": schema.Field{
"type": "int64",
"min": 1,
"max": 12,
},
"title": schema.Field{
"type": "string",
"min": 1,
"max": 100,
},
}
Implementation Contexts
DumbQL can be useful in several scenarios:
- Admin interfaces with filtering capabilities
- API endpoints with query parameters for filtering
- Condition-based alerts or notifications
- Report generation with user-defined filters
- Search functionality with complex conditions
Usage Basics
To use DumbQL in your project:
go get go.tomakado.io/dumbql
Performance Considerations
For struct matching, DumbQL provides two options:
- Reflection-based matching (works immediately but has runtime overhead)
- Code generation via the
dumbqlgentool (eliminates reflection overhead)
Conclusion
DumbQL provides a lightweight query language for Go applications that can simplify filtering logic. It bridges the gap between user-friendly query syntax and database operations while offering features like schema validation and struct matching.
FAQs
Q: What is DumbQL?
A: DumbQL is a lightweight query language for Go applications that simplifies filtering logic.
Q: How does DumbQL work?
A: DumbQL implements a straightforward query syntax that’s converted to SQL or used for in-memory filtering.
Q: What are the benefits of using DumbQL?
A: DumbQL simplifies filtering logic, provides schema validation, and eliminates SQL injection risks.
Q: How do I get started with DumbQL?
A: You can get started with DumbQL by installing the package using go get go.tomakado.io/dumbql.

