github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/3rd_party/fflib/include/ff/sql/table_create.h (about)

     1  /***********************************************
     2    The MIT License (MIT)
     3  
     4    Copyright (c) 2012 Athrun Arthur <athrunarthur@gmail.com>
     5  
     6    Permission is hereby granted, free of charge, to any person obtaining a copy
     7    of this software and associated documentation files (the "Software"), to deal
     8    in the Software without restriction, including without limitation the rights
     9    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    10    copies of the Software, and to permit persons to whom the Software is
    11    furnished to do so, subject to the following conditions:
    12  
    13    The above copyright notice and this permission notice shall be included in
    14    all copies or substantial portions of the Software.
    15  
    16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    17    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    18    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    19    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    20    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    21    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    22    THE SOFTWARE.
    23   *************************************************/
    24  #pragma once
    25  #include "ff/sql/columns.h"
    26  #include "ff/sql/common.h"
    27  #include <sstream>
    28  
    29  namespace ff {
    30  namespace sql {
    31  namespace internal {
    32  
    33  template <typename T> struct dump_col_type_creation {
    34    static void dump(std::stringstream &ss) { ss << " BLOB "; }
    35  };
    36  
    37  #define impl_table_dump_types(cpptype, sqltype)                                \
    38    template <> struct dump_col_type_creation<cpptype> {                         \
    39      static void dump(std::stringstream &ss) { ss << " " << sqltype << " "; }   \
    40    }
    41  impl_table_dump_types(uint64_t, "BIGINT UNSIGNED");
    42  impl_table_dump_types(int64_t, "BIGINT");
    43  impl_table_dump_types(uint32_t, "INT UNSIGNED");
    44  impl_table_dump_types(int32_t, "INT");
    45  impl_table_dump_types(int16_t, "SMALLINT");
    46  impl_table_dump_types(uint16_t, "SMALLINT UNSIGNED");
    47  impl_table_dump_types(int8_t, "TINYINT");
    48  impl_table_dump_types(uint8_t, "TINYINT UNSIGNED");
    49  impl_table_dump_types(float, "FLOAT");
    50  impl_table_dump_types(double, "DOUBLE");
    51  impl_table_dump_types(std::string, "VARCHAR(20)");
    52  
    53  //////////////////////////
    54  } // namespace internal
    55  
    56  enum {
    57    key_type,
    58    index_type,
    59    column_type,
    60  };
    61  template <typename T> struct extract_col_type {
    62    typedef typename T::type ct;
    63    const static int value = std::conditional<
    64        std::is_base_of<key<ct>, T>::value, util::int_number_type<key_type>,
    65        typename std::conditional<std::is_base_of<index<ct>, T>::value,
    66                                  util::int_number_type<index_type>,
    67                                  util::int_number_type<column_type>>::type>::
    68        type::value;
    69  };
    70  template <typename T, int V = extract_col_type<T>::value>
    71  struct dump_col_creation {};
    72  
    73  template <typename T> struct dump_col_creation<T, key_type> {
    74    static void dump(std::stringstream &ss) {
    75      ss << T::name;
    76      internal::dump_col_type_creation<typename T::type>::dump(ss);
    77      ss << " primary key";
    78    }
    79  };
    80  
    81  template <typename T> struct dump_col_creation<T, index_type> {
    82    static void dump(std::stringstream &ss) {
    83      ss << T::name;
    84      internal::dump_col_type_creation<typename T::type>::dump(ss);
    85    }
    86  };
    87  template <typename T> struct dump_col_creation<T, column_type> {
    88    static void dump(std::stringstream &ss) {
    89      ss << T::name;
    90      internal::dump_col_type_creation<typename T::type>::dump(ss);
    91    }
    92  };
    93  } // namespace sql
    94  } // namespace ff