dm-metamapper 0.2.9 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -40,15 +40,15 @@ module DataMapper
|
|
40
40
|
|
41
41
|
def key_to_parent
|
42
42
|
many_to_one.inject({}) do |hash, (r,m)|
|
43
|
-
hash[m.child_key.first.name] = decolonize(m.parent_model_name)
|
43
|
+
hash[m.child_key.first.name] = decolonize(m.parent_model_name.to_const_string)
|
44
44
|
hash
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def child_key(child_model)
|
49
|
-
child_model.relationships.
|
49
|
+
child_model.relationships.select {|m|
|
50
50
|
m.class.name == 'DataMapper::Associations::ManyToOne::Relationship' && m.parent_model_name == model.name
|
51
|
-
}
|
51
|
+
}.first.child_key.first.name.to_s
|
52
52
|
end
|
53
53
|
|
54
54
|
def output_path(model, template)
|
@@ -64,30 +64,29 @@ module DataMapper
|
|
64
64
|
|
65
65
|
def many_to_one
|
66
66
|
return unless model
|
67
|
-
@many_to_one ||= model.relationships.select {|
|
67
|
+
@many_to_one ||= model.relationships.select {|m|
|
68
68
|
m.class.name == 'DataMapper::Associations::ManyToOne::Relationship'
|
69
69
|
}
|
70
|
-
|
71
70
|
#in case of ruby < 1.9
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
if Array === @many_to_one
|
72
|
+
temp = @many_to_one
|
73
|
+
@many_to_one = {}
|
74
|
+
temp.each{|t| @many_to_one[t.name] = t}
|
75
|
+
end
|
77
76
|
|
78
77
|
@many_to_one
|
79
78
|
end
|
80
79
|
def one_to_many
|
81
80
|
return unless model
|
82
|
-
@one_to_many ||= model.relationships.select {|
|
81
|
+
@one_to_many ||= model.relationships.select {|m|
|
83
82
|
m.class.name == 'DataMapper::Associations::OneToMany::Relationship'
|
84
83
|
}
|
85
84
|
#in case of ruby < 1.9
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
85
|
+
if Array === @one_to_many
|
86
|
+
temp = @one_to_many
|
87
|
+
@one_to_many = {}
|
88
|
+
temp.each{|t| @one_to_many[t.name] = t}
|
89
|
+
end
|
91
90
|
|
92
91
|
@one_to_many
|
93
92
|
end
|
@@ -162,6 +162,38 @@ public:
|
|
162
162
|
fields, rows);
|
163
163
|
}
|
164
164
|
|
165
|
+
bool insertDirtyFields(std::vector<O_<%= class_name %>>::const_iterator begin,
|
166
|
+
std::vector<O_<%= class_name %>>::const_iterator end)
|
167
|
+
{
|
168
|
+
if (begin == end)
|
169
|
+
return true;
|
170
|
+
FieldsToRows fields2Rows;
|
171
|
+
for (std::vector<O_<%= class_name %>>::const_iterator it = begin;
|
172
|
+
it != end; ++it)
|
173
|
+
{
|
174
|
+
std::vector<std::string> fields;
|
175
|
+
std::vector<std::string> row;
|
176
|
+
<%- model.generated_properties.each do |property| -%>
|
177
|
+
<% if property.name != model.serial.name %>
|
178
|
+
if (it->_f_<%= property.name %>._dirty){
|
179
|
+
fields.push_back(std::string("<%= property.name %>"));
|
180
|
+
row.push_back(toSQLString(it->_<%= property.name %>()));
|
181
|
+
}
|
182
|
+
<%- end -%>
|
183
|
+
<%- end -%>
|
184
|
+
fields2Rows[fields].push_back(row);
|
185
|
+
}
|
186
|
+
bool ret = true;
|
187
|
+
for (FieldsToRows::const_iterator it = fields2Rows.begin();
|
188
|
+
it != fields2Rows.end(); ++it)
|
189
|
+
{
|
190
|
+
ret = DBFace::instance()->insert("<%= model.storage_name %>",
|
191
|
+
it->first, it->second) && ret;
|
192
|
+
}
|
193
|
+
return ret;
|
194
|
+
}
|
195
|
+
|
196
|
+
|
165
197
|
Condition _constraint;
|
166
198
|
std::vector<std::string> _tables;
|
167
199
|
};
|
@@ -1,3 +1,4 @@
|
|
1
|
+
#include <boost/date_time/posix_time/posix_time.hpp>
|
1
2
|
#include "dmmm_dbface.h"
|
2
3
|
#include "dmmm_utils.hpp"
|
3
4
|
using namespace mysqlpp;
|
@@ -41,11 +42,21 @@ DBFace::connect()
|
|
41
42
|
}
|
42
43
|
}
|
43
44
|
|
45
|
+
string
|
46
|
+
currentDateTime()
|
47
|
+
{
|
48
|
+
using namespace boost::posix_time;
|
49
|
+
ptime now = second_clock::local_time();
|
50
|
+
|
51
|
+
return to_iso_extended_string(now);
|
52
|
+
}
|
53
|
+
|
54
|
+
|
44
55
|
void
|
45
56
|
DBFace::log(const string& message)
|
46
57
|
{
|
47
58
|
if (_os)
|
48
|
-
(*_os) << "DMMM
|
59
|
+
(*_os) << currentDateTime() << " DMMM " << message << endl;
|
49
60
|
}
|
50
61
|
|
51
62
|
void
|
@@ -7,6 +7,29 @@
|
|
7
7
|
#include "dmmm_id.hpp"
|
8
8
|
|
9
9
|
namespace DMMM {
|
10
|
+
|
11
|
+
typedef std::vector<std::string> FieldVector;
|
12
|
+
struct FieldVectorComp{
|
13
|
+
bool operator() (const FieldVector& f1, const FieldVector& f2) const
|
14
|
+
{
|
15
|
+
if (f1.size() < f2.size())
|
16
|
+
return true;
|
17
|
+
if (f1.size() > f2.size())
|
18
|
+
return false;
|
19
|
+
for (size_t i = 0; i < f1.size(); ++i){
|
20
|
+
if (f1[i] < f2[i])
|
21
|
+
return true;
|
22
|
+
if (f1[i] > f2[i])
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
return false;
|
26
|
+
}
|
27
|
+
};
|
28
|
+
|
29
|
+
typedef std::map<FieldVector,
|
30
|
+
std::vector<std::vector<std::string> >,
|
31
|
+
FieldVectorComp> FieldsToRows;
|
32
|
+
|
10
33
|
namespace UTILS {
|
11
34
|
|
12
35
|
template<class T>
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-metamapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.2.9
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Jonah Honeyman
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2012-
|
18
|
+
date: 2012-09-06 00:00:00 Z
|
20
19
|
dependencies: []
|
21
20
|
|
22
21
|
description: C++ API for databases created with DM. Hard typing, compile time checked queries.
|