What is the Queryable trait?
mainThe Queryable trait is used for structs that represent the result of a database query.
Key concepts:
- Mapping: A
Queryablestruct must map exactly to the columns, values, and order specified in your SQL query. - Flexibility: You are not limited to one
Queryablestruct per table. You can create multiple structs for the same table if you only need a subset of columns (e.g., aUserstruct for full profiles and anEmailUserstruct for just IDs and emails). - Safety: If the columns returned by your query do not match the types and order of the fields in your
Queryablestruct, you will encounter a compile-time error.
Commonly used methods from RunQueryDsl with Queryable include:
load()get_result()get_results()first()