SQT
A C++ ORM framework for SQLite
Loading...
Searching...
No Matches
sqt::PredicateType Concept Reference

#include <sqt/orm/expression/predicate_type.h>

Description

Constrains a type to be a predicate type.

Requirements

Predicates are binary expressions that return a boolean, including comparison expressions and logical expressions. They are used in WHERE decorators of queriers to apply conditions to the SQL statement.

A predicate consists of an operator (specified by the sqt::PredicateOperator enum) and two operands (which must satisfy the sqt::PredicateTermType concept). Operands can also be a predicate, allowing to build a tree structure of predicates.

To create predicates, use the comparison operators (==, !=, <, <=, >, >=) on identifiers (including columns, primary keys and indexes), or logical operators (&&, ||) on other predicates. Consider the following entity type and its table definition:

struct MyEntity {
int id{};
std::string name;
};
SQT_TABLE_BEGIN(MyEntity, MyEntity)
SQT_COLUMN_FIELD(name, name)
SQT_INDEX(id, name)
#define SQT_COLUMN_FIELD(COLUMN_NAME, FIELD)
Defines a column that binds to the specified field of the entity type.
Definition table_definition.h:273
#define SQT_PRIMARY_KEY(...)
Defines a primary key with the specified columns.
Definition table_definition.h:608
#define SQT_TABLE_BEGIN(TABLE_NAME, ENTITY_TYPE)
Begins the definition of a table type for the specified entity type.
Definition table_definition.h:141
#define SQT_TABLE_END
Ends the definition of a table type.
Definition table_definition.h:854
#define SQT_INDEX(...)
Defines an index with auto-generated names based on the specified columns.
Definition table_definition.h:733

Examples of creating selecters with predicates:

// Selects entities where the name is not "Unknown".
sqt::Table<MyEntity>.name != "Unknown"
);
// Selects the entity with the primary key.
);
// Selects the entity with the index.
sqt::Table<MyEntity>.Index_id_name == std::make_tuple(100, "Unknown")
);
// Selects entities with multiple conditions.
sqt::Table<MyEntity>.id < 100 && sqt::Table<MyEntity>.name != "Unknown"
);
static constexpr auto MakeSelecter() noexcept
Creates a selecter for retrieving entities from the database table.
Definition data_context.h:520
Represents a primary key for a table, which is a composite of one or more columns.
Definition primary_key.h:29
constexpr const auto & Table
A helper template to retrieve the singleton instance of the table type associated with an entity type...
Definition table_mapping.h:64
See also
sqt::ExpressionLike
sqt::PredicateOperator
sqt::PredicateTermType