pg_sql_caller 0.1.0 → 0.2.1

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: 14dd6a2499e57cd11eb961054e6afbdb48d86c8b61673918167e90189f812f75
4
- data.tar.gz: df298464b9fc9c04b1da3e70f1bd715c3a3f17174b41ba7175c7c34aed7c4c2f
3
+ metadata.gz: 1ef5ec8d44b5fb60d0a49245117f1b1c060a01dd2c6939ab15e544139d3396ac
4
+ data.tar.gz: db7e646d27d678d7d3b3a9284416e53602f979d7766a3746f9032c9685ef1d57
5
5
  SHA512:
6
- metadata.gz: 4cce2039fe18a4368d7b28af7fe241570f239364824db3f0307b87529810fc6517373ccfdd8c7c5c9df21627d20120e6ff728a9a278e9f8b2ff4f72093475e7d
7
- data.tar.gz: 03e2c9a2d163f2b856662c6626a8a8aae7eecb32b604bd2db9c425cfa7df5da150ccd458e0ca28ceb04ac6f6777e4011dbaf1da3cf7609650f785ef4bdef9eed
6
+ metadata.gz: 36fd432ed72e303ba3f2bdea04fe96fa57ea1d875ef36939281cabe9be45596991fc8ee371a25d0639ddf022695cf1b79a15a0b54f5aa3c3c29f98ff045a0c1e
7
+ data.tar.gz: 81430e4e0edc1f3a4efa02723b3b3da93515dc937d92bcf6b1ad9d7db24610e8a3d3ea2fc9f6e8b7b61c06c59a9a21b18f45a040e303c12d2b418845e1e6ea61
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,64 @@ 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
+ delegate :connection, to: :model_class
76
+
77
+ def transaction_open?
78
+ connection.send(:transaction_open?)
79
+ end
72
80
 
73
81
  def select_all_serialized(sql, *bindings)
74
82
  result = select_all(sql, *bindings)
75
- result.map { |row| row.map { |k, v| [k.to_sym, result.column_types[k].deserialize(v)] }.to_h }
83
+ result.map do |row|
84
+ row.map { |key, value| [key.to_sym, deserialize_result(result, key, value)] }.to_h
85
+ end
86
+ end
87
+
88
+ def select_value_serialized(sql, *bindings)
89
+ result = select_all(sql, *bindings)
90
+ key = result.first.keys.first
91
+ value = result.first.values.first
92
+ deserialize_result(result, key, value)
93
+ end
94
+
95
+ def select_values_serialized(sql, *bindings)
96
+ result = select_all(sql, *bindings)
97
+ result.map do |row|
98
+ row.map { |key, value| deserialize_result(result, key, value) }
99
+ end
100
+ end
101
+
102
+ def next_sequence_value(table_name)
103
+ select_value("SELECT last_value FROM #{table_name}_id_seq") + 1
104
+ end
105
+
106
+ def table_full_size(table_name)
107
+ select_value('SELECT pg_total_relation_size(?)', table_name)
108
+ end
109
+
110
+ def table_data_size(table_name)
111
+ select_value('SELECT pg_relation_size(?)', table_name)
112
+ end
113
+
114
+ def select_row(sql, *bindings)
115
+ select_rows(sql, *bindings)[0]
76
116
  end
77
117
 
78
118
  def transaction
@@ -102,7 +142,12 @@ module PgSqlCaller
102
142
 
103
143
  private
104
144
 
105
- delegate :connection, to: :model_class
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
106
151
 
107
152
  def model_class
108
153
  return @model_class if defined?(@model_class)
@@ -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.1'
5
5
  end
data/sql_caller.gemspec CHANGED
@@ -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.1
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: 2023-02-08 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.1.6
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Postgresql Sql Caller for ActiveRecord