summaryrefslogtreecommitdiff
path: root/odb/relational/mysql/schema.cxx
blob: 0b44c535415e02a302c46377dfc857e121651202 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// file      : odb/relational/mysql/schema.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license   : GNU GPL v3; see accompanying LICENSE file

#include <odb/relational/schema.hxx>

#include <odb/relational/mysql/common.hxx>
#include <odb/relational/mysql/context.hxx>

namespace relational
{
  namespace mysql
  {
    namespace schema
    {
      namespace relational = relational::schema;

      //
      // Create.
      //

      struct create_common: virtual relational::create_common
      {
        virtual void
        create_table_post ()
        {
          os << ")";

          string const& engine (options.mysql_engine ());

          if (engine != "default")
            os << endl
               << " ENGINE=" << engine;

          os << endl;
        }
      };

      struct object_columns: relational::object_columns
      {
        object_columns (base const& x): base (x) {}

        virtual void
        constraints (semantics::data_member& m)
        {
          base::constraints (m);

          if (m.count ("auto"))
            os << " AUTO_INCREMENT";
        }

      };
      entry<object_columns> object_columns_;

      struct member_create: relational::member_create, create_common
      {
        member_create (base const& x): base (x) {}
      };
      entry<member_create> member_create_;

      struct class_create: relational::class_create, create_common
      {
        class_create (base const& x): base (x) {}
      };
      entry<class_create> class_create_;
    }
  }
}