jsql 0.1.5 → 0.1.6
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 +4 -4
- data/README.md +18 -4
- data/app/controllers/jsql_controller.rb +43 -17
- data/lib/jsql.rb +19 -1
- data/lib/jsql/configuration.rb +10 -0
- data/lib/jsql/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d991a6a6172e56ee60a1a2a75946df88b41662ce0016a75727eaf51ae57bb955
|
|
4
|
+
data.tar.gz: 1908b61c2b15c30134aba0b1c0e5df1d4a54d2b6e4b7a690dd9e2d112de53c83
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3e7032e21a19532cb119acf1fdc577f447223efce2d8e9fd4086446c29ad7a3765882104a445d9a13ee9eefcce7097c48b05e610aa35186414e728fc61c0417
|
|
7
|
+
data.tar.gz: 605a98db5053ac597e999d7429b27291f1a26dd00de8ff187ad3e6208bfc8d5bee3752e9a2e293c1bd77c3dd4ccfba65cb9950d73050197d0657931fad76b597
|
data/README.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
# Jsql
|
|
2
|
-
|
|
2
|
+
This is plugin for JSQL - sql with only front-end layer.
|
|
3
3
|
|
|
4
4
|
## Usage
|
|
5
|
-
|
|
5
|
+
Gem creates four end points for executing encoded sql queries.
|
|
6
|
+
jsql/select, jsql/update, jsql/insert, jsql/delete, and one for
|
|
7
|
+
transactions : jsql/commit.
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
10
|
+
Jsql gem works with Ruby version under 2.6.0 and Rails 5.2.2
|
|
11
|
+
If you don't have Rails installed yet you have to type in your console:
|
|
12
|
+
```bash
|
|
13
|
+
$ gem install rails
|
|
14
|
+
```
|
|
8
15
|
Add this line to your application's Gemfile:
|
|
9
16
|
|
|
10
17
|
```ruby
|
|
@@ -22,7 +29,14 @@ $ gem install jsql
|
|
|
22
29
|
```
|
|
23
30
|
|
|
24
31
|
## Contributing
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
In your application.rb file you have to add this code:
|
|
33
|
+
```ruby
|
|
34
|
+
Jsql.configure do |config|
|
|
35
|
+
config.api_key = 'your_api_key'
|
|
36
|
+
config.member_key = 'your_member_key'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
To get your api and member key you have to register on jsql.it.
|
|
27
41
|
## License
|
|
28
42
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -3,25 +3,27 @@ require 'timeout'
|
|
|
3
3
|
class JSQLController < ActionController::API
|
|
4
4
|
@@transaction = Array.new
|
|
5
5
|
@@database_type = nil
|
|
6
|
+
|
|
6
7
|
def perform_method(method)
|
|
7
8
|
manager = nil
|
|
9
|
+
puts Jsql.configuration.member_key
|
|
10
|
+
puts Jsql.configuration.api_key
|
|
8
11
|
puts "@database_type"
|
|
9
12
|
puts @@database_type
|
|
10
13
|
puts "@@transaction"
|
|
11
14
|
puts @@transaction
|
|
12
15
|
puts Time::now.tv_sec
|
|
13
16
|
begin
|
|
14
|
-
Timeout::timeout(10) do
|
|
15
|
-
request_body = JSON.parse(request.body.string)
|
|
16
|
-
delete_manager_time
|
|
17
|
-
manager = transaction_control
|
|
18
17
|
|
|
18
|
+
request_body = JSON.parse(request.body.string)
|
|
19
|
+
delete_manager_time
|
|
20
|
+
manager = transaction_control
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
query = create_query(request_body)
|
|
23
|
+
|
|
24
|
+
query = params_switcher(query, request_body)
|
|
25
|
+
query_method_compare(query, method)
|
|
21
26
|
|
|
22
|
-
query = params_switcher(query, request_body)
|
|
23
|
-
query_method_compare(query, method)
|
|
24
|
-
end
|
|
25
27
|
rescue Timeout::Error
|
|
26
28
|
rollback_manager(manager)
|
|
27
29
|
end
|
|
@@ -92,13 +94,23 @@ class JSQLController < ActionController::API
|
|
|
92
94
|
token = request_body['token']
|
|
93
95
|
|
|
94
96
|
if token.class == Array
|
|
97
|
+
|
|
95
98
|
for i in 0..token.size - 1
|
|
96
99
|
if i > 0
|
|
97
100
|
query += " "
|
|
98
101
|
end
|
|
99
102
|
query += get_queries(token[i])
|
|
103
|
+
puts "query.class"
|
|
104
|
+
puts query.class
|
|
105
|
+
puts "query"
|
|
100
106
|
puts query
|
|
107
|
+
if query.include? "code"
|
|
108
|
+
query
|
|
109
|
+
break
|
|
110
|
+
end
|
|
101
111
|
end
|
|
112
|
+
|
|
113
|
+
|
|
102
114
|
else
|
|
103
115
|
query = get_queries(token.to_s)
|
|
104
116
|
puts query
|
|
@@ -112,8 +124,8 @@ class JSQLController < ActionController::API
|
|
|
112
124
|
base_url = 'http://softwarecartoon.com:'
|
|
113
125
|
port = '9291'
|
|
114
126
|
queries = '/api/request/queries'
|
|
115
|
-
member_key =
|
|
116
|
-
api_key =
|
|
127
|
+
member_key = Jsql.configuration.member_key
|
|
128
|
+
api_key = Jsql.configuration.api_key
|
|
117
129
|
url = base_url + port + queries
|
|
118
130
|
database_type((base_url + port), member_key, api_key)
|
|
119
131
|
#parsing token into right regex
|
|
@@ -122,7 +134,8 @@ class JSQLController < ActionController::API
|
|
|
122
134
|
query = HTTP
|
|
123
135
|
.headers('Content-Type' => 'application/json', 'memberKey' => member_key, 'apiKey' => api_key)
|
|
124
136
|
.post(url, :body => token).body.to_s
|
|
125
|
-
|
|
137
|
+
puts "query"
|
|
138
|
+
puts query
|
|
126
139
|
#parsing response to json
|
|
127
140
|
|
|
128
141
|
header = HTTP
|
|
@@ -131,9 +144,16 @@ class JSQLController < ActionController::API
|
|
|
131
144
|
puts header.class
|
|
132
145
|
|
|
133
146
|
no_such_hash = "Cannot get property 'query' on null object"
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
147
|
+
begin
|
|
148
|
+
if (JSON.parse(query)[0] == nil || JSON.parse(query)[0]['query'] == nil) && JSON.parse(query)['message'] == no_such_hash
|
|
149
|
+
puts query
|
|
150
|
+
render_error_msg("No such hash for given ApiKey and MemberKey")
|
|
151
|
+
elsif JSON.parse(query)['code'] != 200
|
|
152
|
+
query
|
|
153
|
+
else
|
|
154
|
+
(JSON.parse(query)[0]['query'])
|
|
155
|
+
end
|
|
156
|
+
rescue
|
|
137
157
|
(JSON.parse(query)[0]['query'])
|
|
138
158
|
end
|
|
139
159
|
end
|
|
@@ -144,7 +164,13 @@ class JSQLController < ActionController::API
|
|
|
144
164
|
response = HTTP
|
|
145
165
|
.headers('Content-Type' => 'application/json', 'memberKey' => member_key, 'apiKey' => api_key)
|
|
146
166
|
.get(url).body.to_s
|
|
147
|
-
|
|
167
|
+
puts response
|
|
168
|
+
if JSON.parse(response)['code'] != 200
|
|
169
|
+
render_error_msg(JSON.parse(response)['description'])
|
|
170
|
+
else
|
|
171
|
+
@@database_type = JSON.parse(response)['data']['databaseDialect']
|
|
172
|
+
end
|
|
173
|
+
|
|
148
174
|
end
|
|
149
175
|
end
|
|
150
176
|
|
|
@@ -207,7 +233,7 @@ class JSQLController < ActionController::API
|
|
|
207
233
|
begin
|
|
208
234
|
if method == 'insert'
|
|
209
235
|
if @@database_type == 'POSTGRES'
|
|
210
|
-
query+=" returning *"
|
|
236
|
+
query += " returning *"
|
|
211
237
|
end
|
|
212
238
|
#puts response.class
|
|
213
239
|
#puts response
|
|
@@ -217,7 +243,7 @@ class JSQLController < ActionController::API
|
|
|
217
243
|
render json: {status: 'OK', lastId: last_id}, status: :ok
|
|
218
244
|
elsif method == 'delete'
|
|
219
245
|
if @@database_type == 'POSTGRES'
|
|
220
|
-
query+=" returning *"
|
|
246
|
+
query += " returning *"
|
|
221
247
|
end
|
|
222
248
|
response = ActiveRecord::Base.connection.execute(query).as_json
|
|
223
249
|
if response.empty?
|
data/lib/jsql.rb
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
require "jsql/engine"
|
|
2
|
-
|
|
2
|
+
require 'jsql/configuration'
|
|
3
3
|
module Jsql
|
|
4
4
|
# Your code goes here...
|
|
5
|
+
class << self
|
|
6
|
+
attr_accessor :configuration
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.configuration
|
|
10
|
+
@configuration ||= Configuration.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.reset
|
|
14
|
+
@configuration = Configuration.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.configure
|
|
18
|
+
yield(configuration)
|
|
19
|
+
end
|
|
20
|
+
|
|
5
21
|
end
|
|
22
|
+
|
|
23
|
+
|
data/lib/jsql/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jsql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adam Radecki
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-01-
|
|
11
|
+
date: 2019-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -65,6 +65,7 @@ files:
|
|
|
65
65
|
- app/views/layouts/jsql/application.html.erb
|
|
66
66
|
- config/routes.rb
|
|
67
67
|
- lib/jsql.rb
|
|
68
|
+
- lib/jsql/configuration.rb
|
|
68
69
|
- lib/jsql/engine.rb
|
|
69
70
|
- lib/jsql/version.rb
|
|
70
71
|
- lib/tasks/jsql_tasks.rake
|