dm-metamapper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -3
- data/VERSION +1 -1
- data/dm-metamapper.gemspec +2 -2
- data/lib/dm-metamapper/generator.rb +3 -3
- data/lib/dm-metamapper/metamapper.rb +1 -1
- data/lib/templates/cpp/class.hpp.erb +3 -3
- data/lib/templates/cpp/dmmm_comparators.hpp.erb +7 -7
- data/lib/templates/cpp/dmmm_dbface.cpp.erb +2 -2
- data/lib/templates/cpp/dmmm_id.hpp.erb +5 -2
- data/lib/templates/cpp/dmmm_identifiers.hpp.erb +3 -2
- data/lib/templates/cpp/dmmm_utils.cpp.erb +3 -0
- data/lib/templates/cpp/dmmm_utils.hpp.erb +2 -0
- data/lib/templates/cpp/instance.hpp.erb +21 -13
- metadata +3 -3
data/Gemfile
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
-
|
3
|
+
dm_gems_version = "~> 0.10"
|
4
|
+
do_gems_version = "~> 0.10"
|
5
|
+
|
6
|
+
gem "dm-core", dm_gems_version
|
4
7
|
|
5
8
|
group :test do
|
6
9
|
gem "rspec"
|
7
10
|
gem "data_objects"
|
8
|
-
gem "do_sqlite3"
|
9
|
-
gem "do_mysql"
|
11
|
+
gem "do_sqlite3", do_gems_version
|
12
|
+
gem "do_mysql", do_gems_version
|
10
13
|
end
|
11
14
|
|
12
15
|
group :deploy do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/dm-metamapper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-metamapper}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jonah Honeyman", "Omer Tamuz"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-09}
|
13
13
|
s.description = %q{C++ API for databases created with DM. Hard typing, compile time checked queries.}
|
14
14
|
s.email = %q{jonah@honeyman.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -82,13 +82,13 @@ class CPPGenerator < DataMapper::MetaMapper::Generator
|
|
82
82
|
puts "Generating files for model " + self.name.to_s
|
83
83
|
key_to_parent = {}
|
84
84
|
relationships.select{|r,m| m.class.name == 'DataMapper::Associations::ManyToOne::Relationship'}.each do |r|
|
85
|
-
key_to_parent[r[1].child_key.first.name.to_s] = r[
|
86
|
-
puts "#{r[1].child_key.first.name.to_s} -> #{r[
|
85
|
+
key_to_parent[r[1].child_key.first.name.to_s] = r[1].parent_model_name.to_const_string.sub(/::/,'_')
|
86
|
+
puts "#{r[1].child_key.first.name.to_s} -> #{key_to_parent[r[1].child_key.first.name.to_s]}"
|
87
87
|
end
|
88
88
|
|
89
89
|
properties.each do |e|
|
90
90
|
cpp_name = if e.serial?
|
91
|
-
"Field<I_#{e.model.name}>"
|
91
|
+
"Field<I_#{e.model.name.sub(/::/,'_')}>"
|
92
92
|
elsif !key_to_parent[e.name.to_s].nil?
|
93
93
|
"Field<I_#{key_to_parent[e.name.to_s]}>"
|
94
94
|
else
|
@@ -26,7 +26,7 @@ module DataMapper
|
|
26
26
|
generated_file.template
|
27
27
|
].join('/')
|
28
28
|
|
29
|
-
result_base_name = context ? context.name.to_s : generated_file.template.sub(/\.erb$/,'')
|
29
|
+
result_base_name = context ? context.name.to_s.sub(/::/,'_') : generated_file.template.sub(/\.erb$/,'')
|
30
30
|
|
31
31
|
result_filename = File.join(
|
32
32
|
File.dirname(__FILE__), "../../output", [
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% class_name = self.name %>
|
1
|
+
<% class_name = self.name.sub(/::/,'_') %>
|
2
2
|
<% all_caps_name = class_name.upcase %>
|
3
3
|
#ifndef T_<%= all_caps_name %>
|
4
4
|
#define T_<%= all_caps_name %>
|
@@ -23,7 +23,7 @@ public:
|
|
23
23
|
_tables.push_back("<%= storage_name %>");
|
24
24
|
}
|
25
25
|
<% self.relationships.select{|r,m| m.class.name == 'DataMapper::Associations::ManyToOne::Relationship'}.each do |r| %>
|
26
|
-
<% parent = r[
|
26
|
+
<% parent = r[1].parent_model_name.sub(/::/,'_') %>
|
27
27
|
T_<%= class_name %>(const T_<%= parent %>& parent)
|
28
28
|
{
|
29
29
|
_tables.push_back("<%= storage_name %>");
|
@@ -76,7 +76,7 @@ public:
|
|
76
76
|
for(size_t i = 0; i < res.size(); ++i){
|
77
77
|
<% generated_properties.each do |property| %>
|
78
78
|
r[i]._f_<%= property.name %>._base =
|
79
|
-
fromString<<%= property.instance_variable_get(:@cpp_name) %>::Base>(res[i]["<%= property.name %>"]);
|
79
|
+
UTILS::fromString<<%= property.instance_variable_get(:@cpp_name) %>::Base>(res[i]["<%= property.name %>"]);
|
80
80
|
<% end %>
|
81
81
|
}
|
82
82
|
}
|
@@ -8,49 +8,49 @@ namespace DMMM {
|
|
8
8
|
template<class E>
|
9
9
|
typename E::ConditionType operator== (E e, const typename E::ComparerType& x){
|
10
10
|
typename E::ConditionType c;
|
11
|
-
c._cond = e._field + " = '" + toString(x) + "'";
|
11
|
+
c._cond = e._field + " = '" + UTILS::toString(x) + "'";
|
12
12
|
return c;
|
13
13
|
}
|
14
14
|
|
15
15
|
template<class E>
|
16
16
|
typename E::ConditionType operator< (E e, const typename E::ComparerType& x){
|
17
17
|
typename E::ConditionType c;
|
18
|
-
c._cond = e._field + " < '" + toString(x) + "'";
|
18
|
+
c._cond = e._field + " < '" + UTILS::toString(x) + "'";
|
19
19
|
return c;
|
20
20
|
}
|
21
21
|
|
22
22
|
template<class E>
|
23
23
|
typename E::ConditionType operator<= (E e, const typename E::ComparerType& x){
|
24
24
|
typename E::ConditionType c;
|
25
|
-
c._cond = e._field + " <= '" + toString(x) + "'";
|
25
|
+
c._cond = e._field + " <= '" + UTILS::toString(x) + "'";
|
26
26
|
return c;
|
27
27
|
}
|
28
28
|
|
29
29
|
template<class E>
|
30
30
|
typename E::ConditionType operator> (E e, const typename E::ComparerType& x){
|
31
31
|
typename E::ConditionType c;
|
32
|
-
c._cond = e._field + " > '" + toString(x) + "'";
|
32
|
+
c._cond = e._field + " > '" + UTILS::toString(x) + "'";
|
33
33
|
return c;
|
34
34
|
}
|
35
35
|
|
36
36
|
template<class E>
|
37
37
|
typename E::ConditionType operator>= (E e, const typename E::ComparerType& x){
|
38
38
|
typename E::ConditionType c;
|
39
|
-
c._cond = e._field + " >= '" + toString(x) + "'";
|
39
|
+
c._cond = e._field + " >= '" + UTILS::toString(x) + "'";
|
40
40
|
return c;
|
41
41
|
}
|
42
42
|
|
43
43
|
template<class E>
|
44
44
|
typename E::ConditionType operator!= (E e, const typename E::ComparerType& x){
|
45
45
|
typename E::ConditionType c;
|
46
|
-
c._cond = e._field + " != '" + toString(x) + "'";
|
46
|
+
c._cond = e._field + " != '" + UTILS::toString(x) + "'";
|
47
47
|
return c;
|
48
48
|
}
|
49
49
|
|
50
50
|
template<class E>
|
51
51
|
typename E::ConditionType operator%= (E e, const typename E::ComparerType& x){
|
52
52
|
typename E::ConditionType c;
|
53
|
-
c._cond = e._field + " LIKE '" + toString(x) + "'";
|
53
|
+
c._cond = e._field + " LIKE '" + UTILS::toString(x) + "'";
|
54
54
|
return c;
|
55
55
|
}
|
56
56
|
|
@@ -54,7 +54,7 @@ DBFace::select(const std::vector<std::string>& tables,
|
|
54
54
|
for (size_t i = 0; i < mysqlRes.num_rows(); ++i){
|
55
55
|
rRes.resize(rRes.size() + 1);
|
56
56
|
for (size_t j = 0; j < columns.size(); ++j)
|
57
|
-
rRes.back()[columns[j]] = toString(mysqlRes[i][columns[j].c_str()]);
|
57
|
+
rRes.back()[columns[j]] = UTILS::toString(mysqlRes[i][columns[j].c_str()]);
|
58
58
|
}
|
59
59
|
return true;
|
60
60
|
}
|
@@ -172,5 +172,5 @@ DBFace::now()
|
|
172
172
|
cerr << "Query failed: " << q << endl << er.what();
|
173
173
|
return string();
|
174
174
|
}
|
175
|
-
return toString(mysqlRes[0]["now()"]);
|
175
|
+
return UTILS::toString(mysqlRes[0]["now()"]);
|
176
176
|
}
|
@@ -6,6 +6,8 @@
|
|
6
6
|
#include <sstream>
|
7
7
|
|
8
8
|
namespace DMMM{
|
9
|
+
namespace UTILS{
|
10
|
+
|
9
11
|
template<class T>
|
10
12
|
class Id {
|
11
13
|
|
@@ -57,11 +59,12 @@ private:
|
|
57
59
|
};
|
58
60
|
|
59
61
|
|
62
|
+
} //namespace UTILS
|
60
63
|
} //namespace DMMM
|
61
64
|
|
62
65
|
template<class T>
|
63
66
|
std::ostream&
|
64
|
-
operator<< (std::ostream& os, const DMMM::Id<T>& id)
|
67
|
+
operator<< (std::ostream& os, const DMMM::UTILS::Id<T>& id)
|
65
68
|
{
|
66
69
|
os << id.to_s();
|
67
70
|
return os;
|
@@ -69,7 +72,7 @@ operator<< (std::ostream& os, const DMMM::Id<T>& id)
|
|
69
72
|
|
70
73
|
template<class T>
|
71
74
|
std::istream&
|
72
|
-
operator>> (std::istream& is, DMMM::Id<T>& id)
|
75
|
+
operator>> (std::istream& is, DMMM::UTILS::Id<T>& id)
|
73
76
|
{
|
74
77
|
is >> id.serialization();
|
75
78
|
return is;
|
@@ -6,8 +6,9 @@
|
|
6
6
|
namespace DMMM {
|
7
7
|
|
8
8
|
<% models.each do |model| %>
|
9
|
-
|
10
|
-
|
9
|
+
<% model_name = model.name.sub(/::/,'_') %>
|
10
|
+
class DummyO_<%= model_name %>;
|
11
|
+
typedef UTILS::Id<DummyO_<%= model_name %>> I_<%= model_name %>;
|
11
12
|
<% end %>
|
12
13
|
|
13
14
|
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#include "dmmm_utils.hpp"
|
2
2
|
|
3
3
|
namespace DMMM {
|
4
|
+
namespace UTILS {
|
5
|
+
|
4
6
|
template<>
|
5
7
|
std::string
|
6
8
|
fromString<std::string>(const std::string& s)
|
@@ -8,4 +10,5 @@ fromString<std::string>(const std::string& s)
|
|
8
10
|
return s;
|
9
11
|
}
|
10
12
|
|
13
|
+
} //namespace UTILS
|
11
14
|
} //namespace DMMM
|
@@ -7,6 +7,7 @@
|
|
7
7
|
#include <dmmm_id.hpp>
|
8
8
|
|
9
9
|
namespace DMMM {
|
10
|
+
namespace UTILS {
|
10
11
|
|
11
12
|
template<class T>
|
12
13
|
std::string
|
@@ -35,6 +36,7 @@ template<>
|
|
35
36
|
std::string
|
36
37
|
fromString<std::string>(const std::string& s);
|
37
38
|
|
39
|
+
} //namespace UTILS
|
38
40
|
} //namespace DMMM
|
39
41
|
|
40
42
|
#endif //DMMM_UTILS_HPP
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<% class_name = self.name %>
|
1
|
+
<% class_name = self.name.sub(/::/,'_') %>
|
2
2
|
<% all_caps_name = class_name.upcase %>
|
3
3
|
#ifndef O_<%= all_caps_name %>
|
4
4
|
#define O_<%= all_caps_name %>
|
@@ -11,7 +11,7 @@
|
|
11
11
|
#include "dmmm_fields.hpp"
|
12
12
|
#include "dmmm_comparators.hpp"
|
13
13
|
<% self.relationships.select{|r,m| m.class.name == 'DataMapper::Associations::ManyToOne::Relationship'}.each do |relative| %>
|
14
|
-
#include "T_<%= relative[1].parent_model.to_s %>.hpp"
|
14
|
+
#include "T_<%= relative[1].parent_model.to_s.sub(/::/,'_') %>.hpp"
|
15
15
|
<% end %>
|
16
16
|
|
17
17
|
<%# self.relationships.select{|r,m| m.class.name == 'DataMapper::Associations::OneToMany::Relationship'}.each do |relative| %>
|
@@ -23,7 +23,7 @@ public:
|
|
23
23
|
|
24
24
|
O_<%= class_name %>() {}
|
25
25
|
<% self.relationships.select{|r,m| m.class.name == 'DataMapper::Associations::ManyToOne::Relationship'}.each do |r| %>
|
26
|
-
<% parent = r[
|
26
|
+
<% parent = r[1].parent_model_name.sub(/::/,'_') %>
|
27
27
|
O_<%= class_name %>(const O_<%= parent %>& parent)
|
28
28
|
: _f_<%= r[1].child_key.first.name.to_s %>(parent._<%= r[1].parent_key.first.name.to_s %>())
|
29
29
|
{}
|
@@ -49,10 +49,10 @@ public:
|
|
49
49
|
<% generated_properties.each do |property| %>
|
50
50
|
if (_f_<%= property.name %>._dirty)
|
51
51
|
field2Val["<%= property.name %>"] =
|
52
|
-
toString(_f_<%= property.name %>._base);
|
52
|
+
UTILS::toString(_f_<%= property.name %>._base);
|
53
53
|
<% end %>
|
54
54
|
std::string where =
|
55
|
-
"<%= serial.name %>=" + toString(_f_<%= serial.name %>._base);
|
55
|
+
"<%= serial.name %>=" + UTILS::toString(_f_<%= serial.name %>._base);
|
56
56
|
return DBFace::instance()->update("<%= storage_name %>",
|
57
57
|
field2Val, where);
|
58
58
|
}
|
@@ -65,23 +65,31 @@ public:
|
|
65
65
|
<% generated_properties.each do |property| %>
|
66
66
|
if (_f_<%= property.name %>._dirty)
|
67
67
|
field2Val["<%= property.name %>"] =
|
68
|
-
toString(_f_<%= property.name %>._base);
|
68
|
+
UTILS::toString(_f_<%= property.name %>._base);
|
69
69
|
<% end %>
|
70
70
|
<% if serial %>
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
if (DBFace::instance()->
|
72
|
+
insert("<%= storage_name %>", field2Val,
|
73
|
+
_f_<%= serial.name %>._base.serialization()))
|
74
74
|
<% else %>
|
75
75
|
size_t id;
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
if (DBFace::instance()->
|
77
|
+
insert("<%= storage_name %>", field2Val,
|
78
|
+
id))
|
79
79
|
<% end %>
|
80
|
+
{
|
81
|
+
<% generated_properties.each do |property| %>
|
82
|
+
_f_<%= property.name %>._dirty = false;
|
83
|
+
<% end %>
|
84
|
+
return true;
|
85
|
+
}
|
86
|
+
else
|
87
|
+
return false;
|
80
88
|
|
81
89
|
}
|
82
90
|
|
83
91
|
<% self.relationships.select{|r,m| m.class.name == 'DataMapper::Associations::ManyToOne::Relationship'}.each do |r| %>
|
84
|
-
<% parent = r[
|
92
|
+
<% parent = r[1].parent_model_name.sub(/::/,'_') %>
|
85
93
|
std::pair<O_<%= parent %>, bool> <%= r[0] %>(){
|
86
94
|
T_<%= parent %> T(T_<%= parent %>::E_<%= r[1].parent_key.first.name.to_s %>() == _<%= r[1].child_key.first.name.to_s %>());
|
87
95
|
return T.first();
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jonah Honeyman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-09 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|