pg_sql_caller 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14dd6a2499e57cd11eb961054e6afbdb48d86c8b61673918167e90189f812f75
4
- data.tar.gz: df298464b9fc9c04b1da3e70f1bd715c3a3f17174b41ba7175c7c34aed7c4c2f
3
+ metadata.gz: e4b2e038f51a96f0c3a4a1e03188c4b4749fdd02e22ec0ba743ea1fd98b52525
4
+ data.tar.gz: 9bdb58247ac0d41b9d802a0c447ff3b5505686aa91b689d53767420a8f3cb87d
5
5
  SHA512:
6
- metadata.gz: 4cce2039fe18a4368d7b28af7fe241570f239364824db3f0307b87529810fc6517373ccfdd8c7c5c9df21627d20120e6ff728a9a278e9f8b2ff4f72093475e7d
7
- data.tar.gz: 03e2c9a2d163f2b856662c6626a8a8aae7eecb32b604bd2db9c425cfa7df5da150ccd458e0ca28ceb04ac6f6777e4011dbaf1da3cf7609650f785ef4bdef9eed
6
+ metadata.gz: 8b9fe48fae8aaa5ed8888261e2d5751521f98775a2216f14563ad774814fb26221cd9f7f408d9995305dc7a1d4c5a2a382f4ca410f44b0f4cee20baa54908ba9
7
+ data.tar.gz: '0494140c6078a7d34427f0fcbdd58c1543fd2901a7d2746b7dad500ad2f5078409ad0579e5d84e703bf8abf48ae82e82eeb46b3aa89fda1af3317d8e75fa628c'
data/README.md CHANGED
@@ -60,7 +60,7 @@ To release a new version, update the version number in `version.rb`, and then ru
60
60
 
61
61
  ## Contributing
62
62
 
63
- Bug reports and pull requests are welcome on GitHub at https://github.com/senid231/pg_sql_caller. 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/[USERNAME]/sql_caller/blob/master/CODE_OF_CONDUCT.md).
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/didww/pg_sql_caller. 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/didww/sql_caller/blob/master/CODE_OF_CONDUCT.md).
64
64
 
65
65
 
66
66
  ## License
@@ -69,4 +69,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
69
69
 
70
70
  ## Code of Conduct
71
71
 
72
- Everyone interacting in the PGSqlCaller project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/senid231/pg_sql_caller/blob/master/CODE_OF_CONDUCT.md).
72
+ Everyone interacting in the PGSqlCaller project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/didww/pg_sql_caller/blob/master/CODE_OF_CONDUCT.md).
@@ -15,8 +15,7 @@ module PgSqlCaller
15
15
  :select_values,
16
16
  :execute,
17
17
  :select_all,
18
- :select_rows,
19
- :select_row
18
+ :select_rows
20
19
  ].freeze
21
20
 
22
21
  class_attribute :_model_class, instance_writer: false
@@ -56,23 +55,62 @@ module PgSqlCaller
56
55
  *CONNECTION_SQL_METHODS,
57
56
  :transaction_open?,
58
57
  :select_all_serialized,
58
+ :select_value_serialized,
59
+ :select_values_serialized,
60
+ :next_sequence_value,
61
+ :table_full_size,
62
+ :table_data_size,
63
+ :select_row,
59
64
  :transaction,
60
65
  :explain_analyze,
61
66
  :typecast_array,
62
67
  :sanitize_sql_array,
63
68
  :current_database,
64
- *CONNECTION_SQL_METHODS,
65
69
  to: :instance,
66
70
  type: :single
67
71
  )
68
72
 
69
73
  define_sql_methods(*CONNECTION_SQL_METHODS)
70
74
 
71
- delegate :transaction_open?, to: :connection
75
+ def transaction_open?
76
+ connection.send(:transaction_open?)
77
+ end
72
78
 
73
79
  def select_all_serialized(sql, *bindings)
74
80
  result = select_all(sql, *bindings)
75
- result.map { |row| row.map { |k, v| [k.to_sym, result.column_types[k].deserialize(v)] }.to_h }
81
+ result.map do |row|
82
+ row.map { |key, value| [key.to_sym, deserialize_result(result, key, value)] }.to_h
83
+ end
84
+ end
85
+
86
+ def select_value_serialized(sql, *bindings)
87
+ result = select_all(sql, *bindings)
88
+ key = result.first.keys.first
89
+ value = result.first.values.first
90
+ deserialize_result(result, key, value)
91
+ end
92
+
93
+ def select_values_serialized(sql, *bindings)
94
+ result = select_all(sql, *bindings)
95
+ result.map do |row|
96
+ row.map { |key, value| deserialize_result(result, key, value) }
97
+ end
98
+ end
99
+
100
+ def next_sequence_value(table_name)
101
+ select_value("SELECT last_value FROM #{table_name}_id_seq") + 1
102
+ end
103
+
104
+ def table_full_size(table_name)
105
+ select_value('SELECT pg_total_relation_size(?)', table_name)
106
+ end
107
+
108
+ def table_data_size(table_name)
109
+ select_value('SELECT pg_relation_size(?)', table_name)
110
+ end
111
+
112
+ def select_row(sql, *bindings)
113
+ select_rows(sql, *bindings)[0]
76
114
  end
77
115
 
78
116
  def transaction
@@ -104,6 +142,13 @@ module PgSqlCaller
104
142
 
105
143
  delegate :connection, to: :model_class
106
144
 
145
+ def deserialize_result(result, column_name, raw_value)
146
+ column_type = result.column_types[column_name]
147
+ return raw_value if column_type.nil?
148
+
149
+ column_type.deserialize(raw_value)
150
+ end
151
+
107
152
  def model_class
108
153
  return @model_class if defined?(@model_class)
109
154
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgSqlCaller
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = 'Postgresql Sql Caller for ActiveRecord'
12
12
  spec.description = 'Postgresql Sql Caller for ActiveRecord.'
13
- spec.homepage = 'https://github.com/senid231/pg_sql_caller'
13
+ spec.homepage = 'https://github.com/didww/pg_sql_caller'
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_sql_caller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-24 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -60,13 +60,13 @@ files:
60
60
  - lib/pg_sql_caller/base.rb
61
61
  - lib/pg_sql_caller/version.rb
62
62
  - sql_caller.gemspec
63
- homepage: https://github.com/senid231/pg_sql_caller
63
+ homepage: https://github.com/didww/pg_sql_caller
64
64
  licenses:
65
65
  - MIT
66
66
  metadata:
67
- homepage_uri: https://github.com/senid231/pg_sql_caller
68
- source_code_uri: https://github.com/senid231/pg_sql_caller
69
- changelog_uri: https://github.com/senid231/pg_sql_caller
67
+ homepage_uri: https://github.com/didww/pg_sql_caller
68
+ source_code_uri: https://github.com/didww/pg_sql_caller
69
+ changelog_uri: https://github.com/didww/pg_sql_caller
70
70
  post_install_message:
71
71
  rdoc_options: []
72
72
  require_paths:
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubygems_version: 3.1.2
85
+ rubygems_version: 3.0.8
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Postgresql Sql Caller for ActiveRecord