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 +4 -4
- data/README.md +2 -2
- data/lib/pg_sql_caller/base.rb +51 -6
- data/lib/pg_sql_caller/version.rb +1 -1
- data/sql_caller.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ef5ec8d44b5fb60d0a49245117f1b1c060a01dd2c6939ab15e544139d3396ac
|
4
|
+
data.tar.gz: db7e646d27d678d7d3b3a9284416e53602f979d7766a3746f9032c9685ef1d57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
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/
|
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).
|
data/lib/pg_sql_caller/base.rb
CHANGED
@@ -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 :
|
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
|
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
|
-
|
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)
|
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/
|
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
|
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:
|
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/
|
63
|
+
homepage: https://github.com/didww/pg_sql_caller
|
64
64
|
licenses:
|
65
65
|
- MIT
|
66
66
|
metadata:
|
67
|
-
homepage_uri: https://github.com/
|
68
|
-
source_code_uri: https://github.com/
|
69
|
-
changelog_uri: https://github.com/
|
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.
|
85
|
+
rubygems_version: 3.1.6
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Postgresql Sql Caller for ActiveRecord
|