dynamic-records-meritfront 3.0.24 → 3.0.26
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 +49 -0
- data/lib/dynamic-records-meritfront/version.rb +1 -1
- data/lib/dynamic-records-meritfront.rb +6 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e61d44017d347ec7083448f67c2a3db1994f49b2a63c21d27c976c8a06c6b777
|
4
|
+
data.tar.gz: bbc308253515c6db53e9964701745fbbee832aee9acd7d4c1d64812b532955f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5a7ae8e89825cf74e31e99e4e422087f3eacc9bb290c727c49ec272c8a40f507d932d3e64f85ee43edf8366c6b2fe6121f3303204ff759e838aaa435ea46c55
|
7
|
+
data.tar.gz: d70bb9d0a4ab3972ad2f940f0606a1cad2b492ad5fc8daafa892d6014800513ae4d54d2d1d3d1f47d62c3b3bcd5f89c9100173e773cb042dceef4d0b5af4fbd4
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -315,6 +315,52 @@ the output:
|
|
315
315
|
...]}
|
316
316
|
```
|
317
317
|
</details>
|
318
|
+
|
319
|
+
<details>
|
320
|
+
<summary>above example with relations (no need for dynamic_attach)</summary>
|
321
|
+
#get list of users, those users friends, and who those users follow, all in one request.
|
322
|
+
|
323
|
+
```ruby
|
324
|
+
friend_attach = attach_on: Proc.new {|users_friend|
|
325
|
+
users_friend.friended_to
|
326
|
+
}
|
327
|
+
|
328
|
+
output = ApplicationRecord.instaload_sql([
|
329
|
+
User.instaload(%Q{
|
330
|
+
select id
|
331
|
+
from users
|
332
|
+
where users.id = any (:user_ids) and users.created_at > :time
|
333
|
+
}, table_name: :limited_users, relied_on: true),
|
334
|
+
User.instaload(%Q{
|
335
|
+
select friends.smaller_user_id as id, friends.bigger_user_id as friended_to
|
336
|
+
from friends
|
337
|
+
inner join limited_users on limited_users.id = bigger_user_id
|
338
|
+
union
|
339
|
+
select friends.bigger_user_id as id, friends.smaller_user_id as friended_to
|
340
|
+
from friends
|
341
|
+
inner join limited_users ON limited_users.id = smaller_user_id
|
342
|
+
}, table_name: :users_friends, base_name: :limited_users, attach_on: attach_on),
|
343
|
+
ApplicationRecord.instaload(%Q{
|
344
|
+
SELECT follows.followable_id, follows.follower_id
|
345
|
+
FROM follows
|
346
|
+
INNER JOIN limited_users ON follows.follower_id = limited_users.id
|
347
|
+
}, table_name: :users_follows, base_name: :limited_users)
|
348
|
+
], user_ids: uids, time: t)
|
349
|
+
|
350
|
+
pp out['limited_users']
|
351
|
+
|
352
|
+
```
|
353
|
+
sql output: same as example above this example
|
354
|
+
|
355
|
+
printed output (same as in dynamic attach example):
|
356
|
+
```ruby
|
357
|
+
#<User id: 3, users_friends: [#<User id: 5, friended_to: 3>, #<User id: 6, friended_to: 3>, #<User id: 21, friended_to: 3>], users_follows: [{"followable_id"=>935, "follower_id"=>3}, {"followable_id"=>938, "follower_id"=>3}, ...]>,
|
358
|
+
#<User id: 14, users_friends: [#<User id: 9, friended_to: 14>, #<User id: 21, friended_to: 14>, ...], users_follows: [{"followable_id"=>936, "follower_id"=>14}, {"followable_id"=>937, "follower_id"=>14}, {"followable_id"=>938, "follower_id"=>14}, ...]>,
|
359
|
+
#<User id: 9, users_friends: [#<User id: 14, friended_to: 9>, #<User id: 22, friended_to: 9>, ...], users_follows: [{"followable_id"=>938, "follower_id"=>9}, {"followable_id"=>937, "follower_id"=>9}, ...]>,
|
360
|
+
#<User id: 19, users_friends: [#<User id: 1, friended_to: 19>, #<User id: 18, friended_to: 19>, ...], users_follows: [{"followable_id"=>935, "follower_id"=>19}, {"followable_id"=>936, "follower_id"=>19}, {"followable_id"=>938, "follower_id"=>19}, ...]>,
|
361
|
+
```
|
362
|
+
|
363
|
+
</details>
|
318
364
|
|
319
365
|
#### self.instaload(sql, table_name: nil, relied_on: false, dont_return: false)
|
320
366
|
A method used to prepare data for the instaload_sql method. It returns a hash of options.
|
@@ -470,6 +516,9 @@ v3.0.6
|
|
470
516
|
- changed how variables are set for ActiveRecord objects, I gave up on figuring out what ActiveRecord is doing for *the most part* and i now just do a eval("self.#{parameter}=value") type deal. Works well. Allows you to override relations when doing polymorphic stuff which is a pretty big use case.
|
471
517
|
- I am thinking of changing how arrays are handled as that is really the only postgresql based dependency here and that will allow the library to open up to other databases. Issue is all the code I have already written in my app dependant on such things.
|
472
518
|
|
519
|
+
3.0.24
|
520
|
+
- changed how questionable_attribute_set works again, this time by using attr_accessors on the singleton class. Seems to paper over the default reflections nicely which has been a huge issue. They use this weird delegate thing which has been throwing me off. Anyway, no more evals which is nice. This fixed an issue with dynamic attach one-to-many relations.
|
521
|
+
|
473
522
|
## Questions
|
474
523
|
- Q: does the name of a sql operation have anything to do with prepared statements?
|
475
524
|
- A: no, the prepared statement determines uniqueness in some other way, dont worry about collisions. The only issue with prepared statements that I can determine is when you write a statement where things change every time, thus preparing potentially infinite prepared statements. This can be alleviated by using sql arguments correctly. Using arguments correctly also will stop sql injection attacks so. You know. Do it properly. Dont just hard code them into the query.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "dynamic-records-meritfront/version"
|
2
2
|
require 'hashid/rails'
|
3
3
|
|
4
|
-
#this file contains multiple classes which should honestly be split up
|
4
|
+
#this file contains multiple classes which should honestly be split up.
|
5
5
|
|
6
6
|
module DynamicRecordsMeritfront
|
7
7
|
extend ActiveSupport::Concern
|
@@ -87,12 +87,10 @@ module DynamicRecordsMeritfront
|
|
87
87
|
Time => ActiveModel::Type::Time,
|
88
88
|
Float => ActiveModel::Type::Float,
|
89
89
|
NilClass => ActiveModel::Type::Boolean,
|
90
|
-
Array => Proc.new{ |first_el_class| ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.new(DB_TYPE_MAPS[first_el_class].new) }
|
90
|
+
Array => Proc.new{ |first_el_class| ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.new(DB_TYPE_MAPS[first_el_class].new) } #this one was a mistake
|
91
91
|
}
|
92
92
|
|
93
93
|
def convert_to_query_attribute(name, v)
|
94
|
-
#yes its dumb I know dont look at me look at rails
|
95
|
-
|
96
94
|
# https://stackoverflow.com/questions/40407700/rails-exec-query-bindings-ignored
|
97
95
|
# binds = [ ActiveRecord::Relation::QueryAttribute.new(
|
98
96
|
# "id", 6, ActiveRecord::Type::Integer.new
|
@@ -294,8 +292,8 @@ module DynamicRecordsMeritfront
|
|
294
292
|
|
295
293
|
self.dynamic_reflections ||= []
|
296
294
|
dyna = dynamic_reflections.map{|dr|
|
297
|
-
self.method(dr.to_sym).call()
|
298
|
-
}
|
295
|
+
[dr, self.method(dr.to_sym).call()]
|
296
|
+
}.to_h
|
299
297
|
|
300
298
|
if dyna.any?
|
301
299
|
"#<#{self.class} #{inspection} | #{dyna.to_s}>"
|
@@ -954,8 +952,9 @@ module DynamicRecordsMeritfront
|
|
954
952
|
|
955
953
|
#just for ease of use
|
956
954
|
def headache_preload(records, associations)
|
957
|
-
|
955
|
+
self.class.headache_preload(records, associations)
|
958
956
|
end
|
957
|
+
|
959
958
|
def safe_increment(col, val) #also used in follow, also used in comment#kill
|
960
959
|
self.class.where(id: self.id).update_all("#{col} = #{col} + #{val}")
|
961
960
|
end
|