icebox 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,6 +6,8 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
+ gem "mysql", "~> 2.8.1"
10
+ gem "sequel", "~> 3.27.0"
9
11
  gem "shoulda", ">= 0"
10
12
  gem "bundler", "~> 1.0.0"
11
13
  gem "jeweler", "~> 1.6.4"
data/README.rdoc CHANGED
@@ -1,11 +1,29 @@
1
1
  = Icebox
2
2
 
3
- Icebox is (or will be, eventually) a Ruby library and command-line utility for
4
- interacting with Infobright Community Edition (ICE), an open-source,
5
- column-oriented database based on MySQL.
3
+ Icebox is a Ruby gem and command-line utility for interacting with Infobright
4
+ Community Edition (ICE), an open-source, column-oriented database based on
5
+ MySQL. It is still in the very earliest stages of development, and shouldn't be
6
+ used by anyone for anything.
7
+
8
+ I follow semantic versioning. In 0.x.y, there is no stable API and anything may
9
+ change at any time. Curious tinkerers who don't mind that should still at least
10
+ wait until 0.1.0, which I use to signify that others could conceivably find the
11
+ project useful.
12
+
13
+ == Example
14
+
15
+ # Icebox wraps around a Sequel database handle:
16
+ db = Sequel.mysql('test', socket: '/tmp/mysql-ib.sock')
17
+ box = Icebox::Icebox.new(db)
18
+
19
+ # From there, you can call handy functions:
20
+ box.create_table_as "output_table", "SELECT * FROM input_table"
21
+
22
+ (Command-line interface forthcoming.)
6
23
 
7
24
  == Contributing to Icebox
8
-
25
+
26
+ * Wait until 0.1.0
9
27
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
10
28
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
11
29
  * Fork the project
data/Rakefile CHANGED
@@ -11,6 +11,11 @@ rescue Bundler::BundlerError => e
11
11
  end
12
12
  require 'rake'
13
13
 
14
+ FileList['tasks/*'].each do |f|
15
+ require_relative f
16
+ end
17
+
18
+
14
19
  require 'jeweler'
15
20
  Jeweler::Tasks.new do |gem|
16
21
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
@@ -51,3 +56,4 @@ Rake::RDocTask.new do |rdoc|
51
56
  rdoc.rdoc_files.include('README*')
52
57
  rdoc.rdoc_files.include('lib/**/*.rb')
53
58
  end
59
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/bin/icebox ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'optparse'
5
+ require 'icebox'
6
+
7
+ opts = OptionParser.new do |opts|
8
+ opts.banner = "Icebox: Multitool for Infobright Community Edition"
9
+ opts.on_tail("-h", "-?", "--help", "Show this message") do
10
+ puts opts
11
+ exit
12
+ end
13
+ end
14
+ opts.parse!
data/data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *
2
+ !.gitignore
data/icebox.gemspec CHANGED
@@ -5,13 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "icebox"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Riley Goodside"]
12
- s.date = "2011-09-28"
12
+ s.date = "2011-10-05"
13
13
  s.description = "Ruby library and command-line utility for working with Infobright Community Edition"
14
14
  s.email = "riley.goodside@gmail.com"
15
+ s.executables = ["icebox"]
15
16
  s.extra_rdoc_files = [
16
17
  "LICENSE.txt",
17
18
  "README.rdoc"
@@ -23,8 +24,11 @@ Gem::Specification.new do |s|
23
24
  "README.rdoc",
24
25
  "Rakefile",
25
26
  "VERSION",
27
+ "bin/icebox",
28
+ "data/.gitignore",
26
29
  "icebox.gemspec",
27
30
  "lib/icebox.rb",
31
+ "tasks/scratch.rb",
28
32
  "test/helper.rb",
29
33
  "test/test_icebox.rb"
30
34
  ]
@@ -38,17 +42,23 @@ Gem::Specification.new do |s|
38
42
  s.specification_version = 3
