old_sql 1.14.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,37 +1,52 @@
1
- = Old SQL
1
+ Old SQL
2
+ =======
2
3
 
3
4
  Old SQL is a Rails Engine database reporting gem that uses plain old SQL.
4
5
 
5
6
  Some features of Old SQL are:
6
7
 
7
8
  * Reports can be created using little or no Ruby code.
8
- - This allows the SQL for the report to be designed by a DBA, or other database developer independent of Ruby.
9
- - Reports can be designed using a design file that mocks the reports. This file can contain data from the SQL, as well as String literals, and formulas (that can also use numeric literals).
10
- - The design documents, which are nothing more than csv files, can also serve as documentation, and describe the layout of the report in an intuitive way.
11
- - If you want more fine grained control and report processor can parse the SQL.
12
- - This also makes it simple to convert legacy reports into Old SQL reports.
9
+ - SQL for the report to be designed by a DBA, or other database developer independent of Ruby.
10
+ - Reports can be designed using a design file that mocks the reports. This file can contain data
11
+ from the SQL, as well as String literals, and formulas (that can also use numeric literals).
12
+ - The design documents, which are nothing more than CSV files, can also serve as documentation,
13
+ and describe the layout of the report in an intuitive way.
14
+ - If you want more fine grained control, a custom report processor can parse the SQL.
15
+ - Simple to convert legacy reports into Old SQL reports.
13
16
  * Multiple report views (jqGrid, HTML table, and chart) that can be configured using the old_sql initializer.
14
17
  * Old SQL uses Devise for authentication, and will install it for you. It can
15
18
  even add Devise support to an existing model (by default users).
16
- * In the report design all data is rounded to a precision that can be set in the old_sql initializer. This feature can also be disabled in the initializer.
17
- * Old SQL has rake tasks for running the reports and outputting the result as CSV. This can simplify testing. It also allows reports to be run as a cron task.
19
+ * In the report design all data is rounded to a precision that can be set in the old_sql initializer.
20
+ This feature can also be disabled in the initializer.
21
+ * Old SQL has rake tasks for running the reports and outputting the result as CSV. This can simplify testing.
22
+ It also allows reports to be run as a cron task.
18
23
  * The look of Old SQL can be customized.
19
- * Support for printing and exporting to csv.
24
+ * Support for printing and exporting to CSV.
20
25
 
21
- == Quick Setup and Demo
26
+ Quick Setup and Demo
27
+ --------------------
22
28
 
23
29
  1. Add gem 'old_sql', and gem 'devise' to your Gemfile.
24
- 2. bundle instal
30
+ 2. bundle install
25
31
  3. rails g old_sql:install, or rails g old_sql:install <model>
26
32
  4. rake db:migrate
27
33
  5. Ensure you have at least one user record, and that old_sql_admin=true.
28
- 6. if you didn't previously have Devise installed open rails console, and select your old_sql_admin user, and set password and password_confirmation. Save, and exit.
34
+ 6. If you didn't previously have Devise installed open rails console, and select your old_sql_admin user,
35
+ and set password and password_confirmation. Save, and exit.
29
36
  7. Type rails s to start your rails server.
30
37
  8. Navigate to http://localhost:3000/sql/reports
31
38
  9. Authenticate using your old_sql_admin user.
32
39
  10. Select user from the Reports drop down list. Click run.
33
40
 
