relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
query.hpp
Go to the documentation of this file.
1#pragma once
2
5#include "query/condition.hpp"
6#include "query/core.hpp"
7#include "query/date.hpp"
8#include "query/delete.hpp"
9#include "query/function.hpp"
10#include "query/helpers.hpp"
11#include "query/insert.hpp"
12#include "query/literals.hpp"
13#include "query/operators.hpp"
15#include "query/select.hpp"
16#include "query/update.hpp"
17#include "query/value.hpp"
18
114namespace relx {
115
116// Convenient imports from the query namespace
117using query::as;
118using query::asc;
119using query::avg;
120using query::case_;
121using query::coalesce;
122using query::count;
123using query::count_all;
126using query::desc;
127using query::distinct;
128using query::in;
130using query::like;
131using query::max;
132using query::min;
133using query::on;
134using query::select;
136using query::sum;
137using query::update;
138using query::val;
139
140// Date/time functions
141using query::abs;
146using query::date_add;
147using query::date_diff;
148using query::date_sub;
150using query::day;
155using query::extract;
156using query::hour;
157using query::interval;
158using query::minute;
159using query::month;
160using query::now;
161using query::second;
165using query::year;
166
167// User-defined literals
168using namespace query::literals; // Enables 42_sql, "string"_sql, etc.
169
170// ===== INTERNAL/ADVANCED API =====
171// These are implementation details that power users might need
172// Most users should not use these directly
173namespace detail {
174using query::to_expr;
175using query::to_table;
176} // namespace detail
177
178} // namespace relx
auto current_timestamp()
CURRENT_TIMESTAMP function - returns the current timestamp.
Definition date.hpp:546
auto start_of_day(const T &date_column)
Get the start of the day for a date.
Definition date.hpp:644
auto min(Expr expr)
MIN aggregate function.
Definition function.hpp:186
auto current_time()
CURRENT_TIME function - returns the current time.
Definition date.hpp:540
auto second(const T &date_column)
Get the second from a timestamp.
Definition date.hpp:772
auto age_in_years(const T &birth_date_column)
Calculate age in years between birth date and current date.
Definition date.hpp:564
auto like(Expr expr, std::string pattern)
Create a LIKE condition.
auto avg(Expr expr)
AVG aggregate function.
Definition function.hpp:166
auto hour(const T &date_column)
Get the hour from a timestamp.
Definition date.hpp:740
auto interval(std::string_view interval_str)
Create an interval expression.
Definition date.hpp:528
auto start_of_month(const T &date_column)
Get the start of the month for a date.
Definition date.hpp:628
auto asc(Expr expr)
Create an ascending order by expression.
Definition select.hpp:586
auto start_of_year(const T &date_column)
Get the start of the year for a date.
Definition date.hpp:612
auto year(const T &date_column)
Get the year from a date.
Definition date.hpp:660
auto in(const schema::column< TableT, Name, T, Modifiers... > &col, Range values)
Create an IN condition with type checking for columns.
auto month(const T &date_column)
Get the month from a date.
Definition date.hpp:676
auto day_of_year(const T &date_column)
Get the day of year from a date (1-366)
Definition date.hpp:724
auto extract(std::string_view unit, Expr expr)
EXTRACT function - extracts a date part from a date.
Definition date.hpp:497
auto day(const T &date_column)
Get the day from a date.
Definition date.hpp:692
auto max(Expr expr)
MAX aggregate function.
Definition function.hpp:206
auto date_add(DateExpr date_expr, IntervalExpr interval_expr)
DATE_ADD function - adds an interval to a date.
Definition date.hpp:460
auto sum(Expr expr)
SUM aggregate function.
Definition function.hpp:146
auto desc(Expr expr)
Create a descending order by expression.
Definition select.hpp:554
auto update(const Table &table)
Create an UPDATE query for the specified table.
Definition update.hpp:252
auto as(const Expr &expr, std::string alias)
Create an aliased column expression.
auto select_expr(const schema::column< TableT, Name, T, Modifiers... > &col, Args &&... args)
auto insert_into(const Table &table)
Create an INSERT query for the specified table.
Definition insert.hpp:330
auto minute(const T &date_column)
Get the minute from a timestamp.
Definition date.hpp:756
auto case_()
Create a CASE expression with type checking.
Definition function.hpp:654
auto current_date()
CURRENT_DATE function - returns the current date.
Definition date.hpp:534
auto to_expr(const C &col, std::string_view table_name="")
Helper to wrap a schema column in a SQL expression.
auto count_distinct(Expr expr)
COUNT(DISTINCT expr) aggregate function.
Definition function.hpp:97
auto count(Expr expr)
COUNT aggregate function.
Definition function.hpp:81
auto days_until(const T &date_column)
Calculate days until a date.
Definition date.hpp:596
auto date_trunc(std::string_view unit, Expr expr)
DATE_TRUNC function - truncates a date to specified precision.
Definition date.hpp:514
auto days_since(const T &date_column)
Calculate days since a date.
Definition date.hpp:580
auto select(const Args &... args)
Create a column reference from a member pointer without requiring a table instance.
Definition select.hpp:501
auto delete_from(const Table &table)
Create a DELETE query for the specified table.
Definition delete.hpp:99
auto date_diff(std::string_view unit, Expr1 date1, Expr2 date2)
DATE_DIFF function - calculates difference between two dates.
Definition date.hpp:428
auto coalesce(First first, Second second, Rest... rest)
Create a COALESCE expression.
Definition function.hpp:409
auto abs(Expr expr)
ABS function for SQL expressions.
Definition date.hpp:833
auto distinct(Expr expr)
Create a DISTINCT expression.
Definition function.hpp:259
auto day_of_week(const T &date_column)
Get the day of week from a date (0=Sunday, 1=Monday, etc.)
Definition date.hpp:708
auto val(const char *str)
Helper to create a value expression from a string literal.
Definition value.hpp:127
auto now()
NOW function - alias for CURRENT_TIMESTAMP.
Definition date.hpp:552
auto to_table(const T &table)
Helper to wrap a schema table in a table adapter.
auto count_all()
COUNT(*) aggregate function.
Definition function.hpp:72
auto on(Condition cond)
Create a join condition with the ON clause.
Definition select.hpp:43
auto date_sub(DateExpr date_expr, IntervalExpr interval_expr)
DATE_SUB function - subtracts an interval from a date.
Definition date.hpp:478
relx database connection