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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7452d0058119526d1ece08203106f8ae07da51f41e22f764c4d5262d2340e7f4
4
- data.tar.gz: 88fc11727ba9a6d016afb22ec03beafc30412e37502daf35e33dce6532ef02b1
3
+ metadata.gz: e61d44017d347ec7083448f67c2a3db1994f49b2a63c21d27c976c8a06c6b777
4
+ data.tar.gz: bbc308253515c6db53e9964701745fbbee832aee9acd7d4c1d64812b532955f3
5
5
  SHA512:
6
- metadata.gz: 69eff49f3efbfd1261477cd3b895786a0dc97ca09e2933aab4471eea85c61f4e54651d37a4d3138e4c9d7c64f4802c3fda0d45152d84598e206072a14b828089
7
- data.tar.gz: e6a26b39284b4b80891fed68af41d930b1d12e83aaadad45c8d6fee4c9f1bfadbaebd3ff56407a09b5714f2248d3cf39cdb58a37cc4a8835241933294f99a2d9
6
+ metadata.gz: f5a7ae8e89825cf74e31e99e4e422087f3eacc9bb290c727c49ec272c8a40f507d932d3e64f85ee43edf8366c6b2fe6121f3303204ff759e838aaa435ea46c55
7
+ data.tar.gz: d70bb9d0a4ab3972ad2f940f0606a1cad2b492ad5fc8daafa892d6014800513ae4d54d2d1d3d1f47d62c3b3bcd5f89c9100173e773cb042dceef4d0b5af4fbd4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamic-records-meritfront (3.0.24)
4
+ dynamic-records-meritfront (3.0.26)
5
5
  hashid-rails
6
6
 
7
7
  GEM
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,5 +1,5 @@
1
1
 
2
2
  module DynamicRecordsMeritfront
3
- VERSION = '3.0.24'
3
+ VERSION = '3.0.26'
4
4
  end
5
5
  #this file gets overwritten automatically on minor updates, major ones need to be manually changed
@@ -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
- self.class.headache_preload(records, associations)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic-records-meritfront
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.24
4
+ version: 3.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Clancy