dm-metamapper 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,5 +3,4 @@
3
3
  .bundle/*
4
4
  .rvmrc
5
5
  *.gem
6
- *.gemspec
7
6
  output
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dm-metamapper}
8
+ s.version = "0.0.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jonah Honeyman", "Omer Tamuz"]
12
+ s.date = %q{2010-06-22}
13
+ s.description = %q{C++ API for databases created with DM. Hard typing, compile time checked queries.}
14
+ s.email = %q{jonah@honeyman.org}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".autospec",
20
+ ".gitignore",
21
+ "Gemfile",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "dm-metamapper.gemspec",
26
+ "example/.gitignore",
27
+ "example/Makefile",
28
+ "example/example.cpp",
29
+ "example/example.rb",
30
+ "lib/dm-metamapper.rb",
31
+ "lib/dm-metamapper/config.rb",
32
+ "lib/dm-metamapper/extension.rb",
33
+ "lib/dm-metamapper/generator.rb",
34
+ "lib/dm-metamapper/generators/cpp.rb",
35
+ "lib/dm-metamapper/metamapper.rb",
36
+ "lib/dm-metamapper/property.rb",
37
+ "lib/dm-metamapper/template.rb",
38
+ "lib/templates/cpp/class.hpp.erb",
39
+ "lib/templates/cpp/dmmm_comparators.hpp.erb",
40
+ "lib/templates/cpp/dmmm_dbface.cpp.erb",
41
+ "lib/templates/cpp/dmmm_dbface.h.erb",
42
+ "lib/templates/cpp/dmmm_fields.hpp.erb",
43
+ "lib/templates/cpp/dmmm_id.hpp.erb",
44
+ "lib/templates/cpp/dmmm_identifiers.hpp.erb",
45
+ "lib/templates/cpp/dmmm_utils.cpp.erb",
46
+ "lib/templates/cpp/dmmm_utils.hpp.erb",
47
+ "lib/templates/cpp/instance.hpp.erb",
48
+ "spec/dm-metamapper/generator_spec.rb",
49
+ "spec/dm-metamapper/template_spec.rb",
50
+ "spec/spec.opts",
51
+ "spec/spec_helper.rb"
52
+ ]
53
+ s.homepage = %q{http://github.com/jonuts/dm-metamapper}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.6}
57
+ s.summary = %q{Code generating C++ ORM}
58
+ s.test_files = [
59
+ "spec/spec_helper.rb",
60
+ "spec/dm-metamapper/generator_spec.rb",
61
+ "spec/dm-metamapper/template_spec.rb"
62
+ ]
63
+
64
+ if s.respond_to? :specification_version then
65
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
66
+ s.specification_version = 3
67
+
68
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
69
+ else
70
+ end
71
+ else
72
+ end
73
+ end
74
+
@@ -8,10 +8,28 @@ DBFace* DBFace::_this = NULL;
8
8
 
9
9
  DBFace::DBFace(const string& database, const string& host,
10
10
  const string& user, const string& password)
11
+ : _os(cout)
11
12
  {
12
13
  _this = this;
13
14
  if (!_connection.connect(database.c_str(), host.c_str(),
14
- user.c_str(), password.c_str())){
15
+ user.c_str(), password.c_str()))
16
+ {
17
+ _os << "Could not connect to DB";
18
+ cerr << "Could not connect to DB";
19
+ exit(-1);
20
+ }
21
+ }
22
+
23
+ DBFace::DBFace(const string& database, const string& host,
24
+ const string& user, const string& password,
25
+ ostream& os)
26
+ : _os(os)
27
+ {
28
+ _this = this;
29
+ if (!_connection.connect(database.c_str(), host.c_str(),
30
+ user.c_str(), password.c_str()))
31
+ {
32
+ _os << "Could not connect to DB";
15
33
  cerr << "Could not connect to DB";
16
34
  exit(-1);
17
35
  }
@@ -41,7 +59,7 @@ DBFace::select(const std::vector<std::string>& tables,
41
59
  q << " WHERE " << where;
42
60
  if (additional.size())
43
61
  q << " " << additional;
44
- cout << q << endl;
62
+ _os << q << endl;
45
63
  StoreQueryResult mysqlRes;
46
64
  try{
47
65
  mysqlRes = q.store();
@@ -72,7 +90,7 @@ DBFace::erase(const std::vector<std::string>& tables,
72
90
  q << " INNER JOIN " + tables[i];
73
91
  if (where.size())
74
92
  q << " WHERE " << where;
75
- cout << q << endl;
93
+ _os << q << endl;
76
94
  return executeQuery(q);
77
95
 
78
96
  }
@@ -97,7 +115,7 @@ DBFace::getLastInsertId(Query& rQuery, size_t& rId)
97
115
  {
98
116
  try{
99
117
  rId = rQuery.insert_id();
100
- cout << "got last insert ID: " << rId << endl;
118
+ _os << "got last insert ID: " << rId << endl;
101
119
  }
102
120
  catch (const mysqlpp::Exception& er) {
103
121
  return false;
@@ -131,7 +149,7 @@ DBFace::insert(const string& table,
131
149
  q << quote << it->second;
132
150
  }
133
151
  q << ")";
134
- cout << q << endl;
152
+ _os << q << endl;
135
153
  bool ok = executeQuery(q);
136
154
  ok = ok && getLastInsertId(q, rInsertId);
137
155
  return ok;
@@ -154,7 +172,7 @@ DBFace::update(const string& table,
154
172
  }
155
173
  if (where.size())
156
174
  q << " WHERE " << where;
157
- cout << q << endl;
175
+ _os << q << endl;
158
176
  return executeQuery(q);
159
177
  }
160
178
 
@@ -2,6 +2,7 @@
2
2
  #define DMMM_DBFACE_H
3
3
 
4
4
  #include <map>
5
+ #include <iosfwd>
5
6
  #include <mysql++.h>
6
7
  #include <boost/thread/mutex.hpp>
7
8
 
@@ -15,6 +16,9 @@ public:
15
16
 
16
17
  DBFace(const std::string& database, const std::string& host,
17
18
  const std::string& user, const std::string& password);
19
+ DBFace(const std::string& database, const std::string& host,
20
+ const std::string& user, const std::string& password,
21
+ std::ostream& os);
18
22
 
19
23
  bool insert(const std::string& table,
20
24
  const std::map<std::string, std::string>& field2Val,
@@ -40,6 +44,7 @@ private:
40
44
  mysqlpp::Connection _connection;
41
45
  mutable boost::mutex _mutex;
42
46
  static DBFace* _this;
47
+ std::ostream& _os;
43
48
  };
44
49
 
45
50
  } //namespace DMMM
@@ -6,7 +6,7 @@
6
6
  #include <sstream>
7
7
 
8
8
  namespace DMMM{
9
- namespace UTILS{
9
+ namespace ID{
10
10
 
11
11
  template<class T>
12
12
  class Id {
@@ -59,12 +59,12 @@ private:
59
59
  };
60
60
 
61
61
 
62
- } //namespace UTILS
62
+ } //namespace ID
63
63
  } //namespace DMMM
64
64
 
65
65
  template<class T>
66
66
  std::ostream&
67
- operator<< (std::ostream& os, const DMMM::UTILS::Id<T>& id)
67
+ operator<< (std::ostream& os, const DMMM::ID::Id<T>& id)
68
68
  {
69
69
  os << id.to_s();
70
70
  return os;
@@ -72,7 +72,7 @@ operator<< (std::ostream& os, const DMMM::UTILS::Id<T>& id)
72
72
 
73
73
  template<class T>
74
74
  std::istream&
75
- operator>> (std::istream& is, DMMM::UTILS::Id<T>& id)
75
+ operator>> (std::istream& is, DMMM::ID::Id<T>& id)
76
76
  {
77
77
  is >> id.serialization();
78
78
  return is;
@@ -8,7 +8,7 @@ namespace DMMM {
8
8
  <% models.each do |model| %>
9
9
  <% model_name = decolonize(model.name) %>
10
10
  class DummyO_<%= model_name %>;
11
- typedef UTILS::Id<DummyO_<%= model_name %>> I_<%= model_name %>;
11
+ typedef ID::Id<DummyO_<%= model_name %>> I_<%= model_name %>;
12
12
  <% end %>
13
13
 
14
14
 
@@ -52,8 +52,16 @@ public:
52
52
  <% end %>
53
53
  std::string where =
54
54
  "<%= model.serial.name %>=" + UTILS::toString(_f_<%= model.serial.name %>._base);
55
- return DBFace::instance()->update("<%= model.storage_name %>",
56
- field2Val, where);
55
+ if (DBFace::instance()->update("<%= model.storage_name %>",
56
+ field2Val, where))
57
+ {
58
+ <% model.generated_properties.each do |property| %>
59
+ _f_<%= property.name %>._dirty = false;
60
+ <% end %>
61
+ return true;
62
+ }
63
+ else
64
+ return false;
57
65
  }
58
66
  <% end %>
59
67
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
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-15 00:00:00 +03:00
18
+ date: 2010-06-22 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -34,6 +34,7 @@ files:
34
34
  - README.md
35
35
  - Rakefile
36
36
  - VERSION
37
+ - dm-metamapper.gemspec
37
38
  - example/.gitignore
38
39
  - example/Makefile
39
40
  - example/example.cpp