dm-metamapper 0.0.11 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/dm-metamapper.rb CHANGED
@@ -1,4 +1,5 @@
1
- $:.push File.dirname(__FILE__)
1
+ lib = File.dirname(__FILE__)
2
+ $:.push lib unless $:.include?(lib)
2
3
 
3
4
  require 'dm-core'
4
5
  require 'dm-metamapper/property'
@@ -27,7 +27,7 @@ module DataMapper
27
27
  "Field<I_#{decolonize(model.name)}>"
28
28
  elsif key_to_parent[prop.name]
29
29
  "Field<I_#{key_to_parent[prop.name]}>"
30
- elsif prop.type.ancestors.include?(DataMapper::Types::Enum)
30
+ elsif DataMapper::Property::Enum === prop
31
31
  name = prop.name.to_s.upcase
32
32
  enums[name] = prop
33
33
  "Field<Enum#{decolonize(model.name)}#{name}>"
@@ -1,8 +1,6 @@
1
- if DataMapper::VERSION > "1.0"
2
- module DataMapper
3
- class Property
4
- accept_options :skip_generation
5
- end
1
+ module DataMapper
2
+ class Property
3
+ accept_options :skip_generation
6
4
  end
7
5
  end
8
6
 
@@ -0,0 +1,6 @@
1
+ module DataMapper
2
+ module MetaMapper
3
+ VERSION = "0.1.0" unless defined?(::DataMapper::MetaMapper::VERSION)
4
+ end
5
+
6
+ end
@@ -34,6 +34,13 @@ public:
34
34
  if (!parent._constraint.nil())
35
35
  _constraint._cond += " AND " + parent._constraint._cond;
36
36
  }
37
+
38
+ T_<%= class_name %>(const I_<%= parent %>& parentId)
39
+ {
40
+ _tables.push_back("<%= model.storage_name %>");
41
+
42
+ _constraint._cond = "(<%= model.storage_name + "." + r[1].child_key.first.name.to_s %> = " + parentId.to_s() + ")";
43
+ }
37
44
  <% end %>
38
45
 
39
46
  <% model.generated_properties.each do |property| %>
