dynamic-records-meritfront 3.0.6 → 3.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -9
- data/README.md +27 -13
- data/lib/dynamic-records-meritfront/version.rb +1 -1
- data/lib/dynamic-records-meritfront.rb +690 -548
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abe695f1cafabc83e3776b7f2527ca1647102cf8cc3aafc45bae0a5a5adb288f
|
4
|
+
data.tar.gz: 44125e65532fc6aaee3de08f506194ea3a6718ae24434a5c45268f374fc4192d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9eab130e60095e150b352098e32442377398c735920676a2221586e82996d1d7eeabfd2f081306d4d0cb48c211dc8951d216fe92a66b30adf16fa0648d72189
|
7
|
+
data.tar.gz: 1d5d4a226354ee08fd8bad951814f03bb0ca4199e5eea2c37516f76639beaf446a111d90cce8495ee4a01a92f0fbdda223f5a27e4f64296e7ca73f7f06dbf3e2
|
data/Gemfile.lock
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dynamic-records-meritfront (3.0.
|
4
|
+
dynamic-records-meritfront (3.0.23)
|
5
5
|
hashid-rails
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (7.0.4)
|
11
|
-
activesupport (= 7.0.4)
|
12
|
-
activerecord (7.0.4)
|
13
|
-
activemodel (= 7.0.4)
|
14
|
-
activesupport (= 7.0.4)
|
15
|
-
activesupport (7.0.4)
|
10
|
+
activemodel (7.0.4.2)
|
11
|
+
activesupport (= 7.0.4.2)
|
12
|
+
activerecord (7.0.4.2)
|
13
|
+
activemodel (= 7.0.4.2)
|
14
|
+
activesupport (= 7.0.4.2)
|
15
|
+
activesupport (7.0.4.2)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
19
19
|
tzinfo (~> 2.0)
|
20
|
-
concurrent-ruby (1.
|
20
|
+
concurrent-ruby (1.2.0)
|
21
21
|
hashid-rails (1.4.1)
|
22
22
|
activerecord (>= 4.0)
|
23
23
|
hashids (~> 1.0)
|
24
24
|
hashids (1.0.6)
|
25
25
|
i18n (1.12.0)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
|
-
minitest (5.
|
27
|
+
minitest (5.17.0)
|
28
28
|
rake (12.3.3)
|
29
29
|
tzinfo (2.0.5)
|
30
30
|
concurrent-ruby (~> 1.0)
|
data/README.md
CHANGED
@@ -5,7 +5,8 @@ Dyanmic Records Meritfront helps extend active record functionality to make it m
|
|
5
5
|
2. communicate with the backend more effectively with sql queries. This becomes especially relevant when you hit the limits of Active Record Relations and the usual way of querying in rails. For instance, if you have dynamic sql queries that are hard to convert properly into ruby.
|
6
6
|
3. add other helper methods to work with your database, such as checking if relations exist, or if a migration has been run.
|
7
7
|
|
8
|
-
Note that postgres is currently a requirement for this gem.
|
8
|
+
Note that postgres is currently a requirement for using arrays in this gem. If it becomes an issue send me a pull request or an issue or somethin.
|
9
|
+
Also note that the gem has not been tested outside of postgres.
|
9
10
|
|
10
11
|
## Basic Examples
|
11
12
|
```ruby
|
@@ -45,16 +46,12 @@ Or install it yourself as:
|
|
45
46
|
|
46
47
|
## Usage
|
47
48
|
|
48
|
-
### Apply to your ApplicationRecord class as such
|
49
|
+
### Apply to your ApplicationRecord class as such (or whatever subclass of ActiveRecord::Base you have)
|
49
50
|
|
50
51
|
```ruby
|
51
52
|
class ApplicationRecord < ActiveRecord::Base
|
52
53
|
self.abstract_class = true
|
53
54
|
include DynamicRecordsMeritfront
|
54
|
-
|
55
|
-
#DYNAMIC_SQL_RAW determines whether dynamic_sql method returns a ActiveRecord::Response object or an Array.
|
56
|
-
#They both have pros and cons. False returns the array.
|
57
|
-
DynamicRecordsMeritfront::DYNAMIC_SQL_RAW = false
|
58
55
|
end
|
59
56
|
```
|
60
57
|
|
@@ -72,10 +69,6 @@ ApplicationRecord.dynamic_sql('select * from users') #returns all user column in
|
|
72
69
|
|
73
70
|
with options:
|
74
71
|
- options not stated below: considered sql arguments, and will replace their ":option_name" with a sql argument. Always use sql arguments to avoid sql injection. Lists are converted into a format such as ```{1,2,3,4}```. Lists of lists are converted into ```(1,2,3), (4,5,6), (7,8,9)``` etc. So as to allow easy inserts/upserts.
|
75
|
-
- raw: whether to return a ActiveRecord::Response object or a hash when called on an abstract class (like ApplicationRecord). Default can be switched with DYNAMIC_SQL_RAW variable on the class level.
|
76
|
-
|
77
|
-
other less critical options:
|
78
|
-
|
79
72
|
- prepare: Defaults to true. Gets passed to ActiveRecord::Base.connection.exec_query as a parameter. Should change whether the command will be prepared, which means that on subsequent calls the command will be faster. Downsides are when, for example, the sql query has hard-coded arguments, the query always changes, causing technical issues as the number of prepared statements stack up.
|
80
73
|
- multi_query: allows more than one query (you can seperate an insert and an update with ';' I dont know how else to say it.)
|
81
74
|
this disables other options including sql_arguments. Not sure how it effects prepared statements. Not super useful.
|
@@ -248,7 +241,7 @@ obj.has_association?(:votes) #false
|
|
248
241
|
#### self.instaload_sql( *optional* name, insta_array, opts = { })
|
249
242
|
*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.
|
250
243
|
- name is passed to dynamic_sql and is the name of the sql request
|
251
|
-
- opts are passed to dynamic_sql
|
244
|
+
- opts are passed to dynamic_sql
|
252
245
|
- requires a list of instaload method output which provides information for how to treat each sql block.
|
253
246
|
|
254
247
|
```ruby
|
@@ -457,13 +450,34 @@ since things may be broken already, it seemed like a good time to do this.
|
|
457
450
|
- this also tells me that uniq'ing variables to decrease the number of them was a bad idea which could cause random failures.
|
458
451
|
- functionality improvements
|
459
452
|
- The biggest change is that names are now optional! name_modifiers is now depreciated functionality as it serves no useful purpose. Will leave in for compatibility but take out of documentation. Used to think the name was related to prepared statements. This will lead simpler ruby code.
|
460
|
-
- If name is left out, the name will be set to the location in your app which called the method. For example, when dynamic_sql was called from irb, the name was: "(irb):45:in `irb_binding'". This is done using stack trace functionality.
|
453
|
+
- If name is left out, the name will be set to the location in your app which called the method. For example, when dynamic_sql was called from irb, the name was: "(irb):45:in `irb_binding'". This is done using stack trace functionality. In another case the name was "app/models/report.rb:364:in `refresh_db_methods'"
|
461
454
|
- dynamic_instaload_sql is now just instaload_sql. dynamic_instaload_sql has been aliased.
|
462
455
|
- Name is optional on instaload_sql aswell
|
463
456
|
- MultiAttributeArrays (array's of arrays) which can be passed into dynamic_sql largely for inserts/upserts will now treat symbols as an attribute name. This leads to more consise sql without running into above error.
|
464
457
|
- When dynamic_sql errors out, it now posts some helpful information to the log.
|
465
458
|
- Added a test script. No experience testing, so its just a method you pass a model, and then it does a rollback to reverse any changes.
|
466
|
-
|
459
|
+
|
460
|
+
v3.0.6
|
461
|
+
- Further simplifications of the library. After looking further into ActiveRecord::Response objects I realized that they respond to .map .first [3] and other Array methods. In addition to this they have the .rows and .cols methods. Feel like I should of caught this earlier, but anyway, functionaly i will be setting DYNAMIC_SQL_RAW to true by default. docs-wise I am removing any reference to the raw option and DYNAMIC_SQL_RAW. This is mainly as ActiveRecord::Response acts as an Array with more functionality.
|
462
|
+
|
463
|
+
3.0.11
|
464
|
+
- error fix to do with multi row expressions and sql variables. No breaking changes.
|
465
|
+
|
466
|
+
3.0....
|
467
|
+
- nil is now supported somewhat as a variable value for dynamic_sql (and instaload_sql). It seeeeems to work... i am suspicous though. The way it works is by assuming the value type boolean and having the value be null.
|
468
|
+
- New way of creating instaload_sql, instaload, and dynamic_attach configurations which is more user friendly. Haven't put an example up yet. Good for polymorphism.
|
469
|
+
- added some debug logs for the instaload configuration
|
470
|
+
- 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
|
+
- 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
|
+
|
473
|
+
## Questions
|
474
|
+
- Q: does the name of a sql operation have anything to do with prepared statements?
|
475
|
+
- 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.
|
476
|
+
- Q: The default name of my sql statements looks like a stack trace? Whats going on?
|
477
|
+
- A: We set the location of where you called the function as the default name for easy debugging. Its not an error, we just take some info from the stacktrace. It also includes the method name which can provide some insite into what the query is doing. Makes logs alot nicer to look at.
|
478
|
+
- Q: Whats MeritFront?
|
479
|
+
- A: I am making a social media platform
|
480
|
+
|
467
481
|
## Contributing
|
468
482
|
|
469
483
|
Bug reports and pull requests are welcome on GitHub at https://github.com/LukeClancy/dynamic-records-meritfront. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/LukeClancy/dynamic-records-meritfront/blob/master/CODE_OF_CONDUCT.md).
|