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 +11 -13
- data/lib/theman/agency/columns.rb +4 -0
- data/lib/theman/agency.rb +4 -2
- data/lib/theman/version.rb +1 -1
- data/spec/agency_spec.rb +1 -1
- data/spec/columns_spec.rb +12 -0
- metadata +3 -3
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
|
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
|
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
|
-
|
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
|
68
|
-
|
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
|
-
|
75
|
+
agent = Theman::Agency.new conn, 'sample.csv', :on_commit => :drop
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
agent.transaction do
|
78
|
+
agent.create!
|
79
|
+
# do stuff
|
80
|
+
end
|
83
81
|
|
84
82
|
== No headers
|
85
83
|
|
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
|
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
|
-
|
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
|
data/lib/theman/version.rb
CHANGED
data/spec/agency_spec.rb
CHANGED
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
|
-
-
|
9
|
-
version: 0.1.
|
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-
|
17
|
+
date: 2011-02-18 00:00:00 +11:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|