module Clear::SQL::Query::CTE

Overview

Allow usage of Common Table Expressions (CTE) in the query building

Direct including types

Defined in:

clear/sql/query/cte.cr

Instance Method Summary

Instance Method Detail

def cte : Hash(String, Clear::SQL::Query::CTE::Record) #

List the current CTE of the query. The key is the name of the CTE, while the value is the fragment (string or Sub-select)


[View source]
def with_cte(name, request : CTEAuthorized, recursive = false) #

Add a CTE to the query.

Clear::SQL.select.with_cte("full_year",
  "SELECT DATE(date)"
  "FROM generate_series(NOW() - INTERVAL '1 year', NOW(), '1 day'::interval) date")
  .select("*").from("full_year")
# WITH full_year AS ( SELECT DATE(date) ... ) SELECT * FROM full_year;

[View source]
def with_cte(tuple : NamedTuple) #

Add a CTE to the query. Use NamedTuple convention:

Clear::SQL.select.with_cte(cte: "xxx")
# WITH cte AS xxx SELECT...

[View source]
def with_recursive_cte(tuple : NamedTuple) #

Add a CTE to the query. Use NamedTuple convention:

Clear::SQL.select.with_recursive_cte(cte: "xxx")
# WITH RECURSIVE cte AS xxx SELECT...

[View source]