dynamic-records-meritfront 3.0.3 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -11
- data/lib/dynamic-records-meritfront/version.rb +1 -1
- data/lib/dynamic-records-meritfront.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa816c1fc2d4e08950ff1f91c1bb4aa1d8025a4e845d62919e7254e449a6901f
|
4
|
+
data.tar.gz: 4649ad599b97346ca16ddbb5f07298fd0408d5028795fcfcb3e5f0b5d1f906c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dbba9dee9ca11dab5665b0d96a2b13840f7bfff8eb28c859e8628119efb420924435ed06ca380dc9fec7408231cf7a7f9671429cc34c18c2e0536646324a3ba
|
7
|
+
data.tar.gz: cddf05b9c1f9eb9df8c1c7fb1a586dc618eed8a5f3fd0a0b8f8b4017d3bbb0beee66143c4925bd102af52d2ea6e302c5fda7384ca8c4f7cfafa8b481afefc0f8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -67,7 +67,7 @@ A better and safer way to write sql. Can return either a Hash, ActiveRecord::Res
|
|
67
67
|
|
68
68
|
```ruby
|
69
69
|
User.dynamic_sql('select * from users') #returns all users
|
70
|
-
ApplicationRecord.dynamic_sql('select
|
70
|
+
ApplicationRecord.dynamic_sql('select * from users') #returns all user column information in an array
|
71
71
|
```
|
72
72
|
|
73
73
|
with options:
|
@@ -149,27 +149,28 @@ Get users who match a list of ids. Uses a postgresql Array, see the potential is
|
|
149
149
|
Do an upsert
|
150
150
|
|
151
151
|
```ruby
|
152
|
+
time = DateTime.now
|
152
153
|
rows = uzrs.map{|u| [
|
153
154
|
u.id, #user_id
|
154
155
|
self.id, #conversation_id
|
155
156
|
from, #invited_by
|
156
|
-
|
157
|
-
|
157
|
+
:time, #created_at (We use symbols to denote other sql arguments)
|
158
|
+
:time, #updated_at
|
158
159
|
]}
|
159
160
|
ApplicationRecord.dynamic_sql("upsert_conversation_invites_2", %Q{
|
160
161
|
INSERT INTO conversation_participants (user_id, conversation_id, invited_by, created_at, updated_at)
|
161
162
|
VALUES :rows
|
162
163
|
ON CONFLICT (conversation_id,user_id)
|
163
164
|
DO UPDATE SET updated_at = :time
|
164
|
-
}, rows: rows, time:
|
165
|
+
}, rows: rows, time: time)
|
165
166
|
```
|
166
|
-
This will output sql similar to below. Note this can be done for multiple conversation_participants. Also note that
|
167
|
+
This will output sql similar to below. Note this can be done for multiple conversation_participants. Also note that we sent only one time variable during our request instead of duplicating it.
|
167
168
|
```sql
|
168
169
|
INSERT INTO conversation_participants (user_id, conversation_id, invited_by, created_at, updated_at)
|
169
170
|
VALUES ($1,$2,$3,$4,$4)
|
170
171
|
ON CONFLICT (conversation_id,user_id)
|
171
172
|
DO UPDATE SET updated_at = $4
|
172
|
-
-- [["rows_1", 15], ["rows_2", 67], ["rows_3", 6], [
|
173
|
+
-- [["rows_1", 15], ["rows_2", 67], ["rows_3", 6], [:time, "2022-10-13 20:49:27.441372"]]
|
173
174
|
```
|
174
175
|
</details>
|
175
176
|
|
@@ -244,7 +245,7 @@ obj.has_association?(:votes) #false
|
|
244
245
|
```
|
245
246
|
</details>
|
246
247
|
|
247
|
-
#### self.
|
248
|
+
#### self.instaload_sql( *optional* name, insta_array, opts = { })
|
248
249
|
*instaloads* a bunch of diffrent models at the same time by casting them to json before returning them. Kinda cool. Maybe a bit overcomplicated. Seems to be more efficient to preloading when i tested it.
|
249
250
|
- name is passed to dynamic_sql and is the name of the sql request
|
250
251
|
- opts are passed to dynamic_sql (except for the raw option which is set to true. Raw output is not allowed on this request)
|
@@ -264,7 +265,7 @@ out = ApplicationRecord.instaload_sql([
|
|
264
265
|
|
265
266
|
```ruby
|
266
267
|
# the ruby entered
|
267
|
-
output = ApplicationRecord.
|
268
|
+
output = ApplicationRecord.instaload_sql([
|
268
269
|
User.instaload('SELECT id FROM users WHERE users.id = ANY (:user_ids) AND users.created_at > :time', table_name: 'limited_users', relied_on: true),
|
269
270
|
User.instaload(%Q{
|
270
271
|
SELECT friends.smaller_user_id AS id, friends.bigger_user_id AS friended_to
|
@@ -323,7 +324,7 @@ the output:
|
|
323
324
|
</details>
|
324
325
|
|
325
326
|
#### self.instaload(sql, table_name: nil, relied_on: false, dont_return: false)
|
326
|
-
A method used to prepare data for the
|
327
|
+
A method used to prepare data for the instaload_sql method. It returns a hash of options.
|
327
328
|
- klass called on: if called on an abstract class (ApplicationRecord) it will return a list of hashes with the data. Otherwise returns a list of the classes records.
|
328
329
|
- table_name: sets the name of the temporary postgresql table. This can then be used in further instaload sql snippets.
|
329
330
|
- relied_on: will make it so other instaload sql snippets can reference this table (it makes it use posrgresql's WITH operator)
|
@@ -349,7 +350,7 @@ User.instaload('SELECT id FROM users WHERE users.id = ANY (:user_ids) AND users.
|
|
349
350
|
</details>
|
350
351
|
|
351
352
|
#### self.dynamic_attach(instaload_sql_output, base_name, attach_name, base_on: nil, attach_on: nil, one_to_one: false)
|
352
|
-
taking the output of the
|
353
|
+
taking the output of the instaload_sql method, this method creates relations between the models.
|
353
354
|
- base_name: the name of the table we will be attaching to
|
354
355
|
- attach_name: the name of the table that will be attached
|
355
356
|
- base_on: put a proc here to override the matching key for the base table. Default is, for a user and post type, {|user| user.id}
|
@@ -357,7 +358,7 @@ taking the output of the dynamic_instaload_sql, this method attaches the models
|
|
357
358
|
- one_to_one: switches between a one-to-one relationship or not
|
358
359
|
|
359
360
|
<details>
|
360
|
-
<summary> attach information for each limited_user in the
|
361
|
+
<summary> attach information for each limited_user in the instaload_sql example </summary>
|
361
362
|
|
362
363
|
```ruby
|
363
364
|
|
@@ -17,7 +17,7 @@ module DynamicRecordsMeritfront
|
|
17
17
|
#should work, probably able to override by redefining in ApplicationRecord class.
|
18
18
|
#Note we defined here as it breaks early on as Rails.application returns nil
|
19
19
|
PROJECT_NAME = Rails.application.class.to_s.split("::").first.to_s.downcase
|
20
|
-
DYNAMIC_SQL_RAW =
|
20
|
+
DYNAMIC_SQL_RAW = true
|
21
21
|
end
|
22
22
|
class DynamicSqlVariables
|
23
23
|
attr_accessor :sql_hash
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic-records-meritfront
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Clancy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashid-rails
|