~singpolyma/biboumi

biboumi/src/database/save.hpp -rw-r--r-- 827 bytes
12223354Stephen Paul Weber Fix caps hash 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once

#include <database/update_query.hpp>
#include <database/insert_query.hpp>

#include <database/engine.hpp>

#include <database/row.hpp>

#include <utils/is_one_of.hpp>

template <typename... T, bool Coucou=true>
void save(Row<T...>& row, DatabaseEngine& db, typename std::enable_if<!is_one_of<Id, T...> && Coucou>::type* = nullptr)
{
  insert(row, db);
}

template <typename... T, bool Coucou=true>
void save(Row<T...>& row, DatabaseEngine& db, typename std::enable_if<is_one_of<Id, T...> && Coucou>::type* = nullptr)
{
  const Id& id = std::get<Id>(row.columns);
    if (id.value == Id::unset_value)
      {
        insert(row, db);
        if (db.last_inserted_rowid >= 0)
          std::get<Id>(row.columns).value = static_cast<Id::real_type>(db.last_inserted_rowid);
      }
    else
      update(row, db);
}