theman 0.1.0 → 0.1.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.
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The man getting you down?
4
4
 
5
- Theman lets you import lots of data into postgres very fast.
5
+ Theman lets you import lots of data into PostgreSQL very fast.
6
6
 
7
7
  == Installation
8
8
 
@@ -36,7 +36,7 @@ Say we have a csv file called <tt>sample.csv</tt> with 220 rows:
36
36
 
37
37
  == Advanced usage with Active Record and an existing model
38
38
 
39
- Theman will call the +create!+ method if you pass in a block.
39
+ Theman will call the <tt>create!</tt> method if you pass in a block.
40
40
 
41
41
  conn = ActiveRecord::Base.connection.raw_connection
42
42
 
@@ -58,28 +58,26 @@ Theman will call the +create!+ method if you pass in a block.
58
58
 
59
59
  => 220
60
60
 
61
- In the above example we omitted the last 15 rows, made some things null,
62
- added a primary key and changed some column data types to something else.
61
+ In the above example we omitted the last 15 rows, made some things null and
62
+ specified some column data types.
63
63
 
64
64
  If you do not provide a table block your columns will be VARCHAR(255); you
65
65
  can cherry pick the columns that you want to change the data types for.
66
66
 
67
- The temp table has no id column by default, but you can add one using the options
68
- hash or calling +add_primary_key+, this will add the agents_pkey column.
69
-
70
- WARNING: if you have user input in your sed commands, don't.
67
+ The temp table has no id column by default, but you can add one by calling
68
+ +add_primary_key!+, this will add the +agents_pkey+ column.
71
69
 
72
70
  == Drop on commit
73
71
 
74
72
  If you want to use <tt>ON COMMIT DROP</tt> you will need to pass in
75
73
  <tt>:on_commit => :drop</tt> into options and do everthing inside a transacton.
76
74
 
77
- agent = Theman::Agency.new conn, csv, :on_commit => :drop
75
+ agent = Theman::Agency.new conn, 'sample.csv', :on_commit => :drop
78
76
 
79
- agent.transaction do
80
- agent.create!
81
- # do stuff
82
- end
77
+ agent.transaction do
78
+ agent.create!
79
+ # do stuff
80
+ end
83
81
 
84
82
  == No headers
85
83
 
@@ -35,6 +35,10 @@ module Theman
35
35
  end
36
36
  @columns << [sym_col, type, *args]
37
37
  end
38
+
39
+ def include?(sym_col)
40
+ @columns.map{|column| column[0] }.include?(sym_col)
41
+ end
38
42
 
39
43
  def column_to_sql(name, type, options = {}) #:nodoc
40
44
  sql = [quote_column_name(name)]
data/lib/theman/agency.rb CHANGED
@@ -125,9 +125,11 @@ module Theman
125
125
  pipe_it
126
126
  end
127
127
 
128
- # adds a serial column called agents_pkey and sets as primary key
128
+ # adds a serial column called id and sets as primary key
129
+ # if your data allready has a column called id the column will be called agents_pkey
129
130
  def add_primary_key!
130
- connection.exec "ALTER TABLE #{table_name} ADD COLUMN agents_pkey serial PRIMARY KEY;"
131
+ name = @columns.include?(:id) ? "agents_pkey" : "id"
132
+ connection.exec "ALTER TABLE #{table_name} ADD COLUMN #{name} serial PRIMARY KEY;"
131
133
  end
132
134
 
133
135
  # analyzes the table for efficent query contstruction on tables larger than ~1000 tuples
@@ -1,3 +1,3 @@
1
1
  module Theman
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/spec/agency_spec.rb CHANGED
@@ -168,7 +168,7 @@ describe Theman::Agency, "add primary key" do
168
168
  end
169
169
 
170
170
  it "should have serial primary key" do
171
- @model.first.agents_pkey.should == 1
171
+ @model.first.id.should == 1
172
172
  end
173
173
  end
174
174
 
data/spec/columns_spec.rb CHANGED
@@ -73,3 +73,15 @@ describe Theman::Agency::Columns, "data types" do
73
73
  @columns.to_sql.should == "\"col_one\" boolean"
74
74
  end
75
75
  end
76
+
77
+ describe Theman::Agency::Columns, "data types" do
78
+ before do
79
+ @columns = Theman::Agency::Columns.new(ActiveRecord::Base.connection.raw_connection)
80
+ end
81
+
82
+ it "should have include? method" do
83
+ @columns.boolean :col_one
84
+ @columns.include?(:col_one).should be_true
85
+ @columns.include?(:col_two).should be_false
86
+ end
87
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rufus Post
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-15 00:00:00 +11:00
17
+ date: 2011-02-18 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency