db_automate 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a1975eb98778aa55cf7bbeb9d34533a6f17d8f6
4
+ data.tar.gz: 55d6b63bd970236c69a7c27d10f10e7f4bb7ad89
5
+ SHA512:
6
+ metadata.gz: a09d84bb2f6d33080fc5caf3c0151f62391bf5ae1be503d0ff244f0bbdfbc4fb7dfc6579733454e48e4b6decd2c2844a04e27c13a9d8dd36e5d119d37d2ea29f
7
+ data.tar.gz: faad753e59f808a48c40c2ecc72afeaaf0bb2f8526390735b5d7a7b74ce2b9d2199e24076a97286ee2b6b81f56c5654e5c6c892a7ccbe3d87098b063b1837919
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+
24
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in db_automate.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Dave Rowan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,121 @@
1
+ # DBAutomate
2
+
3
+ If you actually happened upon this, please note that this project is in its earliest stages and has not been developed much yet.
4
+ The README found here is mainly for the purposes of [Readme Driven Development][rdd] so that I can try to get the API right
5
+ first, and hopefully eliminate lots of churn along the way.
6
+
7
+ If you dare to read on, your suggestions are welcome if you believe
8
+ you have an idea that would make the API and project as a whole better. Just drop me a line, or better yet fork the project and
9
+ create a pull request showing your thoughts.
10
+
11
+ Let it be known that I have many ideas swarming on how to expand this project to do
12
+ more, but I want to start small and get some basics right first. So for now, it is what it is, or more accurately,
13
+ it will be what it is below.
14
+
15
+ Yes, I know what is below is quite messy at this stage, and there is a lot of stuff which will quickly become too much stuff
16
+ and need to be moved to a wiki somewhere with dense digital vegetation. Bare with me!
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'db_automate'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install db_automate
31
+
32
+ ## Usage
33
+
34
+ Initialize a query object with a sql statement and run the query against database 'my_db'
35
+
36
+ my_query = Query.new(:sql => 'select first_name, last_name, email from users')
37
+ my_query.run(:db => :my_db)
38
+
39
+ Give your query a name to make it more
40
+ my_query.name = 'user info'
41
+
42
+ Most query attributes are able to be set in an initialization block
43
+
44
+ my_query = Query.new do |qry|
45
+ qry.name = 'user info'
46
+ qry.db = :my_db
47
+ qry.sql = 'select first_name, last_name, email from users'
48
+ qry.export 'my_query_results', :csv, :xlsx, :export_dir => 'Desktop/query_data'
49
+ end
50
+
51
+ The key passed to #db should be a top-level key in your YAML config file.
52
+
53
+ my_db:
54
+ adapter: mysql
55
+ server: localhost
56
+ username: dave
57
+ password: parties
58
+
59
+ Tell DBAutomate where to find your config file:
60
+
61
+ DBAutomate.config_file = 'my/db/configs.yml'
62
+
63
+ For more complex SQL, pass in the path (relative or absolute) to a file containing your sql
64
+
65
+ my_query.sql = 'sql/my_select_query.sql'
66
+
67
+ By default if only a file name is given and no path, then DBAutomate will search in the current directory and in a subdirectory named 'sql' if it exists.
68
+ You may change the default search path of DBAutomate:
69
+
70
+ DBAutomate.sql_dir = 'relative_path/'
71
+ DBAutomate.sql_dir = '/Users/me/store/all/my/sql/here/absolutely'
72
+
73
+ And execute the query
74
+
75
+ my_query.run
76
+
77
+ Check for results and do stuff with them
78
+
79
+ if my_query.results?
80
+ # do things. . .
81
+ end
82
+
83
+ results = my_query.results
84
+ puts 'query #{my_query.name} returned #{results.length} rows'
85
+ puts 'columns: #{results.headers.join(", ")}'
86
+
87
+ Export your results
88
+
89
+ my_query.export_csv
90
+ # => creates user_info.csv in the current directory
91
+
92
+ my_query.export_xlsx :export_dir => '/home/users/me'
93
+ # => create user_info.xlsx in /home/users/me
94
+
95
+ For a more configurable multi format export, you may like the #export method. Pass it a configuration hash. . .
96
+
97
+ my_query.export :format => [:csv, :xlsx], :file_name => 'user info query results', :export_dir => DESKTOP_PATH
98
+
99
+ . . . Or a block
100
+
101
+ my_query.export do |exp|
102
+ exp.format = :csv, :xlsx
103
+ exp.headers = false
104
+ exp.file_name = 'user info query results'
105
+ exp.export_dir = DESKTOP_PATH
106
+ end
107
+
108
+ Or configure a default export directory for DBAutomate
109
+
110
+ DBAutomate.export_dir = '/my/given/export/path'
111
+
112
+
113
+ ## Contributing
114
+
115
+ 1. Fork it ( https://github.com/DRowan99/db_automate/fork )
116
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
117
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
118
+ 4. Push to the branch (`git push origin my-new-feature`)
119
+ 5. Create a new Pull Request
120
+
121
+ [rdd]: http://tom.preston-werner.com/2010/08/23/readme-driven-development.html
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :test => :spec
7
+
8
+ task :console do
9
+ exec "irb -r db_automate -I ./lib"
10
+ end
11
+
12
+ task :c => :console
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'db_automate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "db_automate"
8
+ spec.version = DBAutomate::VERSION
9
+ spec.authors = ["Dave Rowan"]
10
+ spec.email = ["drowan99@gmail.com"]
11
+ spec.summary = 'An easy way to automate database queries and export the results with Ruby.'
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "db_automate/version"
2
+
3
+ module DBAutomate
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module DBAutomate
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,98 @@
1
+ require 'db_automate'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Allows RSpec to persist some state between runs in order to support
56
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
57
+ # you configure your source control system to ignore this file.
58
+ config.example_status_persistence_file_path = "spec/examples.txt"
59
+
60
+ # Limits the available syntax to the non-monkey patched syntax that is
61
+ # recommended. For more details, see:
62
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
63
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
65
+ config.disable_monkey_patching!
66
+
67
+ # This setting enables warnings. It's recommended, but in some cases may
68
+ # be too noisy due to issues in dependencies.
69
+ config.warnings = true
70
+
71
+ # Many RSpec users commonly either run the entire suite or an individual
72
+ # file, and it's useful to allow more verbose output when running an
73
+ # individual spec file.
74
+ if config.files_to_run.one?
75
+ # Use the documentation formatter for detailed output,
76
+ # unless a formatter has already been configured
77
+ # (e.g. via a command-line flag).
78
+ config.default_formatter = 'doc'
79
+ end
80
+
81
+ # Print the 10 slowest examples and example groups at the
82
+ # end of the spec run, to help surface which specs are running
83
+ # particularly slow.
84
+ config.profile_examples = 10
85
+
86
+ # Run specs in random order to surface order dependencies. If you find an
87
+ # order dependency and want to debug it, you can fix the order by providing
88
+ # the seed, which is printed after each run.
89
+ # --seed 1234
90
+ config.order = :random
91
+
92
+ # Seed global randomization in this process using the `--seed` CLI option.
93
+ # Setting this allows you to use `--seed` to deterministically reproduce
94
+ # test failures related to randomization by passing the same `--seed` value
95
+ # as the one that triggered the failure.
96
+ Kernel.srand config.seed
97
+ =end
98
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: db_automate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dave Rowan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - drowan99@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - db_automate.gemspec
69
+ - lib/db_automate.rb
70
+ - lib/db_automate/version.rb
71
+ - spec/spec_helper.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: An easy way to automate database queries and export the results with Ruby.
96
+ test_files:
97
+ - spec/spec_helper.rb