adacosta-labilerecord 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -2
- data/README.rdoc +7 -3
- data/lib/labilerecord.rb +18 -1
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
== 0.0.
|
1
|
+
== 0.0.8 2009-05-07
|
2
2
|
|
3
3
|
* 1 major enhancement:
|
4
4
|
* Initial release
|
@@ -11,4 +11,9 @@
|
|
11
11
|
* 5 :
|
12
12
|
* Fixed bug introduced in 0.0.4 always referencing row[0]
|
13
13
|
* 6 :
|
14
|
-
* Fix incorrect field.type_id
|
14
|
+
* Fix incorrect field.type_id
|
15
|
+
* 7 :
|
16
|
+
* Increment revision; minor bug fix
|
17
|
+
* 8 :
|
18
|
+
* Added Query.to_insert_sql to transform dataset into
|
19
|
+
an insert statement ... handy for data copies.
|
data/README.rdoc
CHANGED
@@ -12,15 +12,19 @@
|
|
12
12
|
* Access field types
|
13
13
|
* Access types which ActiveRecord won't (e.g. _int4)
|
14
14
|
* Easy to use on tables, views, and functions
|
15
|
-
* Fast - no ruby type conversion on values from connection adapter
|
15
|
+
* Fast - no ruby type conversion on values from connection adapter
|
16
|
+
* Simple sql generation for data copy using Query.to_insert_sql
|
16
17
|
|
17
18
|
== SYNOPSIS:
|
18
19
|
|
19
20
|
require 'rubygems'
|
20
21
|
require 'labilerecord'
|
21
22
|
|
22
|
-
LabileRecord::Base.connection = {:dbname => 'postgres',
|
23
|
-
|
23
|
+
LabileRecord::Base.connection = { :dbname => 'postgres',
|
24
|
+
:user => user,
|
25
|
+
:pass => pass,
|
26
|
+
:host => host,
|
27
|
+
:port => port}
|
24
28
|
|
25
29
|
databases = LabileRecord::Query.new("SELECT * FROM pg_database")
|
26
30
|
# execute the query
|
data/lib/labilerecord.rb
CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module LabileRecord
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.8'
|
6
6
|
require 'pg'
|
7
7
|
|
8
8
|
class Base
|
@@ -61,6 +61,23 @@ module LabileRecord
|
|
61
61
|
def connection
|
62
62
|
LabileRecord::Base.connection
|
63
63
|
end
|
64
|
+
|
65
|
+
def to_insert_sql(table_name=nil)
|
66
|
+
# return: [INSERT INTO table_name] (column_list) gVALUES(value_list);
|
67
|
+
sql = ""
|
68
|
+
each do |row|
|
69
|
+
non_nil_column_names = []
|
70
|
+
non_nil_values = []
|
71
|
+
row.each_with_index do |column, i|
|
72
|
+
non_nil_column_names << fields[i].name if !column.nil?
|
73
|
+
non_nil_values << column if !column.nil?
|
74
|
+
end
|
75
|
+
sql += %Q[
|
76
|
+
#{"INSERT INTO " + table_name.to_s if table_name} (#{ non_nil_column_names.map {|c| '"' + c + '"'} * "," }) VALUES (#{ non_nil_values.map {|c| "'" + c + "'"} * "," });
|
77
|
+
].strip + "\n"
|
78
|
+
end
|
79
|
+
sql
|
80
|
+
end
|
64
81
|
end
|
65
82
|
|
66
83
|
class Field
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adacosta-labilerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Da Costa
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-07 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|