Skip to content

Latest commit

 

History

History
146 lines (118 loc) · 2.25 KB

File metadata and controls

146 lines (118 loc) · 2.25 KB

< Differences

Before and after: Dynamic queries

SELECT

sqlpp11sqlpp23

Dynamically selected column

auto s = dynamic_select(db, tab.id)
             .from(tab)
             .unconditionally();
if (maybe) {
  s.selected_columns.add(tab.int_value);
}
for (const auto& row : db(s)) {
  const int64_t id = row.id;
  const std::string need_to_parse =
      row.at("int_value");
}
for (const auto& row :
     db(select(tab.id,
               dynamic(maybe, tab.int_value))
            .from(tab))) {
  const int64_t id = row.id;
  const int64_t = row.int_value;
}

Dynamic conditions

Conditions can be used in where, having, for instance. The tables here use where as an example.

sqlpp11sqlpp23

Dynamic AND

auto s = dynamic_select(db, tab.id)
             .from(tab)
             .dynamic_where(tab.lang == "c++");
if (maybe_23) {
  s.where.add(tab.version >= "23");
}
for (const auto& row : db(s)) {
  do_something(row.id);
}
for (const auto& row :
     db(select(tab.id).from(tab).where(
         tab.lang == "c++" and
         dynamic(maybe_23, tab_version >= 23)))) {
  do_something(row.id);
}

Dynamic OR

// Not supported.
for (const auto& row :
     db(select(tab.id).from(tab).where(
         tab.lang == "c++" or
         dynamic(maybe_23, tab_version >= 23)))) {
  do_something(row.id);
}

Nested dynamic

// Not supported.
for (const auto& row :
     db(select(tab.id).from(tab).where(
         tab.lang == "c++" and
         (tab.legacy == true or
          dynamic(maybe_23,
                  tab_version >= 23))))) {
  do_something(row.id);
}

< Differences