pakyow-data 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +0 -0
  3. data/LICENSE +4 -0
  4. data/README.md +29 -0
  5. data/lib/pakyow/data/adapters/abstract.rb +58 -0
  6. data/lib/pakyow/data/adapters/sql/commands.rb +58 -0
  7. data/lib/pakyow/data/adapters/sql/dataset_methods.rb +29 -0
  8. data/lib/pakyow/data/adapters/sql/differ.rb +76 -0
  9. data/lib/pakyow/data/adapters/sql/migrator/adapter_methods.rb +95 -0
  10. data/lib/pakyow/data/adapters/sql/migrator.rb +181 -0
  11. data/lib/pakyow/data/adapters/sql/migrators/automator.rb +49 -0
  12. data/lib/pakyow/data/adapters/sql/migrators/finalizer.rb +96 -0
  13. data/lib/pakyow/data/adapters/sql/runner.rb +49 -0
  14. data/lib/pakyow/data/adapters/sql/source_extension.rb +31 -0
  15. data/lib/pakyow/data/adapters/sql/types.rb +50 -0
  16. data/lib/pakyow/data/adapters/sql.rb +247 -0
  17. data/lib/pakyow/data/behavior/config.rb +28 -0
  18. data/lib/pakyow/data/behavior/lookup.rb +75 -0
  19. data/lib/pakyow/data/behavior/serialization.rb +40 -0
  20. data/lib/pakyow/data/connection.rb +103 -0
  21. data/lib/pakyow/data/container.rb +273 -0
  22. data/lib/pakyow/data/errors.rb +169 -0
  23. data/lib/pakyow/data/framework.rb +42 -0
  24. data/lib/pakyow/data/helpers.rb +11 -0
  25. data/lib/pakyow/data/lookup.rb +85 -0
  26. data/lib/pakyow/data/migrator.rb +182 -0
  27. data/lib/pakyow/data/object.rb +98 -0
  28. data/lib/pakyow/data/proxy.rb +262 -0
  29. data/lib/pakyow/data/result.rb +53 -0
  30. data/lib/pakyow/data/sources/abstract.rb +82 -0
  31. data/lib/pakyow/data/sources/ephemeral.rb +72 -0
  32. data/lib/pakyow/data/sources/relational/association.rb +43 -0
  33. data/lib/pakyow/data/sources/relational/associations/belongs_to.rb +47 -0
  34. data/lib/pakyow/data/sources/relational/associations/has_many.rb +54 -0
  35. data/lib/pakyow/data/sources/relational/associations/has_one.rb +54 -0
  36. data/lib/pakyow/data/sources/relational/associations/through.rb +67 -0
  37. data/lib/pakyow/data/sources/relational/command.rb +531 -0
  38. data/lib/pakyow/data/sources/relational/migrator.rb +101 -0
  39. data/lib/pakyow/data/sources/relational.rb +587 -0
  40. data/lib/pakyow/data/subscribers/adapters/memory.rb +153 -0
  41. data/lib/pakyow/data/subscribers/adapters/redis/pipeliner.rb +45 -0
  42. data/lib/pakyow/data/subscribers/adapters/redis/scripts/_shared.lua +73 -0
  43. data/lib/pakyow/data/subscribers/adapters/redis/scripts/expire.lua +16 -0
  44. data/lib/pakyow/data/subscribers/adapters/redis/scripts/persist.lua +15 -0
  45. data/lib/pakyow/data/subscribers/adapters/redis/scripts/register.lua +37 -0
  46. data/lib/pakyow/data/subscribers/adapters/redis.rb +209 -0
  47. data/lib/pakyow/data/subscribers.rb +148 -0
  48. data/lib/pakyow/data/tasks/bootstrap.rake +18 -0
  49. data/lib/pakyow/data/tasks/create.rake +22 -0
  50. data/lib/pakyow/data/tasks/drop.rake +32 -0
  51. data/lib/pakyow/data/tasks/finalize.rake +56 -0
  52. data/lib/pakyow/data/tasks/migrate.rake +24 -0
  53. data/lib/pakyow/data/tasks/reset.rake +18 -0
  54. data/lib/pakyow/data/types.rb +37 -0
  55. data/lib/pakyow/data.rb +27 -0
  56. data/lib/pakyow/environment/data/auto_migrate.rb +31 -0
  57. data/lib/pakyow/environment/data/config.rb +54 -0
  58. data/lib/pakyow/environment/data/connections.rb +76 -0
  59. data/lib/pakyow/environment/data/memory_db.rb +23 -0
  60. data/lib/pakyow/validations/unique.rb +26 -0
  61. metadata +186 -0
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+ require "securerandom"
5
+
6
+ require "pakyow/support/core_refinements/array/ensurable"
7
+
8
+ require "pakyow/data/sources/abstract"
9
+
10
+ module Pakyow
11
+ module Data
12
+ module Sources
13
+ class Ephemeral < Abstract
14
+ using Support::Refinements::Array::Ensurable
15
+ attr_reader :type, :qualifications
16
+
17
+ include Enumerable
18
+
19
+ extend Forwardable
20
+ def_delegator :to_a, :each
21
+
22
+ def initialize(type, **qualifications)
23
+ @type = type
24
+ @qualifications = { type: @type }.merge(qualifications)
25
+ __setobj__([])
26
+ end
27
+
28
+ def set(results)
29
+ tap do
30
+ __setobj__(
31
+ results.map { |result|
32
+ unless result.key?(:id)
33
+ result[:id] = SecureRandom.uuid
34
+ end
35
+
36
+ result
37
+ }
38
+ )
39
+
40
+ yield self if block_given?
41
+ end
42
+ end
43
+
44
+ def to_ary
45
+ to_a
46
+ end
47
+
48
+ def to_a
49
+ Array.ensure(__getobj__)
50
+ end
51
+
52
+ def one
53
+ to_a.first
54
+ end
55
+
56
+ COMMANDS = %i(set).freeze
57
+ def command?(maybe_command_name)
58
+ COMMANDS.include?(maybe_command_name)
59
+ end
60
+
61
+ def command(maybe_command_name)
62
+ method(maybe_command_name)
63
+ end
64
+
65
+ # @api private
66
+ def source_name
67
+ @type
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/inflector"
4
+
5
+ module Pakyow
6
+ module Data
7
+ module Sources
8
+ class Relational
9
+ class Association
10
+ attr_reader :name, :query, :source, :associated_source_name, :associated_source
11
+
12
+ # @api private
13
+ attr_writer :associated_source
14
+
15
+ def initialize(name:, query:, source:, associated_source_name:)
16
+ @name = case result_type
17
+ when :one
18
+ Support.inflector.singularize(name).to_sym
19
+ when :many
20
+ Support.inflector.pluralize(name).to_sym
21
+ end
22
+
23
+ @query, @source, @associated_source_name = query, source, Support.inflector.pluralize(associated_source_name).to_sym
24
+
25
+ @internal = false
26
+ end
27
+
28
+ def dependent_source_names
29
+ [@associated_source_name]
30
+ end
31
+
32
+ def internal?
33
+ @internal == true
34
+ end
35
+
36
+ def internal!
37
+ @internal = true
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/data/sources/relational/association"
4
+
5
+ module Pakyow
6
+ module Data
7
+ module Sources
8
+ class Relational
9
+ module Associations
10
+ class BelongsTo < Association
11
+ def type
12
+ :belongs
13
+ end
14
+
15
+ def specific_type
16
+ :belongs_to
17
+ end
18
+
19
+ def result_type
20
+ :one
21
+ end
22
+
23
+ def foreign_key_field
24
+ :"#{@name}_#{@associated_source.primary_key_field}"
25
+ end
26
+
27
+ def foreign_key_type
28
+ @associated_source.primary_key_type
29
+ end
30
+
31
+ def query_field
32
+ foreign_key_field
33
+ end
34
+
35
+ def associated_query_field
36
+ @associated_source.primary_key_field
37
+ end
38
+
39
+ def dependents?
40
+ false
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/inflector"
4
+
5
+ require "pakyow/data/sources/relational/association"
6
+
7
+ module Pakyow
8
+ module Data
9
+ module Sources
10
+ class Relational
11
+ module Associations
12
+ class HasMany < Association
13
+ attr_reader :associated_name, :dependent
14
+
15
+ def initialize(as:, dependent:, **common_args)
16
+ super(**common_args)
17
+
18
+ @associated_name = Support.inflector.pluralize(as).to_sym
19
+ @dependent = dependent
20
+ end
21
+
22
+ def type
23
+ :has
24
+ end
25
+
26
+ def specific_type
27
+ :has_many
28
+ end
29
+
30
+ def result_type
31
+ :many
32
+ end
33
+
34
+ def foreign_key_field
35
+ associated_query_field
36
+ end
37
+
38
+ def query_field
39
+ @source.primary_key_field
40
+ end
41
+
42
+ def associated_query_field
43
+ :"#{Support.inflector.singularize(@associated_name)}_#{@source.primary_key_field}"
44
+ end
45
+
46
+ def dependents?
47
+ true
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pakyow/support/inflector"
4
+
5
+ require "pakyow/data/sources/relational/association"
6
+
7
+ module Pakyow
8
+ module Data
9
+ module Sources
10
+ class Relational
11
+ module Associations
12
+ class HasOne < Association
13
+ attr_reader :associated_name, :dependent
14
+
15
+ def initialize(as:, dependent:, **common_args)
16
+ super(**common_args)
17
+
18
+ @associated_name = Support.inflector.singularize(as).to_sym
19
+ @dependent = dependent
20
+ end
21
+
22
+ def type
23
+ :has
24
+ end
25
+
26
+ def specific_type
27
+ :has_one
28
+ end
29
+
30
+ def result_type
31
+ :one
32
+ end
33
+
34
+ def foreign_key_field
35
+ associated_query_field
36
+ end
37
+
38
+ def query_field
39
+ @source.primary_key_field
40
+ end
41
+
42
+ def associated_query_field
43
+ :"#{@associated_name}_#{@source.primary_key_field}"
44
+ end
45
+
46
+ def dependents?
47
+ true
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+
5
+ require "pakyow/support/inflector"
6
+
7
+ require "pakyow/data/sources/relational/association"
8
+
9
+ module Pakyow
10
+ module Data
11
+ module Sources
12
+ class Relational
13
+ module Associations
14
+ class Through
15
+ attr_reader :joining_source_name, :joining_source
16
+
17
+ # @api private
18
+ attr_writer :joining_source
19
+
20
+ extend Forwardable
21
+ def_delegators :@association, :associated_name, :associated_query_field, :associated_source=, :associated_source,
22
+ :associated_source_name, :dependent, :dependents?, :name, :query, :query_field, :result_type,
23
+ :source, :specific_type
24
+
25
+ def initialize(association, joining_source_name:)
26
+ @association, @joining_source_name = association, Support.inflector.pluralize(joining_source_name).to_sym
27
+
28
+ @internal = false
29
+ end
30
+
31
+ def type
32
+ :through
33
+ end
34
+
35
+ def dependent_source_names
36
+ [@association.associated_source_name, @joining_source_name]
37
+ end
38
+
39
+ def left_name
40
+ Support.inflector.singularize(@association.name).to_sym
41
+ end
42
+
43
+ def left_foreign_key_field
44
+ :"#{left_name}_#{@association.associated_source.primary_key_field}"
45
+ end
46
+
47
+ def right_name
48
+ Support.inflector.singularize(@association.associated_name).to_sym
49
+ end
50
+
51
+ def right_foreign_key_field
52
+ :"#{right_name}_#{@association.source.primary_key_field}"
53
+ end
54
+
55
+ def internal?
56
+ @internal == true
57
+ end
58
+
59
+ def internal!
60
+ @internal = true
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end