Lightweight 0.20260617.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) 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().
 
template<typename Self >
LIGHTWEIGHT_FORCE_INLINE auto && Varying (this Self &&self) noexcept
 State-preserving override; see Distinct.
 
- Public Member Functions inherited from Lightweight::SqlSelectQueryBuilder
 SqlSelectQueryBuilder (SqlQueryFormatter const &formatter, std::string table, std::string tableAlias) noexcept
 Constructs a SELECT query builder.
 
constexpr LIGHTWEIGHT_FORCE_INLINE SqlSelectQueryBuilderVarying () noexcept
 Sets the builder mode to Varying, allowing varying final query types.
 
template<typename... MoreFields>
SqlSelectQueryBuilderFields (std::string_view const &firstField, MoreFields &&... moreFields)
 Adds a sequence of columns to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilderField (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 SqlSelectQueryBuilderField (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 SqlSelectQueryBuilderField (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 SqlSelectQueryBuilderAs (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 SqlSelectQueryBuilderFields (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 SqlSelectQueryBuilderFields (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 SqlSelectQueryBuilderFields (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 SqlSelectQueryBuilderFields (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 SqlSelectQueryBuilderFields (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>
SqlSelectQueryBuilderFields ()
 Adds a sequence of columns from the given tables to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilderFieldAs (std::string_view const &fieldName, std::string_view const &alias)
 Adds a single column with an alias to the SELECT clause.
 
LIGHTWEIGHT_API SqlSelectQueryBuilderFieldAs (SqlQualifiedTableColumnName const &fieldName, std::string_view const &alias)
 Adds a single column with an alias to the SELECT clause.
 
template<typename Callable >
SqlSelectQueryBuilderBuild (Callable const &callable)
 Builds the query using a callable.
 
LIGHTWEIGHT_API ComposedQuery Count ()
 Finalizes building the query as SELECT COUNT(*) ... query.
 
LIGHTWEIGHT_API ComposedQuery Count () const
 Finalizes building the query as SELECT COUNT(*) ... query.
 
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 SqlSelectQueryBuilderBuild (Callable const &callable)
 Builds the query using a callable.
 
template<typename FirstRecord , typename... MoreRecords>
LIGHTWEIGHT_FORCE_INLINE SqlSelectQueryBuilderFields ()
 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 and Varying are overridden via deducing this so they return Self&& and the starter identity survives them. 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 373 of file Select.hpp.

Constructor & Destructor Documentation

◆ SqlSelectQueryStarter()

Lightweight::SqlSelectQueryStarter::SqlSelectQueryStarter ( SqlQueryFormatter const &  formatter,
std::string  table,
std::string  tableAlias 
)
inlinenoexcept

Constructs a SELECT query starter.

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

Definition at line 380 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 392 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 404 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 416 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 431 of file Select.hpp.

◆ Varying()

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

State-preserving override; see Distinct.

Definition at line 439 of file Select.hpp.


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