smql 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -6
- data/VERSION +1 -1
- data/lib/smql_to_ar/query_builder.rb +1 -2
- data/lib/smql_to_ar.rb +11 -5
- metadata +3 -3
data/README.md
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
Idea
|
2
2
|
====
|
3
3
|
|
4
|
-
Similar to MQL: SMQL
|
4
|
+
Similar to MQL: SMQL allows to perform queries on your database but in a JSON-based language.
|
5
5
|
|
6
6
|
This query language is SQL-injection-safe.
|
7
|
-
|
7
|
+
However, expensive queries can slow down your machine.
|
8
8
|
|
9
9
|
Usage
|
10
10
|
=====
|
11
11
|
|
12
|
-
|
13
|
-
User is a
|
14
|
-
We want to find all
|
12
|
+
Example: An easy query in ruby:
|
13
|
+
User is a ActiveRecord-Model and has a column username.
|
14
|
+
We want to find all _users_ _where_ _username_ = _"auser"_.
|
15
15
|
|
16
16
|
require 'smql'
|
17
17
|
|
@@ -22,6 +22,6 @@ In Rails:
|
|
22
22
|
|
23
23
|
SmqlToAR.to_ar User, params[:smql]
|
24
24
|
|
25
|
-
Don't forget to add gem to
|
25
|
+
Don't forget to add my gem to the _Gemfile_:
|
26
26
|
|
27
27
|
gem 'smql'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
@@ -30,10 +30,9 @@ class SmqlToAR
|
|
30
30
|
|
31
31
|
attr_reader :table_alias, :model, :table_model, :base_table, :_where, :_select, :_wobs, :_joins
|
32
32
|
attr_accessor :logger
|
33
|
-
@@logger = SmqlToAR.logger
|
34
33
|
|
35
34
|
def initialize model
|
36
|
-
@logger =
|
35
|
+
@logger = SmqlToAR.logger
|
37
36
|
@table_alias = Hash.new do |h, k|
|
38
37
|
k = Array.wrap k
|
39
38
|
h[k] = "smql,#{k.join(',')}"
|
data/lib/smql_to_ar.rb
CHANGED
@@ -157,12 +157,18 @@ class SmqlToAR
|
|
157
157
|
|
158
158
|
attr_reader :model, :query, :conditions, :builder, :order
|
159
159
|
attr_accessor :logger
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
160
|
+
if defined? Rails
|
161
|
+
class Railtie < ::Rails::Railtie
|
162
|
+
initializer "active_record.logger" do
|
163
|
+
SmqlToAR.logger = ::Rails.logger
|
164
|
+
$stderr.puts( { self: self, logger: SmqlToAR.logger}.inspect)
|
165
|
+
end
|
165
166
|
end
|
167
|
+
else
|
168
|
+
require 'logger'
|
169
|
+
@@logger = Logger.new $stdout
|
170
|
+
$stderr.puts( { logger: @@logger}.inspect)
|
171
|
+
end
|
166
172
|
|
167
173
|
class <<self
|
168
174
|
def logger=(logger) @@logger = logger end
|
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
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Denis Knauf
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-09-
|
17
|
+
date: 2011-09-11 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|