blob: 7c71b2410f4dd64b2a3b415433479b0cda0a7978 (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// file : odb/mysql/sql-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/mysql/common.hxx>
#include <odb/mysql/schema.hxx>
#include <odb/mysql/sql-schema.hxx>
using namespace std;
namespace mysql
{
namespace
{
struct schema_emitter: emitter, context
{
schema_emitter (context& c): context (c) {}
virtual void
pre ()
{
first_ = true;
}
virtual void
line (const std::string& l)
{
if (first_)
first_ = false;
else
os << endl;
os << l;
}
virtual void
post ()
{
os << ';' << endl
<< endl;
}
private:
bool first_;
};
static char const file_header[] =
"/* This file was generated by ODB, object-relational mapping (ORM)\n"
" * compiler for C++.\n"
" */\n\n";
}
void
generate_schema (context& ctx)
{
ctx.os << file_header;
schema_emitter emitter (ctx);
// Drop.
//
{
traversal::unit unit;
traversal::defines unit_defines;
traversal::namespace_ ns;
class_drop c (ctx, emitter);
unit >> unit_defines >> ns;
unit_defines >> c;
traversal::defines ns_defines;
ns >> ns_defines >> ns;
ns_defines >> c;
unit.dispatch (ctx.unit);
}
ctx.os << endl;
// Create.
//
{
traversal::unit unit;
traversal::defines unit_defines;
traversal::namespace_ ns;
class_create c (ctx, emitter);
unit >> unit_defines >> ns;
unit_defines >> c;
traversal::defines ns_defines;
ns >> ns_defines >> ns;
ns_defines >> c;
unit.dispatch (ctx.unit);
}
}
}
|