39
43
 
40
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<mysql>, ["~> 2.8.1"])
46
+ s.add_development_dependency(%q<sequel>, ["~> 3.27.0"])
41
47
  s.add_development_dependency(%q<shoulda>, [">= 0"])
42
48
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
43
49
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
44
50
  s.add_development_dependency(%q<rcov>, [">= 0"])
45
51
  else
52
+ s.add_dependency(%q<mysql>, ["~> 2.8.1"])
53
+ s.add_dependency(%q<sequel>, ["~> 3.27.0"])
46
54
  s.add_dependency(%q<shoulda>, [">= 0"])
47
55
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
48
56
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
49
57
  s.add_dependency(%q<rcov>, [">= 0"])
50
58
  end
51
59
  else
60
+ s.add_dependency(%q<mysql>, ["~> 2.8.1"])
61
+ s.add_dependency(%q<sequel>, ["~> 3.27.0"])
52
62
  s.add_dependency(%q<shoulda>, [">= 0"])
53
63
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
64
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
data/lib/icebox.rb CHANGED
@@ -1,5 +1,38 @@
1
+ require 'sequel'
2
+
1
3
  module Icebox
2
- def self.do
3
- "Hello, world"
4
+ class Icebox
5
+ def initialize(db)
6
+ @db = db || Sequel.mysql('test', socket: '/tmp/mysql-ib.sock')
7
+ end
8
+
9
+ def create_table_as(table, sql)
10
+ view = "icebox_view_for_#{table}"
11
+ pipe = "/tmp/icebox_pipe_for_#{table}"
12
+
13
+ # Create view from SQL, extract layout, and make new table from it:
14
+ @db.create_or_replace_view view, sql
15
+ fields_definition = @db.schema(view).map do |col|
16
+ "#{col[0]} #{col[1][:db_type]}"
17
+ end.join(',')
18
+ @db.run "CREATE TABLE #{table} (#{fields_definition})"
19
+
20
+ # Simultaneously export and re-import CSV through FIFO pipe:
21
+ @db.disconnect # Needed for fork; Reconnects automatically
22
+ fork do
23
+ @db.run <<-SQL
24
+ SET @bh_pipemode = 'server';
25
+ LOAD DATA INFILE '#{pipe}' INTO TABLE #{table}
26
+ FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\\\';
27
+ SQL
28
+ end
29
+ @db.run <<-SQL
30
+ SET @bh_pipemode = 'client';
31
+ SELECT * FROM #{view} INTO OUTFILE '#{pipe}'
32
+ FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\\\'
33
+ SQL
34
+
35
+ @db.drop_view view
36
+ end
4
37
  end
5
38
  end
data/tasks/scratch.rb ADDED
@@ -0,0 +1,7 @@
1
+ ICEBOX_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ $LOAD_PATH.unshift(File.join(ICEBOX_ROOT, 'lib'))
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+
5
+ require 'icebox'
6
+
7
+ # Rakefile for quick little experiments
data/test/test_icebox.rb CHANGED
@@ -1,7 +1,29 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestIcebox < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ context "a basic CSV file" do
5
+ setup do
6
+ @db = Sequel.mysql('test', socket: '/tmp/mysql-ib.sock')
7
+ csv_body = <<-CSV.gsub(/^\s*/, '')
8
+ 0,"Every good boy deserves fudge."
9
+ 1,"A stitch in time saves nine."
10
+ 2,""
11
+ CSV
12
+ File.open('/tmp/input_table.csv', 'w') { |f| f.write csv_body }
13
+ @db.run <<-SQL
14
+ DROP TABLE IF EXISTS input_table;
15
+ CREATE TABLE input_table (number INTEGER, line TEXT);
16
+ LOAD DATA INFILE '/tmp/input_table.csv' INTO TABLE input_table
17
+ FIELDS TERMINATED BY ',' ENCLOSED BY '\\"';
18
+ SQL
19
+ end
20
+
21
+ should "copy a table with create_table_as" do
22
+ box = Icebox::Icebox.new(@db)
23
+ @db.run "DROP TABLE IF EXISTS output_table"
24
+ box.create_table_as "output_table", "SELECT * FROM input_table"
25
+ result = @db["SELECT COUNT(*) AS ct FROM output_table"].first[:ct]
26
+ assert_equal result, 3
27
+ end
6
28
  end
