Lightweight 0.20260921.0
Loading...
Searching...
No Matches
Lightweight::SqlSelectQueryStarter Class Referencefinal

Compile-time gate for SELECT query construction. More...

#include <Select.hpp>

Inheritance diagram for Lightweight::SqlSelectQueryStarter:
Lightweight::SqlSelectQueryBuilder

Public Member Functions

 SqlSelectQueryStarter (SqlQueryFormatter const &formatter, std::string table, std::string tableAlias, std::vector< SqlVariant > *inputBindings=nullptr) noexcept
 Constructs a SELECT query starter.
 
template<typename Self >
auto All (this Self const &self) -> ComposedQuery
 Empty-projection guard for the All finalizer.
 
template<typename Self >
auto First (this Self const &self, size_t count=1) -> ComposedQuery
 Empty-projection guard for the First finalizer — see All.
 
template<typename Self >
auto Range (this Self const &self, std::size_t offset, std::size_t limit) -> ComposedQuery
 Empty-projection guard for the Range finalizer — see All.
 
template<typename Self >
LIGHTWEIGHT_FORCE_INLINE auto && Distinct (this Self &&self) noexcept
 State-preserving override: returns Self&&, so the starter identity survives the call and the All / First / Range guards above keep their gate against Select().Distinct().All().
 
- Public Member Functions inherited from Lightweight::SqlSelectQueryBuilder
 SqlSelectQueryBuilder (SqlQueryFormatter const &formatter, std::string table, std::string tableAlias, std::vector< SqlVariant > *inputBindings=nullptr) noexcept
 
template<typename... MoreFields>
SqlSelectQueryBuilder & Fields (std::string_view const &firstField, MoreFields &&... moreFields)
 Adds a sequence of columns to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & Field (std::string_view const &fieldName)
 Adds a single column to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & Field (std::string_view const &fieldName) const
 Adds a single column to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & Field (SqlQualifiedTableColumnName const &fieldName)
 Adds a single column to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & Field (SqlQualifiedTableColumnName const &fieldName) const
 Adds a single column to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & Field (SqlFieldExpression const &fieldExpression)
 Adds an aggregate function call to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & Field (SqlFieldExpression const &fieldExpression) const
 Adds an aggregate function call to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & As (std::string_view alias)
 Aliases the last added field (a column or an aggregate call) in the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & As (std::string_view alias) const
 Aliases the last added field (a column or an aggregate call) in the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & Fields (std::vector< std::string_view > const &fieldNames)
 Adds a sequence of columns to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & Fields (std::vector< std::string_view > const &fieldNames) const
 Adds a sequence of columns to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & Fields (std::vector< std::string_view > const &fieldNames, std::string_view tableName)
 Adds a sequence of columns from the given table to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & Fields (std::vector< std::string_view > const &fieldNames, std::string_view tableName) const
 Adds a sequence of columns from the given table to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & Fields (std::initializer_list< std::string_view > const &fieldNames, std::string_view tableName)
 Adds a sequence of columns from the given table to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & Fields (std::initializer_list< std::string_view > const &fieldNames, std::string_view tableName) const
 Adds a sequence of columns from the given table to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & Fields (std::span< SqlQualifiedTableColumnName const > fieldNames)
 Adds a sequence of qualified table column names to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & Fields (std::span< SqlQualifiedTableColumnName const > fieldNames) const
 Adds a sequence of qualified table column names to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & Fields (std::initializer_list< SqlQualifiedTableColumnName const > fieldNames)
 Adds a sequence of qualified table column names to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder const & Fields (std::initializer_list< SqlQualifiedTableColumnName const > fieldNames) const
 Adds a sequence of qualified table column names to the SELECT clause.
 
template<typename FirstRecord , typename... MoreRecords>
SqlSelectQueryBuilder & Fields ()
 Adds a sequence of columns from the given tables to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & FieldAs (std::string_view const &fieldName, std::string_view const &alias)
 Adds a single column with an alias to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilder & FieldAs (SqlQualifiedTableColumnName const &fieldName, std::string_view const &alias)
 Adds a single column with an alias to the SELECT clause.
 
template<typename Callable >
SqlSelectQueryBuilder & Build (Callable const &callable)
 Builds the query using a callable.
 
LIGHTWEIGHT_API ComposedQuery Count ()
 
LIGHTWEIGHT_API ComposedQuery Count () const
 
LIGHTWEIGHT_API ComposedQuery All ()
 Finalizes building the query as SELECT field names FROM ... query.
 
LIGHTWEIGHT_API ComposedQuery All () const
 Finalizes building the query as SELECT field names FROM ... query.
 
LIGHTWEIGHT_API ComposedQuery First (size_t count=1)
 Finalizes building the query as SELECT TOP n field names FROM ... query.
 
LIGHTWEIGHT_API ComposedQuery First (size_t count=1) const
 Finalizes building the query as SELECT TOP n field names FROM ... query.
 
LIGHTWEIGHT_API ComposedQuery Range (std::size_t offset, std::size_t limit)
 Finalizes building the query as SELECT field names FROM ... query with a range.
 
LIGHTWEIGHT_API ComposedQuery Range (std::size_t offset, std::size_t limit) const
 Finalizes building the query as SELECT field names FROM ... query with a range.
 
LIGHTWEIGHT_FORCE_INLINE SqlSearchCondition & SearchCondition () noexcept
 Returns the search condition for the query.
 