@@ -74,7 +81,7 @@ public:
74
81
  for(size_t i = 0; i < res.size(); ++i){
75
82
  <% model.generated_properties.each do |property| %>
76
83
  r[i]._f_<%= property.name %>._base =
77
- <% if property.type.ancestors.include?(DataMapper::Types::Enum) %>
84
+ <% if DataMapper::Property::Enum === property %>
78
85
  (<%= property.cpp_name %>::Base)UTILS::fromString<size_t>(res[i]["<%= property.name %>"]);
79
86
  <% else %>
80
87
  UTILS::fromString<<%= property.cpp_name %>::Base>(res[i]["<%= property.name %>"]);
@@ -0,0 +1,75 @@
1
+ #ifndef PPORM_COMPARATORS_H
2
+ #define PPORM_COMPARATORS_H
3
+
4
+ #include <string>
5
+
6
+ #include <sstream>
7
+
8
+ namespace PPORM {
9
+ template<class E>
10
+ typename E::ConditionType operator== (E e, const typename E::ComparerType& x){
11
+ typename E::ConditionType c;
12
+ c._cond = e._field + " = '" + toString(x) + "'";
13
+ return c;
14
+ }
15
+
16
+ template<class E>
17
+ typename E::ConditionType operator< (E e, const typename E::ComparerType& x){
18
+ typename E::ConditionType c;
19
+ c._cond = e._field + " < '" + toString(x) + "'";
20
+ return c;
21
+ }
22
+
23
+ template<class E>
24
+ typename E::ConditionType operator<= (E e, const typename E::ComparerType& x){
25
+ typename E::ConditionType c;
26
+ c._cond = e._field + " <= '" + toString(x) + "'";
27
+ return c;
28
+ }
29
+
30
+ template<class E>
31
+ typename E::ConditionType operator> (E e, const typename E::ComparerType& x){
32
+ typename E::ConditionType c;
33
+ c._cond = e._field + " > '" + toString(x) + "'";
34
+ return c;
35
+ }
36
+
37
+ template<class E>
38
+ typename E::ConditionType operator>= (E e, const typename E::ComparerType& x){
39
+ typename E::ConditionType c;
40
+ c._cond = e._field + " >= '" + toString(x) + "'";
41
+ return c;
42
+ }
43
+
44
+ template<class E>
45
+ typename E::ConditionType operator!= (E e, const typename E::ComparerType& x){
46
+ typename E::ConditionType c;
47
+ c._cond = e._field + " != '" + toString(x) + "'";
48
+ return c;
49
+ }
50
+
51
+ template<class E>
52
+ typename E::ConditionType operator%= (E e, const typename E::ComparerType& x){
53
+ typename E::ConditionType c;
54
+ c._cond = e._field + " LIKE '" + toString(x) + "'";
55
+ return c;
56
+ }
57
+
58
+ template<class C>
59
+ C operator&& (const C& c1, const C& c2){
60
+ C c;
61
+ c._cond = "(" + c1._cond + ") AND (" + c2._cond + ")";
62
+ return c;
63
+ }
64
+
65
+ template<class C>
66
+ C operator|| (const C& c1, const C& c2){
67
+ C c;
68
+ c._cond = "(" + c1._cond + ") OR (" + c2._cond + ")";
69
+ return c;
70
+ }
71
+
72
+
73
+ } //namespace PPORM
74
+
75
+ #endif //PPORM_COMPARATORS_H
@@ -0,0 +1,190 @@
1
+ #include "dbface.h"
2
+ #include "utils.hpp"
3
+ using namespace mysqlpp;
4
+ using namespace std;
5
+
6
+ DBFace* DBFace::_this = NULL;
7
+
8
+ DBFace::DBFace(const string& database, const string& host,
9
+ const string& user, const string& password)
10
+ :_database(database)
11
+ {
12
+ _this = this;
13
+ if (!_connection.connect(database.c_str(), host.c_str(),
14
+ user.c_str(), password.c_str())){
15
+ cerr << "Could not connect to DB";
16
+ exit(-1);
17
+ }
18
+ _dbtype2BaseType["int"] = "int";
19
+ _dbtype2BaseType["bigint"] = "int";
20
+ _dbtype2BaseType["tinyint"] = "int";
21
+ _dbtype2BaseType["text"] = "std::string";
22
+ _dbtype2BaseType["float"] = "double";
23
+ _dbtype2BaseType["datetime"] = "std::string";
24
+ _dbtype2BaseType["date"] = "std::string";
25
+ _dbtype2BaseType["varchar"] = "std::string";
26
+ }
27
+
28
+ bool
29
+ DBFace::select(const std::string& table,
30
+ const std::vector<string>& columns,
31
+ const std::string& where,
32
+ const std::string& additional,
33
+ QueryRes& rRes)
34
+ {
35
+ Query q = _connection.query();
36
+
37
+ q << "SELECT ";
38
+ for (size_t i = 0; i < columns.size(); ++i){
39
+ if (i > 0)
40
+ q << ",";
41
+ q << columns[i];
42
+ }
43
+ q << " FROM " << table;
44
+ if (where.size())
45
+ q << " WHERE " << where;
46
+ if (additional.size())
47
+ q << " " << additional;
48
+ // cout << q << endl;
49
+ StoreQueryResult mysqlRes;
50
+ try{
51
+ mysqlRes = q.store();
52
+ }
53
+ catch (const mysqlpp::Exception& er) {
54
+ cerr << "Query failed: " << q << endl << er.what();
55
+ return false;
56
+ }
57
+
58
+ for (size_t i = 0; i < mysqlRes.num_rows(); ++i){
59
+ rRes.resize(rRes.size() + 1);
60
+ for (size_t j = 0; j < columns.size(); ++j)
61
+ rRes.back()[columns[j]] = toString(mysqlRes[i][columns[j].c_str()]);
62
+ }
63
+ return true;
64
+ }
65
+
66
+ bool
67
+ DBFace:: selectTables(QueryRes& rRes)
68
+ {
69
+ vector<string> columns;
70
+ columns.push_back("table_name");
71
+ string where = "table_schema='" + _database + "'";
72
+ return select("information_schema.tables", columns, where, "", rRes);
73
+ }
74
+
75
+
76
+ bool
77
+ DBFace::selectColumns(const string& table, QueryRes& rRes)
78
+ {
79
+ vector<string> columns;
80
+ columns.push_back("column_name");
81
+ columns.push_back("data_type");
82
+ string where =
83
+ "table_schema='" + _database +
84
+ "'" + " and table_name='" + table + "'";
85
+ return select("information_schema.columns", columns, where, "", rRes);
86
+ }
87
+
88
+
89
+ void
90
+ DBFace::getTables(vector<Table>& rTables)
91
+ {
92
+ QueryRes res;
93
+ selectTables(res);
94
+ for (size_t i = 0; i < res.size(); ++i){
95
+ rTables.resize(rTables.size() + 1);
96
+ Table& table = rTables.back();
97
+ table._name = res[i]["table_name"];
98
+ QueryRes resCols;
99
+ selectColumns(res[i]["table_name"], resCols);
100
+ table._hasId = false;
101
+ for (size_t j = 0; j < resCols.size(); ++j){
102
+ Column col;
103
+ col._field = resCols[j]["column_name"];
104
+ col._type = resCols[j]["data_type"];
105
+ table._columns.push_back(col);
106
+ if (col._field == "id")
107
+ table._hasId = true;
108
+ }
109
+ }
110
+ }
111
+
112
+ bool
113
+ DBFace::executeQuery(Query& q)
114
+ {
115
+ boost::mutex::scoped_lock lock(_mutex);
116
+ try{
117
+ q.execute();
118
+ }
119
+ catch (const mysqlpp::Exception& er) {
120
+ cerr << "Query failed: " << q << endl << er.what();
121
+ return false;
122
+ }
123
+ return true;
124
+ }
125
+
126
+ bool
127
+ DBFace::insert(const string& table,
128
+ const map<string, string>& field2Val)
129
+ {
130
+ if (field2Val.size() == 0)
131
+ return true;
132
+
133
+ Query q = _connection.query();
134
+ q << "INSERT INTO " << table << " (";
135
+ for (map<string, string>::const_iterator it = field2Val.begin();
136
+ it != field2Val.end(); ++it)
137
+ {
138
+ if (it != field2Val.begin())
139
+ q << ",";
140
+ q << it->first;
141
+ }
142
+ q << ")VALUES(";
143
+ for (map<string, string>::const_iterator it = field2Val.begin();
144
+ it != field2Val.end(); ++it)
145
+ {
146
+ if (it != field2Val.begin())
147
+ q << ",";
148
+ q << quote << it->second;
149
+ }
150
+ q << ")";
151
+ return executeQuery(q);
152
+ }
153
+
154
+ bool
155
+ DBFace::update(const string& table,
156
+ const map<string, string>& field2Val,
157
+ const string& where)
158
+ {
159
+ Query q = _connection.query();
160
+
161
+ q << "UPDATE " << table << " SET ";
162
+ for (map<string, string>::const_iterator it = field2Val.begin();
163
+ it != field2Val.end(); ++it)
164
+ {
165
+ if (it != field2Val.begin())
166
+ q << ",";
167
+ q << it->first << "=" << quote << it->second;
168
+ }
169
+ if (where.size())
170
+ q << " WHERE " << where;
171
+ // cout << q << endl;
172
+ return executeQuery(q);
173
+ }
174
+
175
+ string
176
+ DBFace::now()
177
+ {
178
+ Query q = _connection.query();
179
+
180
+ q << "SELECT NOW()";
181
+ StoreQueryResult mysqlRes;
182
+ try{
183
+ mysqlRes = q.store();
184
+ }
185
+ catch (const mysqlpp::Exception& er) {
186
+ cerr << "Query failed: " << q << endl << er.what();
187
+ return string();
188
+ }
189
+ return toString(mysqlRes[0]["now()"]);
190
+ }
@@ -0,0 +1,47 @@
1
+ #ifndef DBFACE_H
2
+ #define DBFACE_H
3
+
4
+ #include <map>
5
+ #include <mysql++.h>
6
+ #include <boost/thread/mutex.hpp>
7
+ #include "pporm.h"
8
+
9
+
10
+ class DBFace{
11
+ public:
12
+ static DBFace* instance() { return _this; }
13
+
14
+ DBFace(const std::string& database, const std::string& host,
15
+ const std::string& user, const std::string& password);
16
+
17
+ bool insert(const std::string& table,
18
+ const std::map<std::string, std::string>& field2Val);
19
+ bool update(const std::string& table,
20
+ const std::map<std::string, std::string>& field2Val,
21
+ const std::string& where);
22
+ bool select(const std::string& table,
23
+ const std::vector<std::string>& columns,
24
+ const std::string& where,
25
+ const std::string& additional,
26
+ QueryRes& rRes);
27
+ bool selectTables(QueryRes& rRes);
28
+ bool selectColumns(const std::string& table, QueryRes& rRes);
29
+ void getTables(std::vector<Table>& rTables);
30
+ const std::map<std::string, std::string>& dbtype2BaseType() const
31
+ { return _dbtype2BaseType; }
32
+
33
+ std::string now();
34
+
35
+ private:
36
+ bool executeQuery(mysqlpp::Query& rQuery);
37
+
38
+ private:
39
+ mysqlpp::Connection _connection;
40
+ const std::string _database;
41
+ std::map<std::string, std::string> _dbtype2BaseType;
42
+ mutable boost::mutex _mutex;
43
+ static DBFace* _this;
44
+ };
45
+
46
+
47
+ #endif //DB_H
@@ -0,0 +1,27 @@
1
+ #ifndef PPORM_FIELDS_H
2
+ #define PPORM_FIELDS_H
3
+
4
+ #include <string>
5
+
6
+ #include <sstream>
7
+
8
+ #include "utils.hpp"
9
+
10
+ namespace PPORM {
11
+
12
+ template<class T>
13
+ struct Field{
14
+ Field<T>() :_dirty(false) {}
15
+ typedef T Base;
16
+ bool _dirty;
17
+ T _base;
18
+ }; //class Field
19
+
20
+ typedef Field<int> F_Integer;
21
+ typedef Field<double> F_Float;
22
+ typedef Field<std::string> F_String;
23
+ typedef Field<bool> F_TrueString;
24
+
25
+ } //namespace PPORM
26
+
27
+ #endif //PPORM_FIELDS_H
@@ -0,0 +1,31 @@
1
+ #ifndef PPORM_FIELDS_H
2
+ #define PPORM_FIELDS_H
3
+
4
+ #include <string>
5
+
6
+ #include <sstream>
7
+
8
+ #include "utils.hpp"
9
+
10
+ namespace PPORM {
11
+
12
+ template<class T>
13
+ struct Field{
14
+ Field<T>() :_dirty(false) {}
15
+ typedef T Base;
16
+ bool _dirty;
17
+ T _base;
18
+ }; //class Field
19
+
20
+ typedef Field<int> F_bigint;
21
+ typedef Field<std::string> F_date;
22
+ typedef Field<std::string> F_datetime;
23
+ typedef Field<double> F_float;
24
+ typedef Field<int> F_int;
25
+ typedef Field<std::string> F_text;
26
+ typedef Field<int> F_tinyint;
27
+ typedef Field<std::string> F_varchar;
28
+
29
+ } //namespace PPORM
30
+
31
+ #endif //PPORM_FIELDS_H
@@ -0,0 +1,75 @@
1
+ #ifndef _ID_HPP
2
+ #define _ID_HPP
3
+
4
+ #include <iosfwd>
5
+ #include <string>
6
+ #include <sstream>
7
+
8
+ namespace PPORM{
9
+ template<class T>
10
+ class Id {
11
+
12
+ public:
13
+ explicit Id(size_t id) : _id(id) {}
14
+ Id() {}
15
+
16
+ inline Id operator++() {
17
+ ++_id; return *this;
18
+ }
19
+
20
+ inline Id operator++(int) {
21
+ Id val=*this;
22
+ ++*this;
23
+ return val;
24
+ }
25
+
26
+ inline bool operator==(const Id& that) const {
27
+ return _id == that._id;
28
+ }
29
+ inline bool operator< (const Id& that) const {
30
+ return _id < that._id;
31
+ }
32
+ inline bool operator<=(const Id& that) const {
33
+ return _id <= that._id;
34
+ }
35
+ inline bool operator> (const Id& that) const {
36
+ return _id > that._id;
37
+ }
38
+ inline bool operator!=(const Id& that) const {
39
+ return ! (*this == that);
40
+ }
41
+
42
+ std::string to_s() const {
43
+ std::ostringstream oss;
44
+ oss << _id;
45
+ return oss.str();
46
+ }
47
+
48
+
49
+ inline size_t& serialization() { return _id; }
50
+
51
+ private:
52
+ size_t _id;
53
+
54
+ };
55
+
56
+
57
+ }; //namespace PPORM
58
+
59
+ template<class T>
60
+ std::ostream&
61
+ operator<< (std::ostream& os, const PPORM::Id<T>& id)
62
+ {
63
+ os << id.to_s();
64
+ return os;
65
+ }
66
+
67
+ template<class T>
68
+ std::istream&
69
+ operator>> (std::istream& is, PPORM::Id<T>& id)
70
+ {
71
+ is >> id.serialization();
72
+ return is;
73
+ }
74
+
75
+ #endif //_ID_HPP
@@ -0,0 +1,208 @@
1
+ #ifndef PPORM_IDENTIFIERS_HPP
2
+ #define PPORM_IDENTIFIERS_HPP
3
+
4
+ #include "id.hpp"
5
+
6
+ namespace PPORM {
7
+
8
+ class DummyO_AccountIssues;
9
+ typedef Id<DummyO_AccountIssues> I_AccountIssues;
10
+
11
+ class DummyO_AccountResearchKeywords;
12
+ typedef Id<DummyO_AccountResearchKeywords> I_AccountResearchKeywords;
13
+
14
+ class DummyO_Accounts;
15
+ typedef Id<DummyO_Accounts> I_Accounts;
16
+
17
+ class DummyO_AdminProps;
18
+ typedef Id<DummyO_AdminProps> I_AdminProps;
19
+
20
+ class DummyO_Assignments;
21
+ typedef Id<DummyO_Assignments> I_Assignments;
22
+
23
+ class DummyO_Backlinks;
24
+ typedef Id<DummyO_Backlinks> I_Backlinks;
25
+
26
+ class DummyO_Broadcasts;
27
+ typedef Id<DummyO_Broadcasts> I_Broadcasts;
28
+
29
+ class DummyO_Canonicals;
30
+ typedef Id<DummyO_Canonicals> I_Canonicals;
31
+
32
+ class DummyO_ClankPages;
33
+ typedef Id<DummyO_ClankPages> I_ClankPages;
34
+
35
+ class DummyO_ClankPlacements;
36
+ typedef Id<DummyO_ClankPlacements> I_ClankPlacements;
37
+
38
+ class DummyO_ClankSourceKeywords;
39
+ typedef Id<DummyO_ClankSourceKeywords> I_ClankSourceKeywords;
40
+
41
+ class DummyO_ClankSources;
42
+ typedef Id<DummyO_ClankSources> I_ClankSources;
43
+
44
+ class DummyO_Competitions;
45
+ typedef Id<DummyO_Competitions> I_Competitions;
46
+
47
+ class DummyO_Contacts;
48
+ typedef Id<DummyO_Contacts> I_Contacts;
49
+
50
+ class DummyO_Diagnostics;
51
+ typedef Id<DummyO_Diagnostics> I_Diagnostics;
52
+
53
+ class DummyO_Differentials;
54
+ typedef Id<DummyO_Differentials> I_Differentials;
55
+
56
+ class DummyO_DriveBackLogs;
57
+ typedef Id<DummyO_DriveBackLogs> I_DriveBackLogs;
58
+
59
+ class DummyO_DriveTasks;
60
+ typedef Id<DummyO_DriveTasks> I_DriveTasks;
61
+
62
+ class DummyO_Emphases;
63
+ typedef Id<DummyO_Emphases> I_Emphases;
64
+
65
+ class DummyO_ErrorReports;
66
+ typedef Id<DummyO_ErrorReports> I_ErrorReports;
67
+
68
+ class DummyO_GoogleSuggestions;
69
+ typedef Id<DummyO_GoogleSuggestions> I_GoogleSuggestions;
70
+
71
+ class DummyO_HashCount;
72
+ typedef Id<DummyO_HashCount> I_HashCount;
73
+
74
+ class DummyO_HistoricalRankingPowers;
75
+ typedef Id<DummyO_HistoricalRankingPowers> I_HistoricalRankingPowers;
76
+
77
+ class DummyO_HistoricalScores;
78
+ typedef Id<DummyO_HistoricalScores> I_HistoricalScores;
79
+
80
+ class DummyO_HttpErrors;
81
+ typedef Id<DummyO_HttpErrors> I_HttpErrors;
82
+
83
+ class DummyO_Images;
84
+ typedef Id<DummyO_Images> I_Images;
85
+
86
+ class DummyO_IssuePageClasses;
87
+ typedef Id<DummyO_IssuePageClasses> I_IssuePageClasses;
88
+
89
+ class DummyO_IssuePages;
90
+ typedef Id<DummyO_IssuePages> I_IssuePages;
91
+
92
+ class DummyO_Issues;
93
+ typedef Id<DummyO_Issues> I_Issues;
94
+
95
+ class DummyO_KeywordExclusions;
96
+ typedef Id<DummyO_KeywordExclusions> I_KeywordExclusions;
97
+
98
+ class DummyO_Keywords;
99
+ typedef Id<DummyO_Keywords> I_Keywords;
100
+
101
+ class DummyO_Links;
102
+ typedef Id<DummyO_Links> I_Links;
103
+
104
+ class DummyO_LoggedActions;
105
+ typedef Id<DummyO_LoggedActions> I_LoggedActions;
106
+
107
+ class DummyO_MirrorLogs;
108
+ typedef Id<DummyO_MirrorLogs> I_MirrorLogs;
109
+
110
+ class DummyO_NonHtmls;
111
+ typedef Id<DummyO_NonHtmls> I_NonHtmls;
112
+
113
+ class DummyO_Notifications;
114
+ typedef Id<DummyO_Notifications> I_Notifications;
115
+
116
+ class DummyO_PageClasses;
117
+ typedef Id<DummyO_PageClasses> I_PageClasses;
118
+
119
+ class DummyO_PageHeaders;
120
+ typedef Id<DummyO_PageHeaders> I_PageHeaders;
121
+
122
+ class DummyO_PageSearchKeywords;
123
+ typedef Id<DummyO_PageSearchKeywords> I_PageSearchKeywords;
124
+
125
+ class DummyO_PageTrackedKeywords;
126
+ typedef Id<DummyO_PageTrackedKeywords> I_PageTrackedKeywords;
127
+
128
+ class DummyO_Pages;
129
+ typedef Id<DummyO_Pages> I_Pages;
130
+
131
+ class DummyO_PlacementContacts;
132
+ typedef Id<DummyO_PlacementContacts> I_PlacementContacts;
133
+
134
+ class DummyO_Rankings;
135
+ typedef Id<DummyO_Rankings> I_Rankings;
136
+
137
+ class DummyO_Redirects;
138
+ typedef Id<DummyO_Redirects> I_Redirects;
139
+
140
+ class DummyO_SavedSearches;
141
+ typedef Id<DummyO_SavedSearches> I_SavedSearches;
142
+
143
+ class DummyO_SearchCompetitionKeywords;
144
+ typedef Id<DummyO_SearchCompetitionKeywords> I_SearchCompetitionKeywords;
145
+
146
+ class DummyO_SearchCompetitions;
147
+ typedef Id<DummyO_SearchCompetitions> I_SearchCompetitions;
148
+
149
+ class DummyO_SearchEngineSearchKeywords;
150
+ typedef Id<DummyO_SearchEngineSearchKeywords> I_SearchEngineSearchKeywords;
151
+
152
+ class DummyO_SearchEngines;
153
+ typedef Id<DummyO_SearchEngines> I_SearchEngines;
154
+
155
+ class DummyO_SearchKeywords;
156
+ typedef Id<DummyO_SearchKeywords> I_SearchKeywords;
157
+
158
+ class DummyO_Searches;
159
+ typedef Id<DummyO_Searches> I_Searches;
160
+
161
+ class DummyO_Sessions;
162
+ typedef Id<DummyO_Sessions> I_Sessions;
163
+
164
+ class DummyO_Settings;
165
+ typedef Id<DummyO_Settings> I_Settings;
166
+
167
+ class DummyO_StatusUpdateTypes;
168
+ typedef Id<DummyO_StatusUpdateTypes> I_StatusUpdateTypes;
169
+
170
+ class DummyO_StatusUpdates;
171
+ typedef Id<DummyO_StatusUpdates> I_StatusUpdates;
172
+
173
+ class DummyO_TableSettings;
174
+ typedef Id<DummyO_TableSettings> I_TableSettings;
175
+
176
+ class DummyO_Taggings;
177
+ typedef Id<DummyO_Taggings> I_Taggings;
178
+
179
+ class DummyO_Tags;
180
+ typedef Id<DummyO_Tags> I_Tags;
181
+
182
+ class DummyO_ToolsCompetitors;
183
+ typedef Id<DummyO_ToolsCompetitors> I_ToolsCompetitors;
184
+
185
+ class DummyO_ToolsResearchKeywords;
186
+ typedef Id<DummyO_ToolsResearchKeywords> I_ToolsResearchKeywords;
187
+
188
+ class DummyO_ToolsSuggestions;
189
+ typedef Id<DummyO_ToolsSuggestions> I_ToolsSuggestions;
190
+
191
+ class DummyO_Tooltips;
192
+ typedef Id<DummyO_Tooltips> I_Tooltips;
193
+
194
+ class DummyO_TrackedBacklinks;
195
+ typedef Id<DummyO_TrackedBacklinks> I_TrackedBacklinks;
196
+
197
+ class DummyO_TrackedKeywords;
198
+ typedef Id<DummyO_TrackedKeywords> I_TrackedKeywords;
199
+
200
+ class DummyO_Users;
201
+ typedef Id<DummyO_Users> I_Users;
202
+
203
+ class DummyO_Wikilinks;
204
+ typedef Id<DummyO_Wikilinks> I_Wikilinks;
205
+
206
+
207
+ } //namespace PPORM
208
+ #endif //PPORM_IDENTIFIERS_HPP
@@ -0,0 +1,8 @@
1
+ #include "dmmm_utils.hpp"
2
+
3
+ template<>
4
+ std::string
5
+ fromString<std::string>(const std::string& s)
6
+ {
7
+ return s;
8
+ }
@@ -0,0 +1,39 @@
1
+ #ifndef UTILS_HPP
2
+ #define UTILS_HPP
3
+
4
+ #include <vector>
5
+ #include <map>
6
+ #include <sstream>
7
+
8
+ template<class T>
9
+ std::string
10
+ toString(const T& t)
11
+ {
12
+ std::ostringstream oss;
13
+ oss << t;
14
+
15
+ return oss.str();
16
+ }
17
+
18
+ template<class T>
19
+ T
20
+ fromString(const std::string& s)
21
+ {
22
+ std::istringstream iss;
23
+ iss.str(s);
24
+
25
+ T ret;
26
+ iss >> ret;
27
+
28
+ return ret;
29
+ }
30
+
31
+ template<>
32
+ std::string
33
+ fromString<std::string>(const std::string& s)
34
+ {
35
+ return s;
36
+ }
37
+
38
+
39
+ #endif //UTILS_HPP
@@ -18,7 +18,7 @@
18
18
  <%# end %>
19
19
 
20
20
  <% model.enums.each do |name, property| %>
21
- enum Enum<%= class_name %><%= name %> { <%= property.type.flag_map.map{|v, k| class_name.upcase + "_" + property.name.to_s.upcase + "_" + k.to_s.sub(".","_").upcase + " = " + v.to_s}.join(", ") %> };
21
+ enum Enum<%= class_name %><%= name %> { <%= property.flag_map.map{|v, k| class_name.upcase + "_" + property.name.to_s.upcase + "_" + k.to_s.sub(".","_").upcase + " = " + v.to_s}.join(", ") %> };
22
22
  <% end %>
23
23
 
24
24
  namespace DMMM {
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-metamapper
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
8
+ - 1
7
9
  - 0
8
- - 11
9
- version: 0.0.11
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jonah Honeyman
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-08-08 00:00:00 -04:00
19
+ date: 2010-12-19 00:00:00 +02:00
19
20
  default_executable:
20
21
  dependencies: []
21
22
 
@@ -28,38 +29,35 @@ extensions: []
28
29
  extra_rdoc_files:
29
30
  - README.md
30
31
  files:
31
- - .autospec
32
- - .gitignore
33
- - Gemfile
34
- - README.md
35
- - Rakefile
36
- - VERSION
37
- - example/.gitignore
38
- - example/Makefile
39
- - example/example.cpp
40
- - example/example.rb
41
- - lib/dm-metamapper.rb
42
- - lib/dm-metamapper/config.rb
43
32
  - lib/dm-metamapper/generator.rb
44
- - lib/dm-metamapper/generators/cpp.rb
45
- - lib/dm-metamapper/metamapper.rb
46
33
  - lib/dm-metamapper/model.rb
34
+ - lib/dm-metamapper/config.rb
35
+ - lib/dm-metamapper/generators/cpp.rb
47
36
  - lib/dm-metamapper/property.rb
37
+ - lib/dm-metamapper/version.rb
38
+ - lib/dm-metamapper/metamapper.rb
48
39
  - lib/dm-metamapper/template.rb
49
- - lib/templates/cpp/class.hpp.erb
50
- - lib/templates/cpp/dmmm_comparators.hpp.erb
40
+ - lib/dm-metamapper.rb
41
+ - lib/templates/cpp/dmmm_fields.hpp~
51
42
  - lib/templates/cpp/dmmm_dbface.cpp.erb
52
- - lib/templates/cpp/dmmm_dbface.h.erb
43
+ - lib/templates/cpp/dmmm_utils.hpp~
44
+ - lib/templates/cpp/dmmm_id.h~
45
+ - lib/templates/cpp/dmmm_identifiers.hpp.erb
46
+ - lib/templates/cpp/dmmm_utils.cpp.erb~
47
+ - lib/templates/cpp/dmmm_dbface.h~
48
+ - lib/templates/cpp/dmmm_fields.hpp.erb~
49
+ - lib/templates/cpp/dmmm_comparators.hpp~
50
+ - lib/templates/cpp/dmmm_comparators.hpp.erb
53
51
  - lib/templates/cpp/dmmm_fields.hpp.erb
52
+ - lib/templates/cpp/dmmm_dbface.h.erb
53
+ - lib/templates/cpp/instance.hpp.erb
54
54
  - lib/templates/cpp/dmmm_id.hpp.erb
55
- - lib/templates/cpp/dmmm_identifiers.hpp.erb
56
55
  - lib/templates/cpp/dmmm_utils.cpp.erb
56
+ - lib/templates/cpp/dmmm_dbface.cpp~
57
57
  - lib/templates/cpp/dmmm_utils.hpp.erb
58
- - lib/templates/cpp/instance.hpp.erb
59
- - spec/dm-metamapper/generator_spec.rb
60
- - spec/dm-metamapper/template_spec.rb
61
- - spec/spec.opts
62
- - spec/spec_helper.rb
58
+ - lib/templates/cpp/class.hpp.erb
59
+ - lib/templates/cpp/dmmm_identifiers.hpp~
60
+ - README.md
63
61
  has_rdoc: true
64
62
  homepage: http://github.com/jonuts/dm-metamapper
65
63
  licenses: []
@@ -70,27 +68,31 @@ rdoc_options:
70
68
  require_paths:
71
69
  - lib
72
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
73
72
  requirements:
74
73
  - - ">="
75
74
  - !ruby/object:Gem::Version
75
+ hash: 3
76
76
  segments:
77
77
  - 0
78
78
  version: "0"
79
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
80
81
  requirements:
81
82
  - - ">="
82
83
  - !ruby/object:Gem::Version
84
+ hash: 23
83
85
  segments:
84
- - 0
85
- version: "0"
86
+ - 1
87
+ - 3
88
+ - 6
89
+ version: 1.3.6
86
90
  requirements: []
87
91
 
88
- rubyforge_project:
89
- rubygems_version: 1.3.6
92
+ rubyforge_project: dm-metamapper
93
+ rubygems_version: 1.3.7
90
94
  signing_key:
91
95
  specification_version: 3
92
96
  summary: Code generating C++ ORM
93
- test_files:
94
- - spec/spec_helper.rb
95
- - spec/dm-metamapper/generator_spec.rb
96
- - spec/dm-metamapper/template_spec.rb
97
+ test_files: []
98
+
data/.autospec DELETED
@@ -1,6 +0,0 @@
1
- Autotest.add_hook :reset do |at|
2
- at.clear_mappings
3
- at.add_exception(/\.git/)
4
- at.add_mapping(%r{^spec/.*_spec}) {|name,_| at.files_matching(/#{name}/)}
5
- at.add_mapping(//) {|_,_| at.files_matching %r{spec/.*_spec}}
6
- end
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- *~
2
- *.sw[p|o]
3
- .bundle/*
4
- .rvmrc
5
- *.gem
6
- output
data/Gemfile DELETED
@@ -1,22 +0,0 @@
1
- source :rubygems
2
-
3
- dm_gems_version = "~> 0.10"
4
- do_gems_version = "~> 0.10"
5
-
6
- gem "dm-core", dm_gems_version
7
- gem "dm-types", dm_gems_version
8
-
9
-
10
- group :test do
11
- gem "rspec"
12
- gem "data_objects"
13
- gem "do_sqlite3", do_gems_version
14
- gem "do_mysql", do_gems_version
15
- gem "ZenTest"
16
- end
17
-
18
- group :deploy do
19
- gem "jeweler"
20
- end
21
-
22
- # vim: set ft=ruby:
data/Rakefile DELETED
@@ -1,24 +0,0 @@
1
- begin
2
- require 'bundler'
3
- Bundler.setup :deploy
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gemspec|
6
- gemspec.name = "dm-metamapper"
7
- gemspec.summary = "Code generating C++ ORM"
8
- gemspec.description = "C++ API for databases created with DM. Hard typing, compile time checked queries."
9
- gemspec.email = "jonah@honeyman.org"
10
- gemspec.homepage = "http://github.com/jonuts/dm-metamapper"
11
- gemspec.authors = ["Jonah Honeyman", "Omer Tamuz"]
12
- end
13
- rescue LoadError
14
- puts "Jeweler not available. Install it with: gem install jeweler"
15
- end
16
-
17
- desc "local gem build and install"
18
- task :local do
19
- sh "rvm ree@drive"
20
- sh "gem uninstall -a dm-metamapper"
21
- sh "gem build dm-metamapper.gemspec"
22
- version = File.read("VERSION").chomp
23
- sh "gem install -l ./dm-metamapper-#{version}.gem"
24
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.11
data/example/.gitignore DELETED
@@ -1 +0,0 @@
1
- example
data/example/Makefile DELETED
@@ -1,4 +0,0 @@
1
- all:
2
- echo "generating code"
3
- cd ..; bundle exec ruby -r example/example.rb -e "DataMapper::MetaMapper.generate(:cpp, :output_dir => './output')"
4
- g++ ../output/dmmm_utils.cpp ../output/dmmm_dbface.cpp example.cpp -I ../output -I /usr/include/mysql -I /usr/local/include/mysql++ -I /usr/local/mysql/include/mysql -lmysqlpp -lmysqlclient /usr/lib/libboost_thread-mt.so -L/usr/lib -L/usr/local/lib -Wall -o example
data/example/example.cpp DELETED
@@ -1,78 +0,0 @@
1
- #include <vector>
2
- #include "dmmm_dbface.h"
3
- #include "T_User.hpp"
4
- #include "T_Dog.hpp"
5
- #include "T_LittleFlea.hpp"
6
-
7
- using namespace std;
8
- using namespace DMMM;
9
-
10
- int main(int argc, char* argv[])
11
- {
12
- string host("localhost");
13
- string user("root");
14
- string database("dmmm");
15
- string password("");
16
- DBFace dbFace(database, host, user, password, &cout);
17
-
18
- T_Dog d;
19
- T_User u;
20
- d.erase();
21
- u.erase();
22
-
23
- O_User u1;
24
- u1._name() = "omer";
25
- u1._balance() = 5.3;
26
- u1._weight() = 10;
27
- u1.insert();
28
-
29
- O_Dog d1;
30
- d1._user_id() = u1._id();
31
- d1._name() = "spot";
32
- d1._stinks() = true;
33
- d1._color() = DOG_COLOR_WHITE;
34
- d1.insert();
35
-
36
- d1 = d.select(d1._id()).first;
37
-
38
- O_Dog d2(u1);
39
- d2._name() = "rover";
40
- d2._stinks() = false;
41
- d2.insert();
42
-
43
- O_User u2;
44
- u2._name() = "jonah";
45
- u2.insert();
46
-
47
- O_Dog d3(u2._id());
48
- d3._name() = "rover";
49
- d3._stinks() = false;
50
- d3.insert();
51
-
52
- O_LittleFlea f1(d3);
53
- f1.insert();
54
-
55
- vector<O_Dog> dogs;
56
- d.select((d._stinks() == false) && (d._name() %= "\%over"), dogs);
57
- for(size_t i = 0; i < dogs.size(); ++i){
58
- dogs[i]._name() = string("good_") + dogs[i]._name();
59
- dogs[i].update();
60
- cout << dogs[i]._name()
61
- << " belongs to " << dogs[i].user().first._name()
62
- << endl;
63
- }
64
-
65
-
66
- T_Dog dconst(T_User(u._name() == "omer"));
67
- dogs.clear();
68
- dconst.select(d._stinks() == true, dogs);
69
- cout << dogs.size()
70
- << " dogs meet criterion" << endl;
71
- cout << dconst.count(d._stinks() == true)
72
- << " dogs meet criterion" << endl;
73
- dconst.erase();
74
-
75
- d.erase(d._user_id() == u2._id());
76
-
77
- return 0;
78
- }
data/example/example.rb DELETED
@@ -1,50 +0,0 @@
1
- require "erb"
2
- require "rubygems"
3
- require "bundler"
4
- Bundler.setup(:default, :test)
5
- require "dm-core"
6
- require "dm-types"
7
- require File.expand_path("../../lib/dm-metamapper.rb", __FILE__)
8
- require "dm-metamapper/generators/cpp"
9
-
10
- #DataMapper.setup(:default, "sqlite3::memory:")
11
- DataMapper.setup(:default, "mysql://root@localhost/dmmm")
12
-
13
- COLORS = [
14
- :blue,
15
- :white,
16
- "light.red"
17
- ]
18
-
19
- class User
20
- include DataMapper::Resource
21
-
22
- has n, :dogs
23
-
24
- property :id, Serial
25
- property :name, String
26
- property :balance, Float
27
- property :weight, Integer
28
- end
29
-
30
- class Dog
31
- include DataMapper::Resource
32
-
33
- belongs_to :user
34
- has n, :little_fleas
35
-
36
- property :id, Serial
37
- property :user_id, Integer
38
- property :name, String
39
- property :color, Enum[*COLORS]
40
- property :stinks, Boolean
41
- end
42
-
43
- class LittleFlea
44
- include DataMapper::Resource
45
-
46
- belongs_to :dog
47
-
48
- property :id, Serial
49
- property :dog_id, Integer
50
- end
@@ -1,62 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- class MyGenerator < DMMM::Generator;end
4
-
5
- class LolModel
6
- include DataMapper::Resource
7
-
8
- property :id, Serial
9
- property :name, String
10
- end
11
-
12
- describe "Generator" do
13
- describe "General" do
14
- it "is configurable" do
15
- MyGenerator.config.should == DMMM.instance_variable_get(:@_default_opts)
16
- end
17
-
18
- it "stores a block to extend models" do
19
- blk = proc { @__foo__ = "lol" }
20
- MyGenerator.send(:setup_model, &blk)
21
- MyGenerator.setup_model_blk.should == blk
22
- end
23
- end
24
-
25
- describe "Templates" do
26
- it "has a template store" do
27
- DMMM::TemplateCollection.should === MyGenerator.generated_files
28
- end
29
-
30
- it "stores template info" do
31
- MyGenerator.send(:generates_file, :model, "foo")
32
- MyGenerator.generated_files.size.should == 1
33
- MyGenerator.generated_files.first.name.should == "foo"
34
- end
35
- end
36
-
37
- describe ".new" do
38
- before :each do
39
- MyGenerator.instance_variable_set :@generated_files, DMMM::TemplateCollection.new
40
- model_files = ["foo", "bar", "baz", "bleh"]
41
-
42
- model_files.each do |f|
43
- MyGenerator.send :generates_file, :model, f
44
- end
45
- end
46
-
47
- it "requires model info" do
48
- lambda {MyGenerator.new}.should raise_error(ArgumentError)
49
- end
50
-
51
- it "has model templates when called with model" do
52
- @generator = MyGenerator.new(LolModel)
53
- @generator.instance_variable_get(:@templates).should == MyGenerator.generated_files.models
54
- end
55
-
56
- it "has global templates when called without model" do
57
- @generator = MyGenerator.new nil
58
- @generator.instance_variable_get(:@templates).should == MyGenerator.generated_files.global
59
- end
60
- end
61
- end
62
-
@@ -1,29 +0,0 @@
1
- require File.expand_path("../../spec_helper", __FILE__)
2
-
3
- class LolGenerator < DMMM::Generator; end
4
-
5
- describe "Template" do
6
- describe "invalid" do
7
- it "requires a name" do
8
- lambda {DMMM::Template.new}.should raise_error(ArgumentError)
9
- end
10
-
11
- it "requires a generator" do
12
- lambda {DMMM::Template.new(:foo)}.should raise_error(DMMM::NoGeneratorError)
13
- end
14
-
15
- it "requires a valid type" do
16
- lambda {DMMM::Template.new(:few, generator: LolGenerator)}.
17
- should raise_error(DMMM::InvalidTypeError)
18
- end
19
- end
20
-
21
- describe "valid" do
22
- before :all do
23
- @template = DMMM::Template.new :foo,
24
- generator: LolGenerator,
25
- type: :global
26
- end
27
- end
28
- end
29
-
data/spec/spec.opts DELETED
@@ -1,4 +0,0 @@
1
- --colour
2
- --loadby random
3
- --format profile
4
- --backtrace
data/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- $:.push File.expand_path('../lib', __FILE__)
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- Bundler.setup(:default, :test)
6
- require 'spec'
7
-
8
- require 'dm-metamapper'
9
-
10
- DMMM = DataMapper::MetaMapper