7
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-28 00:00:00.000000000Z
12
+ date: 2011-10-05 00:00:00.000000000Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mysql
16
+ requirement: &17081840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.1
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *17081840
25
+ - !ruby/object:Gem::Dependency
26
+ name: sequel
27
+ requirement: &17081320 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 3.27.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *17081320
14
36
  - !ruby/object:Gem::Dependency
15
37
  name: shoulda
16
- requirement: &16728660 !ruby/object:Gem::Requirement
38
+ requirement: &17080800 !ruby/object:Gem::Requirement
17
39
  none: false
18
40
  requirements:
19
41
  - - ! '>='
@@ -21,10 +43,10 @@ dependencies:
21
43
  version: '0'
22
44
  type: :development
23
45
  prerelease: false
24
- version_requirements: *16728660
46
+ version_requirements: *17080800
25
47
  - !ruby/object:Gem::Dependency
26
48
  name: bundler
27
- requirement: &16726400 !ruby/object:Gem::Requirement
49
+ requirement: &17080280 !ruby/object:Gem::Requirement
28
50
  none: false
29
51
  requirements:
30
52
  - - ~>
@@ -32,10 +54,10 @@ dependencies:
32
54
  version: 1.0.0
33
55
  type: :development
34
56
  prerelease: false
35
- version_requirements: *16726400
57
+ version_requirements: *17080280
36
58
  - !ruby/object:Gem::Dependency
37
59
  name: jeweler
38
- requirement: &16723700 !ruby/object:Gem::Requirement
60
+ requirement: &17079760 !ruby/object:Gem::Requirement
39
61
  none: false
40
62
  requirements:
41
63
  - - ~>
@@ -43,10 +65,10 @@ dependencies:
43
65
  version: 1.6.4
44
66
  type: :development
45
67
  prerelease: false
46
- version_requirements: *16723700
68
+ version_requirements: *17079760
47
69
  - !ruby/object:Gem::Dependency
48
70
  name: rcov
49
- requirement: &16706380 !ruby/object:Gem::Requirement
71
+ requirement: &17079220 !ruby/object:Gem::Requirement
50
72
  none: false
51
73
  requirements:
52
74
  - - ! '>='
@@ -54,11 +76,12 @@ dependencies:
54
76
  version: '0'
55
77
  type: :development
56
78
  prerelease: false
57
- version_requirements: *16706380
79
+ version_requirements: *17079220
58
80
  description: Ruby library and command-line utility for working with Infobright Community
59
81
  Edition
60
82
  email: riley.goodside@gmail.com
61
- executables: []
83
+ executables:
84
+ - icebox
62
85
  extensions: []
63
86
  extra_rdoc_files:
64
87
  - LICENSE.txt
@@ -70,8 +93,11 @@ files:
70
93
  - README.rdoc
71
94
  - Rakefile
72
95
  - VERSION
96
+ - bin/icebox
97
+ - data/.gitignore
73
98
  - icebox.gemspec
74
99
  - lib/icebox.rb
100
+ - tasks/scratch.rb
75
101
  - test/helper.rb
76
102
  - test/test_icebox.rb
77
103
  homepage: http://github.com/goodside/icebox
@@ -89,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
115
  version: '0'
90
116
  segments:
91
117
  - 0
92
- hash: 442249175712399011
118
+ hash: 2168865579570218248
93
119
  required_rubygems_version: !ruby/object:Gem::Requirement
94
120
  none: false
95
121
  requirements: