associate_jsonb 0.0.2 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +145 -31
- data/Rakefile +1 -3
- data/lib/associate_jsonb.rb +111 -2
- data/lib/associate_jsonb/arel_extensions/nodes/binary.rb +14 -0
- data/lib/associate_jsonb/arel_extensions/nodes/table_alias.rb +38 -0
- data/lib/associate_jsonb/arel_extensions/table.rb +40 -0
- data/lib/associate_jsonb/arel_extensions/visitors/postgresql.rb +113 -0
- data/lib/associate_jsonb/arel_extensions/visitors/visitor.rb +19 -0
- data/lib/associate_jsonb/arel_nodes/jsonb/attribute.rb +38 -0
- data/lib/associate_jsonb/arel_nodes/sql_casted_binary.rb +20 -0
- data/lib/associate_jsonb/arel_nodes/sql_casted_equality.rb +26 -12
- data/lib/associate_jsonb/associations/alias_tracker.rb +13 -0
- data/lib/associate_jsonb/associations/association_scope.rb +18 -45
- data/lib/associate_jsonb/associations/belongs_to_association.rb +8 -8
- data/lib/associate_jsonb/associations/builder/belongs_to.rb +5 -3
- data/lib/associate_jsonb/associations/join_dependency.rb +21 -0
- data/lib/associate_jsonb/attribute_methods.rb +19 -0
- data/lib/associate_jsonb/attribute_methods/read.rb +15 -0
- data/lib/associate_jsonb/connection_adapters/schema_creation.rb +167 -0
- data/lib/associate_jsonb/connection_adapters/schema_definitions/add_jsonb_foreign_key_function.rb +9 -0
- data/lib/associate_jsonb/connection_adapters/schema_definitions/add_jsonb_nested_set_function.rb +9 -0
- data/lib/associate_jsonb/connection_adapters/schema_definitions/alter_table.rb +40 -0
- data/lib/associate_jsonb/connection_adapters/schema_definitions/constraint_definition.rb +60 -0
- data/lib/associate_jsonb/connection_adapters/schema_definitions/reference_definition.rb +102 -0
- data/lib/associate_jsonb/connection_adapters/schema_definitions/table.rb +12 -0
- data/lib/associate_jsonb/connection_adapters/schema_definitions/table_definition.rb +25 -0
- data/lib/associate_jsonb/connection_adapters/schema_statements.rb +116 -0
- data/lib/associate_jsonb/persistence.rb +14 -0
- data/lib/associate_jsonb/predicate_builder.rb +15 -0
- data/lib/associate_jsonb/reflection.rb +2 -2
- data/lib/associate_jsonb/relation/where_clause.rb +19 -0
- data/lib/associate_jsonb/version.rb +1 -1
- data/lib/associate_jsonb/with_store_attribute.rb +59 -23
- metadata +34 -10
- data/lib/associate_jsonb/arel_node_extensions/binary.rb +0 -12
- data/lib/associate_jsonb/connection_adapters/reference_definition.rb +0 -64
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AssociateJsonb
|
4
|
-
module ConnectionAdapters
|
5
|
-
module ReferenceDefinition #:nodoc:
|
6
|
-
# rubocop:disable Metrics/ParameterLists
|
7
|
-
def initialize(
|
8
|
-
name,
|
9
|
-
store: false,
|
10
|
-
**options
|
11
|
-
)
|
12
|
-
@store = store && store.to_sym
|
13
|
-
|
14
|
-
super(name, **options)
|
15
|
-
end
|
16
|
-
# rubocop:enable Metrics/ParameterLists
|
17
|
-
|
18
|
-
def add_to(table)
|
19
|
-
return super unless store
|
20
|
-
|
21
|
-
should_add_col = false
|
22
|
-
if table.respond_to? :column_exists?
|
23
|
-
should_add_col = !table.column_exists?(store)
|
24
|
-
elsif table.respond_to? :columns
|
25
|
-
should_add_col = table.columns.none? {|col| col.name.to_sym == store}
|
26
|
-
end
|
27
|
-
|
28
|
-
table.column(store, :jsonb, null: false, default: {}) if should_add_col
|
29
|
-
|
30
|
-
return unless index
|
31
|
-
|
32
|
-
# should_add_idx = false
|
33
|
-
# if table.respond_to? :index_exists?
|
34
|
-
# should_add_idx = !table.index_exists?([ store ], using: :gin)
|
35
|
-
# elsif table.respond_to? :indexes
|
36
|
-
# should_add_idx = table.indexes.none? do |idx, opts|
|
37
|
-
# (idx == [ store ]) \
|
38
|
-
# && (opts == { using: :gin })
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# table.index([ store ], using: :gin) if should_add_idx
|
43
|
-
|
44
|
-
column_names.each do |column_name|
|
45
|
-
table.index(
|
46
|
-
"CAST (\"#{store}\"->'#{column_name}' AS #{@type || :bigint})",
|
47
|
-
using: :btree,
|
48
|
-
name: "index_#{table.name}_on_#{store}_#{column_name}"
|
49
|
-
)
|
50
|
-
|
51
|
-
table.index(
|
52
|
-
"(#{store}->>'#{column_name}')",
|
53
|
-
using: :btree,
|
54
|
-
name: "index_#{table.name}_on_#{store}_#{column_name}_text"
|
55
|
-
)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
protected
|
60
|
-
|
61
|
-
attr_reader :store
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|