LIGHTWEIGHT_FORCE_INLINE SqlQueryFormatter const & Formatter () const noexcept
 Returns the SQL query formatter.
 
template<typename Callable >
LIGHTWEIGHT_FORCE_INLINE SqlSelectQueryBuilder & Build (Callable const &callable)
 Builds the query using a callable.
 
template<typename FirstRecord , typename... MoreRecords>
LIGHTWEIGHT_FORCE_INLINE SqlSelectQueryBuilder & Fields ()
 Adds fields from one or more record types to the SELECT clause.
 

Additional Inherited Members

- Public Types inherited from Lightweight::SqlSelectQueryBuilder
using SelectType = detail::SelectType
 The select query type alias.
 

Detailed Description

Compile-time gate for SELECT query construction.

Returned by SqlQueryBuilder::Select(). The starter inherits publicly from SqlSelectQueryBuilder (so every projection / WHERE / JOIN method resolves directly through inheritance), but defines its own All, First, and Range as deducing-this member templates whose bodies are ill-formed via static_assert. Those locals shadow the corresponding base methods at name lookup, so:

  • Select().All(), Select().First(), Select().Range(...) — and the two-step variant auto q = Select(); q.All(); — fail at compile time with a diagnostic asking the user to add a projection first. Without a projection these would emit malformed SELECT FROM "T" SQL.
  • Select().Field(...).All() compiles: Field(...) is inherited and returns SqlSelectQueryBuilder&, so the subsequent All() resolves against the base type (no shadowing) and reaches the real finalizer.
  • Count is intentionally not overridden — SELECT COUNT(*) FROM ... is well-formed without an explicit column list, so the inherited Count remains directly callable.
  • Distinct is overridden via deducing this so it returns Self&& and the starter identity survives it. That keeps the gate intact for Select().Distinct().All() while still allowing Select().Distinct().Fields(...).All().

Methods that conceptually follow the column list (Where, OrderBy, GroupBy, InnerJoin, LeftOuterJoin, etc.) are reachable on the starter through public inheritance and return SqlSelectQueryBuilder&, which technically lets Select().WhereNotNull("x").All() compile (a known gate leak the type primarily defends against the empty-Select().All() typo, which is far more common).

For the imperative loop pattern, capture the first projection as a builder reference and continue from there:

auto starter = qb.Select();
auto& query = starter.Field(columns[0].name);
for (size_t i = 1; i < columns.size(); ++i)
query.Field(columns[i].name);
return query.All();

Definition at line 406 of file Select.hpp.

Constructor & Destructor Documentation

◆ SqlSelectQueryStarter()

Lightweight::SqlSelectQueryStarter::SqlSelectQueryStarter ( SqlQueryFormatter const &  formatter,
std::string  table,
std::string  tableAlias,
std::vector< SqlVariant > *  inputBindings = nullptr 
)
inlinenoexcept

Constructs a SELECT query starter.

Intentionally not explicit so the factory in SqlQueryBuilder::Select can return via braced init.

Constructs a SELECT query builder.

Parameters
formatterDialect the query is written in.
tableTable to select from.
tableAliasAlias for that table, empty for none.
inputBindingsReceives the WHERE values as bound parameters instead of having them written into the query text; null keeps them inline. Values are appended, never cleared. Execute the result with SqlStatement::ExecuteWithVariants(), not ExecuteDirect(), which would leave the markers unbound. Both the vector and anything a stored std::string_view / std::u16string_view points at must outlive the execution, because the binder hands the driver that pointer directly.
Note
An explicit SqlWildcard emits its marker without recording a value here, and a WhereIn() set larger than SqlMaxBoundSetSize falls back to inline literals; either makes the marker count differ from the vector size. A finalizer (All(), First(), Count(), Range()) moves the query out of the builder, so keep building only until the first one: a Where() issued afterwards still appends here while its marker is gone.

Definition at line 415 of file Select.hpp.

Member Function Documentation

◆ All()

template<typename Self >
auto Lightweight::SqlSelectQueryStarter::All ( this Self const &  self) -> ComposedQuery
inline

Empty-projection guard for the All finalizer.

Instantiating this template emits a static_assert telling the caller to add a projection first. Calling All() on a SqlSelectQueryBuilder& returned by Field(...) / Fields(...) bypasses the shadow and reaches the real SqlSelectQueryBuilder::All().

Definition at line 430 of file Select.hpp.

◆ First()

template<typename Self >
auto Lightweight::SqlSelectQueryStarter::First ( this Self const &  self,
size_t  count = 1 
) -> ComposedQuery
inline

Empty-projection guard for the First finalizer — see All.

Definition at line 442 of file Select.hpp.

◆ Range()

template<typename Self >
auto Lightweight::SqlSelectQueryStarter::Range ( this Self const &  self,
std::size_t  offset,
std::size_t  limit 
) -> ComposedQuery
inline

Empty-projection guard for the Range finalizer — see All.

Definition at line 454 of file Select.hpp.

◆ Distinct()

template<typename Self >
LIGHTWEIGHT_FORCE_INLINE auto && Lightweight::SqlSelectQueryStarter::Distinct ( this Self &&  self)
inlinenoexcept

State-preserving override: returns Self&&, so the starter identity survives the call and the All / First / Range guards above keep their gate against Select().Distinct().All().

Definition at line 469 of file Select.hpp.


The documentation for this class was generated from the following file: