sqlpp11gen 0.1.1
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.
- checksums.yaml +7 -0
- data/README.md +190 -0
- data/Rakefile +6 -0
- data/app/controllers/cxxes_controller.rb +8 -0
- data/app/helpers/cxxes_helper.rb +50 -0
- data/app/views/cxxes/index.h.erb +67 -0
- data/lib/generators/sqlpp11gen/USAGE +8 -0
- data/lib/generators/sqlpp11gen/cxxes_context.rb +12 -0
- data/lib/generators/sqlpp11gen/cxxes_helper.rb +50 -0
- data/lib/generators/sqlpp11gen/tab_generator.rb +101 -0
- data/lib/generators/sqlpp11gen/templates/index.h.erb +67 -0
- data/lib/sqlpp11gen/engine.rb +4 -0
- data/lib/sqlpp11gen/version.rb +3 -0
- data/lib/sqlpp11gen.rb +28 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0944c15116b2c3358fd67ddecc62bc4debaa8f4a
|
4
|
+
data.tar.gz: edba7f7977392c8b5afa416e1b9398ec4c48e7c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3cc6f62c9dcd33a0e05b6e77088c522870425b0d88838193b47cdf38e8d46997d5dba302059c1a81869e41f6469c37c3dea7986a572e67bdc511a0a781d375a9
|
7
|
+
data.tar.gz: ca5033b8743cce17f1fed23e5b0197091d3b8a9c2d674d9829b576067f0ee27bd9d5d8c0c18b597151b06c3168a3e569e1b3760d9672bb80b60c4c675f3a46d1
|
data/README.md
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
# Sqlpp11gen
|
2
|
+
|
3
|
+
sqlpp11gen is a c++ table class generator for [sqlpp11](https://github.com/rbock/sqlpp11).
|
4
|
+
|
5
|
+
NOTE: This gem is not published yet, but you can install it manually. Someday I will fix it. If you're familiar with ruby gems, you can help fix it.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
### Manual install
|
10
|
+
|
11
|
+
(1) downlod the source code and copy `app` folder to the `app` folder of your Rails project.
|
12
|
+
Make sure the following files exist in your project:
|
13
|
+
```ruby
|
14
|
+
app/controllers/cxxes_controller.rb
|
15
|
+
app/helpers/cxxes_helper.rb
|
16
|
+
app/views/cxxes/index.h.erb
|
17
|
+
```
|
18
|
+
|
19
|
+
(2) add a route in config/routes.rb
|
20
|
+
``` ruby
|
21
|
+
# config/routes.rb
|
22
|
+
resources :cxxes
|
23
|
+
```
|
24
|
+
|
25
|
+
(3) register a new MIME type in config/initializers/mime_types.rb
|
26
|
+
```ruby
|
27
|
+
# config/initializers/mime_types.rb
|
28
|
+
Mime::Type.register "text/plain", :h
|
29
|
+
```
|
30
|
+
|
31
|
+
That's it! Now ignite your rails app!
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Assume that a 'users' table already exists, browse 'http://localhost:3000/cxxes.h'.
|
36
|
+
|
37
|
+
If not, browse 'http://localhost:3000/cxxes.h?model=YourModelName'. e.g. for Product model, browse 'http://localhost:3000/cxxes.h?model=Product'.
|
38
|
+
|
39
|
+
### Step by step
|
40
|
+
|
41
|
+
#### create your table
|
42
|
+
Let's create a table named 'Product'.
|
43
|
+
|
44
|
+
```
|
45
|
+
$ rails g scaffold Product name:string price:decimal
|
46
|
+
$ rake db:migrate
|
47
|
+
$ rails s
|
48
|
+
```
|
49
|
+
|
50
|
+
#### browse
|
51
|
+
Browse 'http://localhost:3000/cxxes.h?model=Product'. The output will be:
|
52
|
+
|
53
|
+
```c++
|
54
|
+
// WARNING; don't change this file manually. This file is generated by sqlpp11gen!
|
55
|
+
#ifndef SQLPP_TAB_PRODUCT_H
|
56
|
+
#define SQLPP_TAB_PRODUCT_H
|
57
|
+
|
58
|
+
#include <sqlpp11/table.h>
|
59
|
+
#include <sqlpp11/char_sequence.h>
|
60
|
+
#include <sqlpp11/column_types.h>
|
61
|
+
|
62
|
+
//
|
63
|
+
// table: Product
|
64
|
+
// fields: 5
|
65
|
+
// id integer false integer
|
66
|
+
// name string true varchar
|
67
|
+
// price decimal true decimal
|
68
|
+
// created_at datetime false datetime
|
69
|
+
// updated_at datetime false datetime
|
70
|
+
//
|
71
|
+
|
72
|
+
namespace TabProduct_ {
|
73
|
+
struct Id {
|
74
|
+
struct _alias_t {
|
75
|
+
static constexpr const char _literal[] = "id";
|
76
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
77
|
+
template <typename T>
|
78
|
+
struct _member_t {
|
79
|
+
T id;
|
80
|
+
T& operator()() { return id; }
|
81
|
+
const T& operator()() const { return id; }
|
82
|
+
};
|
83
|
+
};
|
84
|
+
using _traits = sqlpp::make_traits<sqlpp::integer>;
|
85
|
+
};
|
86
|
+
struct Name {
|
87
|
+
struct _alias_t {
|
88
|
+
static constexpr const char _literal[] = "name";
|
89
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
90
|
+
template <typename T>
|
91
|
+
struct _member_t {
|
92
|
+
T name;
|
93
|
+
T& operator()() { return name; }
|
94
|
+
const T& operator()() const { return name; }
|
95
|
+
};
|
96
|
+
};
|
97
|
+
using _traits = sqlpp::make_traits<sqlpp::varchar, sqlpp::tag::can_be_null>;
|
98
|
+
};
|
99
|
+
struct Price {
|
100
|
+
struct _alias_t {
|
101
|
+
static constexpr const char _literal[] = "price";
|
102
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
103
|
+
template <typename T>
|
104
|
+
struct _member_t {
|
105
|
+
T price;
|
106
|
+
T& operator()() { return price; }
|
107
|
+
const T& operator()() const { return price; }
|
108
|
+
};
|
109
|
+
};
|
110
|
+
using _traits = sqlpp::make_traits<sqlpp::floating_point, sqlpp::tag::can_be_null>;
|
111
|
+
};
|
112
|
+
struct CreatedAt {
|
113
|
+
struct _alias_t {
|
114
|
+
static constexpr const char _literal[] = "created_at";
|
115
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
116
|
+
template <typename T>
|
117
|
+
struct _member_t {
|
118
|
+
T created_at;
|
119
|
+
T& operator()() { return created_at; }
|
120
|
+
const T& operator()() const { return created_at; }
|
121
|
+
};
|
122
|
+
};
|
123
|
+
using _traits = sqlpp::make_traits<sqlpp::time_point>;
|
124
|
+
};
|
125
|
+
struct UpdatedAt {
|
126
|
+
struct _alias_t {
|
127
|
+
static constexpr const char _literal[] = "updated_at";
|
128
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
129
|
+
template <typename T>
|
130
|
+
struct _member_t {
|
131
|
+
T updated_at;
|
132
|
+
T& operator()() { return updated_at; }
|
133
|
+
const T& operator()() const { return updated_at; }
|
134
|
+
};
|
135
|
+
};
|
136
|
+
using _traits = sqlpp::make_traits<sqlpp::time_point>;
|
137
|
+
};
|
138
|
+
} // namespace TabProduct_
|
139
|
+
|
140
|
+
struct TabProduct : sqlpp::table_t<TabProduct
|
141
|
+
, TabProduct_::Id
|
142
|
+
, TabProduct_::Name
|
143
|
+
, TabProduct_::Price
|
144
|
+
, TabProduct_::CreatedAt
|
145
|
+
, TabProduct_::UpdatedAt
|
146
|
+
>
|
147
|
+
{
|
148
|
+
using _value_type = sqlpp::no_value_t;
|
149
|
+
struct _alias_t {
|
150
|
+
static constexpr const char _literal[] = "products";
|
151
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
152
|
+
template <typename T>
|
153
|
+
struct _member_t {
|
154
|
+
T tabProduct;
|
155
|
+
T& operator()() { return tabProduct; }
|
156
|
+
const T& operator()() const { return tabProduct; }
|
157
|
+
};
|
158
|
+
};
|
159
|
+
};
|
160
|
+
|
161
|
+
struct ProductData {
|
162
|
+
ProductData() : id(0), price(0.0f) {}
|
163
|
+
std::int64_t id ; // false integer
|
164
|
+
std::string name ; // true varchar
|
165
|
+
double price ; // true decimal
|
166
|
+
sqlpp::chrono::microsecond_point created_at ; // false datetime
|
167
|
+
sqlpp::chrono::microsecond_point updated_at ; // false datetime
|
168
|
+
};
|
169
|
+
|
170
|
+
#endif // SQLPP_TAB_PRODUCT_H
|
171
|
+
```
|
172
|
+
|
173
|
+
#### copy and paste the code!
|
174
|
+
|
175
|
+
|
176
|
+
## Development
|
177
|
+
|
178
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
179
|
+
|
180
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
181
|
+
|
182
|
+
## Contributing
|
183
|
+
|
184
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sqlpp11gen. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
185
|
+
|
186
|
+
|
187
|
+
## License
|
188
|
+
|
189
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
190
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module CxxesHelper
|
2
|
+
|
3
|
+
def coltype2ctype(coltype)
|
4
|
+
if coltype == 'integer' then
|
5
|
+
ctype = 'std::int64_t'
|
6
|
+
elsif coltype == 'string' || coltype == 'text' then
|
7
|
+
ctype = 'std::string'
|
8
|
+
elsif coltype == 'datetime' or coltype.start_with?("timestamp") then
|
9
|
+
ctype = 'sqlpp::chrono::microsecond_point'
|
10
|
+
elsif coltype == 'decimal' then
|
11
|
+
ctype = 'double'
|
12
|
+
elsif coltype == 'boolean' then
|
13
|
+
ctype = 'bool'
|
14
|
+
else
|
15
|
+
ctype = coltype
|
16
|
+
end
|
17
|
+
ctype
|
18
|
+
end
|
19
|
+
|
20
|
+
def sqlpptype(coltype)
|
21
|
+
case coltype
|
22
|
+
when /datetime/, /\Atimestamp/
|
23
|
+
"time_point"
|
24
|
+
when /decimal/, /numeric/
|
25
|
+
"floating_point"
|
26
|
+
when /character varying/, /\Avarchar/
|
27
|
+
"varchar"
|
28
|
+
when /int/
|
29
|
+
"integer"
|
30
|
+
else
|
31
|
+
coltype
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def buildCtor(cols)
|
36
|
+
a = []
|
37
|
+
cols.each do |col|
|
38
|
+
coltype = col.type.to_s
|
39
|
+
if coltype == 'integer'
|
40
|
+
a << col.name + '(0)'
|
41
|
+
elsif coltype == 'boolean'
|
42
|
+
a << col.name + '(false)'
|
43
|
+
elsif coltype == 'decimal'
|
44
|
+
a << col.name + '(0.0f)'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
a.join(', ')
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
// WARNING; don't change this file manually. This file is generated by sqlpp11gen!
|
2
|
+
#ifndef SQLPP_TAB_<%= @tablename.upcase %>_H
|
3
|
+
#define SQLPP_TAB_<%= @tablename.upcase %>_H
|
4
|
+
|
5
|
+
#include <sqlpp11/table.h>
|
6
|
+
#include <sqlpp11/char_sequence.h>
|
7
|
+
#include <sqlpp11/column_types.h>
|
8
|
+
|
9
|
+
//
|
10
|
+
// table: <%= @tablename %>
|
11
|
+
// fields: <%= @cols.length%>
|
12
|
+
<% @cols.each do |col| %>
|
13
|
+
// <%= " %-30s %-10s %-10s %s" % [col.name, col.type, col.null, col.sql_type.downcase] %>
|
14
|
+
<% end %>
|
15
|
+
//
|
16
|
+
|
17
|
+
namespace Tab<%= @tablename%>_ {
|
18
|
+
<% @cols.each do |col| %>
|
19
|
+
struct <%= col.name.camelcase %> {
|
20
|
+
struct _alias_t {
|
21
|
+
static constexpr const char _literal[] = "<%= col.name%>";
|
22
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
23
|
+
template <typename T>
|
24
|
+
struct _member_t {
|
25
|
+
T <%= col.name %>;
|
26
|
+
T& operator()() { return <%= col.name %>; }
|
27
|
+
const T& operator()() const { return <%= col.name %>; }
|
28
|
+
};
|
29
|
+
};
|
30
|
+
<%
|
31
|
+
#sqltype = col.sql_type.downcase
|
32
|
+
#sqltype = 'time_point' if sqltype == 'datetime'
|
33
|
+
#sqltype = 'floating_point' if sqltype == 'decimal'
|
34
|
+
sqltype = sqlpptype(col.sql_type.downcase)
|
35
|
+
%>
|
36
|
+
using _traits = sqlpp::make_traits<sqlpp::<%= sqltype %><% if col.null %>, sqlpp::tag::can_be_null<%end%>>;
|
37
|
+
};
|
38
|
+
<% end %>
|
39
|
+
} // namespace Tab<%= @tablename %>_
|
40
|
+
|
41
|
+
struct Tab<%= @tablename %> : sqlpp::table_t<Tab<%= @tablename%>
|
42
|
+
<% @cols.each do |col|%>
|
43
|
+
, Tab<%= @tablename %>_::<%= col.name.camelcase %>
|
44
|
+
<% end%> >
|
45
|
+
{
|
46
|
+
using _value_type = sqlpp::no_value_t;
|
47
|
+
struct _alias_t {
|
48
|
+
static constexpr const char _literal[] = "<%= @tableklass.table_name %>";
|
49
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
50
|
+
template <typename T>
|
51
|
+
struct _member_t {
|
52
|
+
T tab<%= @tablename %>;
|
53
|
+
T& operator()() { return tab<%= @tablename %>; }
|
54
|
+
const T& operator()() const { return tab<%= @tablename %>; }
|
55
|
+
};
|
56
|
+
};
|
57
|
+
};
|
58
|
+
|
59
|
+
struct <%= @tablename%>Data {
|
60
|
+
<%= @tablename%>Data() : <%= buildCtor(@cols) %> {}
|
61
|
+
<% @cols.each do |col| %>
|
62
|
+
<% ctype = coltype2ctype(col.type.to_s) %>
|
63
|
+
<%= " %-32s %-25s; // %-10s %s" % [ctype, col.name, col.null, col.sql_type.downcase] %>
|
64
|
+
<% end %>
|
65
|
+
};
|
66
|
+
|
67
|
+
#endif // SQLPP_TAB_<%= @tablename.upcase %>_H
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module CxxesHelper
|
2
|
+
|
3
|
+
def coltype2ctype(coltype)
|
4
|
+
if coltype == 'integer' then
|
5
|
+
ctype = 'std::int64_t'
|
6
|
+
elsif coltype == 'string' || coltype == 'text' then
|
7
|
+
ctype = 'std::string'
|
8
|
+
elsif coltype == 'datetime' or coltype.start_with?("timestamp") then
|
9
|
+
ctype = 'sqlpp::chrono::microsecond_point'
|
10
|
+
elsif coltype == 'decimal' then
|
11
|
+
ctype = 'double'
|
12
|
+
elsif coltype == 'boolean' then
|
13
|
+
ctype = 'bool'
|
14
|
+
else
|
15
|
+
ctype = coltype
|
16
|
+
end
|
17
|
+
ctype
|
18
|
+
end
|
19
|
+
|
20
|
+
def sqlpptype(coltype)
|
21
|
+
case coltype
|
22
|
+
when /datetime/, /\Atimestamp/
|
23
|
+
"time_point"
|
24
|
+
when /decimal/, /numeric/
|
25
|
+
"floating_point"
|
26
|
+
when /character varying/, /\Avarchar/
|
27
|
+
"varchar"
|
28
|
+
when /int/
|
29
|
+
"integer"
|
30
|
+
else
|
31
|
+
coltype
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def buildCtor(cols)
|
36
|
+
a = []
|
37
|
+
cols.each do |col|
|
38
|
+
coltype = col.type.to_s
|
39
|
+
if coltype == 'integer'
|
40
|
+
a << col.name + '(0)'
|
41
|
+
elsif coltype == 'boolean'
|
42
|
+
a << col.name + '(false)'
|
43
|
+
elsif coltype == 'decimal'
|
44
|
+
a << col.name + '(0.0f)'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
a.join(', ')
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'active_record'
|
3
|
+
require 'generators/sqlpp11gen/cxxes_context'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
module Sqlpp11gen
|
7
|
+
module Generators
|
8
|
+
class TabGenerator < Rails::Generators::NamedBase
|
9
|
+
# source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
# Commandline options can be defined here using Thor-like options:
|
12
|
+
argument :output_path, :type => :string, :required => false, :desc => "setup output path for the generated file. The default output path is 'app/cxxes'."
|
13
|
+
argument :filename_prefix, :type => :string, :required => false, :desc => "setup a filename prefix for the generated file. The default one is 'tab_'."
|
14
|
+
argument :filename_ext, :type => :string, :required => false, :desc => "setup a filename ext for the generated file. The default one is 'hpp'."
|
15
|
+
|
16
|
+
def self.source_root
|
17
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(args, *options)
|
21
|
+
super(args, *options)
|
22
|
+
initialize_views_variables
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_cxx_header_file
|
26
|
+
|
27
|
+
tableklass = table_name.to_s.singularize.camelize.constantize
|
28
|
+
|
29
|
+
ctx = ::CxxesContext.new
|
30
|
+
ctx.tablename = table_name
|
31
|
+
ctx.tableklass = tableklass
|
32
|
+
ctx.cols = tableklass.columns
|
33
|
+
|
34
|
+
template = File.read(File.join(File.dirname(__FILE__), "templates", "index.h.erb"))
|
35
|
+
|
36
|
+
path = output_path || 'app/cxxes'
|
37
|
+
prefix = filename_prefix || 'tab_'
|
38
|
+
ext = filename_ext || 'hpp'
|
39
|
+
|
40
|
+
create_file "#{path}/#{prefix}#{file_name}.#{ext}", ERB.new(template).result(ctx.template_binding)
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
def initialize_views_variables
|
47
|
+
end
|
48
|
+
|
49
|
+
def columns
|
50
|
+
retrieve_columns.reject {|c| excluded?(c.name) }.map do |c|
|
51
|
+
new_attribute(c.name, c.type.to_s)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def excluded_columns_names
|
56
|
+
%w[_id _type id created_at updated_at]
|
57
|
+
end
|
58
|
+
|
59
|
+
def excluded_columns_pattern
|
60
|
+
[
|
61
|
+
/.*_checksum/,
|
62
|
+
/.*_count/,
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
def excluded_columns
|
67
|
+
options['excluded_columns']||[]
|
68
|
+
end
|
69
|
+
|
70
|
+
def excluded?(name)
|
71
|
+
excluded_columns_names.include?(name) ||
|
72
|
+
excluded_columns_pattern.any? {|p| name =~ p } ||
|
73
|
+
excluded_columns.include?(name)
|
74
|
+
end
|
75
|
+
|
76
|
+
def retrieve_columns
|
77
|
+
if defined?(ActiveRecord) == "constant" && ActiveRecord.class == Module
|
78
|
+
rescue_block ActiveRecord::StatementInvalid do
|
79
|
+
@model_name.constantize.columns
|
80
|
+
end
|
81
|
+
else
|
82
|
+
rescue_block do
|
83
|
+
@model_name.constantize.fields.map {|c| c[1] }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def new_attribute(name, type)
|
89
|
+
::Rails::Generators::GeneratedAttribute.new(name, type)
|
90
|
+
end
|
91
|
+
|
92
|
+
def rescue_block(exception=Exception)
|
93
|
+
yield if block_given?
|
94
|
+
rescue exception => e
|
95
|
+
say e.message, :red
|
96
|
+
exit
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
// WARNING; don't change this file manually. This file is generated by sqlpp11gen!
|
2
|
+
#ifndef SQLPP_TAB_<%= @tablename.upcase %>_H
|
3
|
+
#define SQLPP_TAB_<%= @tablename.upcase %>_H
|
4
|
+
|
5
|
+
#include <sqlpp11/table.h>
|
6
|
+
#include <sqlpp11/char_sequence.h>
|
7
|
+
#include <sqlpp11/column_types.h>
|
8
|
+
|
9
|
+
//
|
10
|
+
// table: <%= @tablename %>
|
11
|
+
// fields: <%= @cols.length%>
|
12
|
+
<% @cols.each do |col| %>
|
13
|
+
// <%= " %-30s %-10s %-10s %s" % [col.name, col.type, col.null, col.sql_type.downcase] %>
|
14
|
+
<% end %>
|
15
|
+
//
|
16
|
+
|
17
|
+
namespace Tab<%= @tablename%>_ {
|
18
|
+
<% @cols.each do |col| %>
|
19
|
+
struct <%= col.name.camelcase %> {
|
20
|
+
struct _alias_t {
|
21
|
+
static constexpr const char _literal[] = "<%= col.name%>";
|
22
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
23
|
+
template <typename T>
|
24
|
+
struct _member_t {
|
25
|
+
T <%= col.name %>;
|
26
|
+
T& operator()() { return <%= col.name %>; }
|
27
|
+
const T& operator()() const { return <%= col.name %>; }
|
28
|
+
};
|
29
|
+
};
|
30
|
+
<%
|
31
|
+
#sqltype = col.sql_type.downcase
|
32
|
+
#sqltype = 'time_point' if sqltype == 'datetime'
|
33
|
+
#sqltype = 'floating_point' if sqltype == 'decimal'
|
34
|
+
sqltype = sqlpptype(col.sql_type.downcase)
|
35
|
+
%>
|
36
|
+
using _traits = sqlpp::make_traits<sqlpp::<%= sqltype %><% if col.null %>, sqlpp::tag::can_be_null<%end%>>;
|
37
|
+
};
|
38
|
+
<% end %>
|
39
|
+
} // namespace Tab<%= @tablename %>_
|
40
|
+
|
41
|
+
struct Tab<%= @tablename %> : sqlpp::table_t<Tab<%= @tablename%>
|
42
|
+
<% @cols.each do |col|%>
|
43
|
+
, Tab<%= @tablename %>_::<%= col.name.camelcase %>
|
44
|
+
<% end%> >
|
45
|
+
{
|
46
|
+
using _value_type = sqlpp::no_value_t;
|
47
|
+
struct _alias_t {
|
48
|
+
static constexpr const char _literal[] = "<%= @tableklass.table_name %>";
|
49
|
+
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
50
|
+
template <typename T>
|
51
|
+
struct _member_t {
|
52
|
+
T tab<%= @tablename %>;
|
53
|
+
T& operator()() { return tab<%= @tablename %>; }
|
54
|
+
const T& operator()() const { return tab<%= @tablename %>; }
|
55
|
+
};
|
56
|
+
};
|
57
|
+
};
|
58
|
+
|
59
|
+
struct <%= @tablename%>Data {
|
60
|
+
<%= @tablename%>Data() : <%= buildCtor(@cols) %> {}
|
61
|
+
<% @cols.each do |col| %>
|
62
|
+
<% ctype = coltype2ctype(col.type.to_s) %>
|
63
|
+
<%= " %-32s %-25s; // %-10s %s" % [ctype, col.name, col.null, col.sql_type.downcase] %>
|
64
|
+
<% end %>
|
65
|
+
};
|
66
|
+
|
67
|
+
#endif // SQLPP_TAB_<%= @tablename.upcase %>_H
|
data/lib/sqlpp11gen.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'active_support/dependencies'
|
3
|
+
require "sqlpp11gen/version"
|
4
|
+
|
5
|
+
|
6
|
+
module Sqlpp11gen
|
7
|
+
# autoload :Delegator, 'devise/delegator'
|
8
|
+
|
9
|
+
require 'sqlpp11gen/engine' if defined?(Rails)
|
10
|
+
|
11
|
+
# The parent controller all Devise controllers inherits from.
|
12
|
+
# Defaults to ApplicationController. This should be set early
|
13
|
+
# in the initialization process and should be set to a string.
|
14
|
+
mattr_accessor :parent_controller
|
15
|
+
@@parent_controller = "ApplicationController"
|
16
|
+
|
17
|
+
def self.root
|
18
|
+
File.expand_path '../..', __FILE__
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.bin
|
22
|
+
File.join root, 'bin'
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.lib
|
26
|
+
File.join root, 'lib'
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sqlpp11gen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yongwang Dou
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: 'A c++ table class wrapper generator for sqlpp11 (c++11). See more about
|
56
|
+
sqlpp11 '
|
57
|
+
email:
|
58
|
+
- douyongwang@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- app/controllers/cxxes_controller.rb
|
66
|
+
- app/helpers/cxxes_helper.rb
|
67
|
+
- app/views/cxxes/index.h.erb
|
68
|
+
- lib/generators/sqlpp11gen/USAGE
|
69
|
+
- lib/generators/sqlpp11gen/cxxes_context.rb
|
70
|
+
- lib/generators/sqlpp11gen/cxxes_helper.rb
|
71
|
+
- lib/generators/sqlpp11gen/tab_generator.rb
|
72
|
+
- lib/generators/sqlpp11gen/templates/index.h.erb
|
73
|
+
- lib/sqlpp11gen.rb
|
74
|
+
- lib/sqlpp11gen/engine.rb
|
75
|
+
- lib/sqlpp11gen/version.rb
|
76
|
+
homepage: https://github.com/douyw/sqlpp11gen
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata:
|
80
|
+
allowed_push_host: https://rubygems.org
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.6
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A c++ table class wrapper generator for sqlpp11 (c++11).
|
101
|
+
test_files: []
|