sql_pluck 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/LICENSE +21 -0
- data/README.md +19 -0
- data/lib/sql_pluck.rb +33 -0
- data/sql_pluck.gemspec +16 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d9f5086d4cb495cb7c516e7163fb066f22123cdd223e6a7b6443c722a0ef2785
|
4
|
+
data.tar.gz: 8efe9c3b4ebad21a60ed99ccd08b241bdeaced31e189871049d0fe1d09aa0904
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47b031b25c4502ccb3ce3fff20b2db3d248828d7743c1e542ff1ae71b9201eba1cfcc6664710890b0bd8dae51a1bc9945e8aaced86a9ff989c6f7f96253b4a14
|
7
|
+
data.tar.gz: 48b6df878922ec6ff1fa91e35eb3aad88e4a2412839fda6552ec4e450475fe8cae17f60ac5212333694b8735800120e6033606fb7ac85fba9be635333ea6b904
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Minero Aoki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# sql_pluck gem
|
2
|
+
|
3
|
+
Provide #pluck_by_sql method for Rails ActiveRecord models.
|
4
|
+
You can execute arbitrary SQL and get bare attribute values without
|
5
|
+
creating ActiveRecord objects, while values are casted to appropreate types.
|
6
|
+
|
7
|
+
## Usage:
|
8
|
+
|
9
|
+
```
|
10
|
+
class SomeModel < ActiveRecord::Base
|
11
|
+
extend SQLPluck
|
12
|
+
end
|
13
|
+
|
14
|
+
SomeModel.pluck_by_sql('select id, name from some_model where id % 777 = 0')
|
15
|
+
# => [[777, 'name777'], [1554, 'name1554'], ...]
|
16
|
+
|
17
|
+
SomeModel.pluck_by_sql(['select id, name from some_model where created_at > ?', time])
|
18
|
+
# => [[1901, 'name1901'], [1902, 'name1902'], ...]
|
19
|
+
```
|
data/lib/sql_pluck.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
##
|
2
|
+
# Provides #pluck_by_sql method.
|
3
|
+
#
|
4
|
+
# Usage:
|
5
|
+
# class SomeModel < ActiveRecord::Base
|
6
|
+
# extend SQLPluck
|
7
|
+
# end
|
8
|
+
# SomeModel.pluck_by_sql(['select * from some_model where created_at > ?', time])
|
9
|
+
#
|
10
|
+
module SQLPluck
|
11
|
+
##
|
12
|
+
# Executes +sql+ as SQL SELECT statement and
|
13
|
+
# returns the result as an array of array of field values,
|
14
|
+
# like .pluck method.
|
15
|
+
#
|
16
|
+
def pluck_by_sql(sql, binds = [])
|
17
|
+
rs = connection.select_all(sanitize_sql(sql), "#{name} Load", binds)
|
18
|
+
types = rs.column_types
|
19
|
+
rs.map {|record| cast_record(record, types) }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def cast_record(record, types)
|
25
|
+
record.map {|name, string| types[name].type_cast(string) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if defined?(ActiveRecord::Type)
|
30
|
+
class ActiveRecord::Type::Value # reopen
|
31
|
+
public :type_cast
|
32
|
+
end
|
33
|
+
end
|
data/sql_pluck.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.platform = Gem::Platform::RUBY
|
3
|
+
s.name = 'sql_pluck'
|
4
|
+
s.version = '1.0.0'
|
5
|
+
s.summary = 'Provide #pluck_by_sql for Rails ActiveRecord models'
|
6
|
+
s.license = 'MIT'
|
7
|
+
|
8
|
+
s.author = ['Minero Aoki']
|
9
|
+
s.email = 'aamine@loveruby.net'
|
10
|
+
s.homepage = 'https://github.com/aamine/sql_pluck'
|
11
|
+
|
12
|
+
s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
|
13
|
+
s.require_path = 'lib'
|
14
|
+
|
15
|
+
s.add_dependency 'activerecord', '~> 4.0'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sql_pluck
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Minero Aoki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
description:
|
28
|
+
email: aamine@loveruby.net
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- lib/sql_pluck.rb
|
37
|
+
- sql_pluck.gemspec
|
38
|
+
homepage: https://github.com/aamine/sql_pluck
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.0.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: 'Provide #pluck_by_sql for Rails ActiveRecord models'
|
61
|
+
test_files: []
|