34
- == Installation
41
+ Screenshots
42
+ -----------
43
+
44
+ ![jqGrid view](https://github.com/egonz/old_sql/raw/master/screenshots/jqgrid.png "jqGrid view")
45
+ ![table view](https://github.com/egonz/old_sql/raw/master/screenshots/table.png "Table view")
46
+ ![table view](https://github.com/egonz/old_sql/raw/master/screenshots/chart.png "Chart view")
47
+
48
+ Installation
49
+ ------------
35
50
 
36
51
  To install Old SQL type:
37
52
 
@@ -44,9 +59,10 @@ This will create the following directories:
44
59
 
45
60
  This generator will also create a migration that will add a old_sql_admin column to the model used for authentication (by default users).
46
61
 
47
- If not already installed Devise is setup.
62
+ If not already installed Devise is setup.
48
63
 
49
- == Creating Reports
64
+ Creating Reports
65
+ ----------------
50
66
 
51
67
  Configure your reports config/old_sql/report.yml. An example configuration is created when you run the old_sql:install generator.
52
68
 
@@ -65,7 +81,7 @@ Configure your reports config/old_sql/report.yml. An example configuration is cr
65
81
  # itself should follow normal ruby class naming conventions.
66
82
  #
67
83
  # 'report_design' is also optional, and should point to a file in config/old_sql/report_design.
68
- # See config/old_sql/report_design/user_old_sql_demo.csv for an example.
84
+ # See config/old_sql/report_design/user_old_sql_demo.CSV for an example.
69
85
  #
70
86
  # 'report_view' is optional. It overrides the default_report_view defined in the initializer. It
71
87
  # can be set to jqgrid, table, or chart.
@@ -73,31 +89,31 @@ Configure your reports config/old_sql/report.yml. An example configuration is cr
73
89
  # The 'fields' are the headers for the report.
74
90
 
75
91
  user_jqgrid:
76
- description: User jqGrid
77
- report_sql: user_old_sql_demo
78
- report_design: user_old_sql_demo.csv
79
- report_view: jqgrid
80
- fields:
81
- - 'id'
82
- - 'name'
92
+ description: User jqGrid
93
+ report_sql: user_old_sql_demo
94
+ report_design: user_old_sql_demo.CSV
95
+ report_view: jqgrid
96
+ fields:
97
+ - 'id'
98
+ - 'name'
83
99
 
84
100
  user_table:
85
- description: User HTML Table
86
- report_sql: user_old_sql_demo
87
- report_processor: User_Old_Sql_Demo_Processor
88
- report_view: table
89
- fields:
90
- - 'id'
91
- - 'name'
101
+ description: User HTML Table
102
+ report_sql: user_old_sql_demo
103
+ report_processor: User_Old_Sql_Demo_Processor
104
+ report_view: table
105
+ fields:
106
+ - 'id'
107
+ - 'name'
92
108
 
93
109
  user_chart:
94
- description: User Chart
95
- report_sql: user_old_sql_demo
96
- report_design: user_old_sql_demo.yml
97
- report_view: chart
98
- fields:
99
- - 'id'
100
- - 'name'
110
+ description: User Chart
111
+ report_sql: user_old_sql_demo
112
+ report_design: user_old_sql_demo.yml
113
+ report_view: chart
114
+ fields:
115
+ - 'id'
116
+ - 'name'
101
117
 
102
118
  Create a sql file under config/old_sql/report_sql. The following example is included:
103
119
 
@@ -106,7 +122,7 @@ Create a sql file under config/old_sql/report_sql. The following example is incl
106
122
  WHERE u.created_at > date('<%=start_date.gsub('/','-')%>')
107
123
  AND u.created_at < date('<%=end_date.gsub('/','-')%>')
108
124
 
109
- Optionally create a design file under config/old_sql/report_design:
125
+ Optionally create a CSV DESIGN file under config/old_sql/report_design:
110
126
 
111
127
  # Old SQL:
112
128
  # Example Report Design Document
@@ -135,6 +151,22 @@ Optionally create a design file under config/old_sql/report_design:
135
151
  "Divide by Zero 3",0.0 / 0.0
136
152
  "Rounding",200.0 / 43.0
137
153
 
154
+ Optionally create a CHART DESIGN file under config/old_sql/report_design:
155
+
156
+ # Old SQL Chart Design Example
157
+ #
158
+ # The key can either be pie or bar.
159
+ # Items should be numbered from 0 to n.
160
+ # The value of each item can be either a column name, or
161
+ # a formula.
162
+
163
+ pie:
164
+ 0: id + 10
165
+ 1: id + 20
166
+ 2: id + 50
167
+ 3: id + 70
168
+ 4: id + 100
169
+
138
170
  Optionally create a processor under lib/old_sql_report_processor:
139
171
 
140
172
  require 'old_sql/report_processor/base'
@@ -148,8 +180,8 @@ Optionally create a processor under lib/old_sql_report_processor:
148
180
 
149
181
  Rails.logger.debug "REC: #{@rec}"
150
182
 
151
- add_row(nil, [@rec['id'], @rec['name']])
152
- add_row('Totals', ['...'])
183
+ add_row([@rec['id'], @rec['name']])
184
+ add_row(['Totals', '...'])
153
185
 
154
186
  @data
155
187
  end
@@ -157,7 +189,27 @@ Optionally create a processor under lib/old_sql_report_processor:
157
189
  end
158
190
  end
159
191
 
160
- == Customize
192
+ Design File Tips
193
+ ----------------
194
+
195
+ Design files, both CSV and CHART, work best (only?) with queries that return a single record.
196
+ Ideally the query returns aggregate results, form one or more tables. For example:
197
+
198
+ SELECT
199
+ IFNULL(SUM(f.total),0) AS foo_total,
200
+ IFNULL(SUM(CASE WHEN f.attempts IS NOT NULL THEN 1 ELSE 0 END),0) AS foo_attempts,
201
+ IFNULL(bar_totals.bar_count,0) AS bar_count
202
+ FROM
203
+ foo f
204
+ JOIN
205
+ (SELECT COUNT(id) AS bar_count FROM bar) AS bar_totals
206
+ WHERE
207
+ 1=1
208
+ AND f.created_at > '<%=start_date%>'
209
+ AND f.created_at < '<%=end_date%>'
210
+
211
+ Customize
212
+ ---------
161
213
 
162
214
  All css and html template files can be copied to your installation by executing:
163
215
 
@@ -165,7 +217,8 @@ All css and html template files can be copied to your installation by executing:
165
217
 
166
218
  Settings for Old SQL can be configured in config/initializers/old_sql.rb.
167
219
 
168
- == Rake Examples
220
+ Rake Examples
221
+ -------------
169
222
 
170
223
  rake old_sql:print:range[user_table,'development','2011-03-01','2011-09-01']
171
224
 
@@ -173,7 +226,8 @@ Settings for Old SQL can be configured in config/initializers/old_sql.rb.
173
226
 
174
227
  rake old_sql:print:week[user_table,'development']
175
228
 
176
- == Contributing to old_sql
229
+ Contributing to old_sql
230
+ -----------------------
177
231
 
178
232
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
179
233
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -183,7 +237,8 @@ Settings for Old SQL can be configured in config/initializers/old_sql.rb.
183
237
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
184
238
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
185
239
 
186
- == Copyright
240
+ Copyright
241
+ ---------
187
242
 
188
243
  Copyright (c) 2011 Eddie Gonzales. See LICENSE.txt for
189
244
  further details.
@@ -8,6 +8,7 @@
8
8
  var options = {
9
9
  "IECanvasHTC": "/plotkit/iecanvas.htc",
10
10
  "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[0]),
11
+ "backgroundColor": Color.whiteColor(),
11
12
  "xTicks": <%=chart_fields%>,
12
13
  "drawYAxis": true
13
14
  };
@@ -1,4 +1,9 @@
1
1
  # Old SQL Chart Design Example
2
+ #
3
+ # The key can either be pie or bar.
4
+ # Items should be numbered from 0 to n.
5
+ # The value of each item can be either a column name, or
6
+ # a formula.
2
7
 
3
8
  pie:
4
9
  0: id + 10
@@ -9,8 +9,8 @@ module OldSql
9
9
 
10
10
  Rails.logger.debug "REC: #{@rec}"
11
11
 
12
- add_row(nil, [@rec['id'], @rec['name']])
13
- add_row('Totals', ['...'])
12
+ add_row([@rec['id'], @rec['name']])
13
+ add_row(['Totals', '...'])
14
14
 
15
15
  @data
16
16
  end
@@ -182,11 +182,7 @@ module OldSql
182
182
  @data[:rows] = []
183
183
  end
184
184
 
185
- def add_row(title = nil, cell_data = [], id = @id+1)
186
- if !title.nil?
187
- cell_data.unshift "<b>#{title}</b>"
188
- end
189
-
185
+ def add_row(cell_data = [], id = @id+1)
190
186
  @data[:rows] << {id: id, cell: cell_data}
191
187
  end
192
188
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: old_sql
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.14.0
5
+ version: 1.15.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Eddie Gonzales
@@ -42,11 +42,10 @@ extensions: []
42
42
 
43
43
  extra_rdoc_files:
44
44
  - LICENSE.txt
45
- - README.rdoc
45
+ - README.md
46
46
  files:
47
47
  - Gemfile
48
48
  - LICENSE.txt
49
- - README.rdoc
50
49
  - Rakefile
51
50
  - app/controllers/old_sql/report_controller.rb
52
51
  - app/views/layouts/old_sql/report.html.erb
@@ -440,6 +439,7 @@ files:
440
439
  - public/stylesheets/old_sql/ui-lightness/images/ui-icons_ffd27a_256x240.png
441
440
  - public/stylesheets/old_sql/ui-lightness/images/ui-icons_ffffff_256x240.png
442
441
  - public/stylesheets/old_sql/ui-lightness/jquery-ui-1.8.13.custom.css
442
+ - README.md
443
443
  homepage: http://github.com/egonz/old_sql
444
444
  licenses:
445
445
  - MIT
@@ -453,7 +453,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
453
453
  requirements:
454
454
  - - ">="
455
455
  - !ruby/object:Gem::Version
456
- hash: 1769007801397558054
456
+ hash: 3219166271632423260
457
457
  segments:
458
458
  - 0
459
459
  version: "0"