momomoto 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/momomoto/base.rb +57 -20
- data/lib/momomoto/database.rb +3 -8
- data/lib/momomoto/datatype/array.rb +78 -0
- data/lib/momomoto/datatype/base.rb +8 -3
- data/lib/momomoto/datatype.rb +1 -0
- data/lib/momomoto/procedure.rb +11 -36
- data/lib/momomoto/row.rb +0 -3
- data/lib/momomoto/table.rb +19 -56
- data/test/test.sql +2 -0
- data/test/test_array.rb +18 -0
- data/test/test_base.rb +4 -3
- data/test/test_procedure.rb +11 -9
- data/test/test_table.rb +4 -3
- metadata +6 -4
data/Rakefile
CHANGED
@@ -35,12 +35,12 @@ end
|
|
35
35
|
|
36
36
|
desc "create documentation for ri"
|
37
37
|
task :doc do
|
38
|
-
sh "rdoc -r lib"
|
38
|
+
sh "rdoc -r lib -A momomoto_attribute=rw,momomoto_attribute_reader=r"
|
39
39
|
end
|
40
40
|
|
41
41
|
desc "create html documentation"
|
42
42
|
task :html do
|
43
|
-
sh "rdoc --template jamis --main Momomoto::Table --inline-source --force-update --webcvs 'http://trac.c3d2.de/momomoto/browser/trunk/%s' lib"
|
43
|
+
sh "rdoc -A momomoto_attribute=rw,momomoto_attribute_reader=r --template jamis --main Momomoto::Table --inline-source --force-update --webcvs 'http://trac.c3d2.de/momomoto/browser/trunk/%s' lib"
|
44
44
|
end
|
45
45
|
|
46
46
|
desc "update html documentation on momomoto.rubyforge.org"
|
data/lib/momomoto/base.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
## Momomoto is a database abstraction layer for PostgreSQL
|
3
3
|
module Momomoto
|
4
4
|
|
5
|
+
@debug = false
|
6
|
+
|
5
7
|
class << self
|
6
8
|
|
7
9
|
# Getter and setter for debugging.
|
@@ -76,9 +78,60 @@ module Momomoto
|
|
76
78
|
|
77
79
|
class << self
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
81
|
+
def momomoto_attribute_reader( name )
|
82
|
+
singleton = self.instance_eval{class << self; self; end}
|
83
|
+
varname = "@#{name}"
|
84
|
+
# define getter method
|
85
|
+
singleton.send(:define_method, name) do | *values |
|
86
|
+
if not instance_variable_defined?( varname )
|
87
|
+
initialize
|
88
|
+
end
|
89
|
+
instance_variable_get( varname )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def momomoto_attribute( name )
|
94
|
+
singleton = self.instance_eval{class << self; self; end}
|
95
|
+
varname = "@#{name}"
|
96
|
+
settername = "#{name}="
|
97
|
+
# define getter method
|
98
|
+
singleton.send(:define_method, name) do | *values |
|
99
|
+
if values[0]
|
100
|
+
send( settername, values[0] )
|
101
|
+
else
|
102
|
+
if not instance_variable_defined?( varname )
|
103
|
+
initialize
|
104
|
+
end
|
105
|
+
instance_variable_get( varname )
|
106
|
+
end
|
107
|
+
end
|
108
|
+
# define setter method
|
109
|
+
singleton.send(:define_method, settername) do | value |
|
110
|
+
instance_variable_set( varname, value )
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def initialize
|
115
|
+
return if initialized
|
116
|
+
|
117
|
+
@schema_name ||= construct_schema_name( self.name )
|
118
|
+
@logical_operator ||= 'AND'
|
119
|
+
|
120
|
+
self.initialized = true
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
# The schema name of the table this class operates on. Invokes
|
126
|
+
# #schema_name= if +schema_name+ is given as parameter. Returns
|
127
|
+
# +@schema_name+
|
128
|
+
momomoto_attribute :schema_name
|
129
|
+
|
130
|
+
# The logical operator is used in #compile_where and defines
|
131
|
+
# the top level logical relation for where clauses.
|
132
|
+
momomoto_attribute_reader :logical_operator
|
133
|
+
|
134
|
+
class << self
|
82
135
|
|
83
136
|
# Set the default logical operator for constraints. AND and OR are
|
84
137
|
# supported.
|
@@ -91,23 +144,7 @@ module Momomoto
|
|
91
144
|
end
|
92
145
|
end
|
93
146
|
|
94
|
-
|
95
|
-
def schema_name=( schema_name )
|
96
|
-
@schema_name = schema_name
|
97
|
-
end
|
98
|
-
|
99
|
-
# Get the schema name of the table this class operates on. Invokes
|
100
|
-
# #schema_name= if +schema_name+ is given as parameter. Returns
|
101
|
-
# +@schema_name+
|
102
|
-
def schema_name( schema_name = nil )
|
103
|
-
return self.schema_name=( schema_name ) if schema_name
|
104
|
-
if not instance_variable_defined?( :@schema_name )
|
105
|
-
self.schema_name=( construct_schema_name( self.name ) )
|
106
|
-
end
|
107
|
-
@schema_name
|
108
|
-
end
|
109
|
-
|
110
|
-
protected
|
147
|
+
protected
|
111
148
|
|
112
149
|
# Getter and setter used for marking tables as initialized.
|
113
150
|
attr_accessor :initialized
|
data/lib/momomoto/database.rb
CHANGED
@@ -1,12 +1,5 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
gem 'ruby-postgres', '>= 0.7.1.2006.04.06'
|
5
|
-
require 'postgres'
|
6
|
-
rescue LoadError
|
7
|
-
require 'postgres'
|
8
|
-
end
|
9
|
-
|
2
|
+
require 'postgres'
|
10
3
|
require 'singleton'
|
11
4
|
|
12
5
|
require 'momomoto/information_schema/columns'
|
@@ -140,6 +133,8 @@ module Momomoto
|
|
140
133
|
end
|
141
134
|
end
|
142
135
|
p
|
136
|
+
rescue => e
|
137
|
+
raise Error, "Fetching procedure parameters for #{procedure_name} failed: #{e}"
|
143
138
|
end
|
144
139
|
|
145
140
|
# fetches the result set columns of a stored procedure
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Momomoto
|
2
|
+
module Datatype
|
3
|
+
|
4
|
+
# Represents the data type Array.
|
5
|
+
class Array < Base
|
6
|
+
|
7
|
+
# Escapes +input+ to be saved in database.
|
8
|
+
# Returns 'NULL' if +input+ is nil or empty. Otherwise escapes
|
9
|
+
# using Database#escape_string
|
10
|
+
def escape( input )
|
11
|
+
if input.nil?
|
12
|
+
"NULL"
|
13
|
+
elsif input.instance_of?( ::Array )
|
14
|
+
"ARRAY[" + input.map{|m| "'" + Database.escape_string(m) + "'"}.join(',') + "]"
|
15
|
+
else
|
16
|
+
"'" + Database.escape_string(m) + "'"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Values are filtered by this function when being set. See the
|
21
|
+
# method in the appropriate derived data type class for allowed
|
22
|
+
# values.
|
23
|
+
def filter_get( value ) # :nodoc:
|
24
|
+
case value
|
25
|
+
when ::Array then value
|
26
|
+
when nil,"" then nil
|
27
|
+
when "{}" then []
|
28
|
+
when /^\{[^"]+(,[^"]+)*\}$/
|
29
|
+
m = v.match(/^\{()\}$/)
|
30
|
+
m[1].split(',')
|
31
|
+
when /^\{"[^"]+"(,"[^"]+")*\}$/
|
32
|
+
m = v.match(/^\{()\}$/)
|
33
|
+
m[1].split(',').map{|e| e.gsub(/^"(.*)"$/, "\\1")}
|
34
|
+
else
|
35
|
+
raise Error, "Error parsing array value"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
# Values are filtered by this function when being set. See the
|
41
|
+
# method in the appropriate derived data type class for allowed
|
42
|
+
# values.
|
43
|
+
def filter_set( value ) # :nodoc:
|
44
|
+
value = [value] unless value.instance_of?( ::Array )
|
45
|
+
value
|
46
|
+
end
|
47
|
+
|
48
|
+
# Get the default value for this Datatype.
|
49
|
+
def default_operator
|
50
|
+
"@>"
|
51
|
+
end
|
52
|
+
|
53
|
+
# This method is used when compiling the where clause. No need
|
54
|
+
# for direct use.
|
55
|
+
def compile_rule( field_name, value ) # :nodoc:
|
56
|
+
case value
|
57
|
+
when ::Array then
|
58
|
+
raise Error, "empty or nil array conditions are not allowed for #{field_name}" if value.empty? or value.member?( nil )
|
59
|
+
field_name.to_s + ' @> ' + escape(filter_set(value))
|
60
|
+
else
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Additional operators for instances of Array.
|
66
|
+
# See Base#operator_sign
|
67
|
+
def self.operator_sign( op )
|
68
|
+
case op
|
69
|
+
when :contains then '@>'
|
70
|
+
when :contained then '<@'
|
71
|
+
else
|
72
|
+
super( op )
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -20,6 +20,11 @@ module Momomoto
|
|
20
20
|
@default
|
21
21
|
end
|
22
22
|
|
23
|
+
# Get the default value for this Datatype.
|
24
|
+
def default_operator
|
25
|
+
"="
|
26
|
+
end
|
27
|
+
|
23
28
|
# Returns true if this column can be NULL otherwise false.
|
24
29
|
def not_null?
|
25
30
|
@not_null
|
@@ -64,7 +69,7 @@ module Momomoto
|
|
64
69
|
field_name.to_s + ' IS NULL'
|
65
70
|
when :NOT_NULL then
|
66
71
|
field_name.to_s + ' IS NOT NULL'
|
67
|
-
when Array then
|
72
|
+
when ::Array then
|
68
73
|
raise Error, "empty array conditions are not allowed for #{field_name}" if value.empty?
|
69
74
|
raise Error, "nil values not allowed in compile_rule for #{field_name}" if value.member?( nil )
|
70
75
|
field_name.to_s + ' IN (' + value.map{ | v | escape(filter_set(v)) }.join(',') + ')'
|
@@ -73,7 +78,7 @@ module Momomoto
|
|
73
78
|
rules = []
|
74
79
|
value.each do | op, v |
|
75
80
|
raise Error, "nil values not allowed in compile_rule for #{field_name}" if v == nil
|
76
|
-
v = [v] if not v.kind_of?( Array )
|
81
|
+
v = [v] if not v.kind_of?( ::Array )
|
77
82
|
if op == :eq # use IN if comparing for equality
|
78
83
|
rules << compile_rule( field_name, v )
|
79
84
|
else
|
@@ -84,7 +89,7 @@ module Momomoto
|
|
84
89
|
end
|
85
90
|
rules.join( " AND " )
|
86
91
|
else
|
87
|
-
field_name.to_s +
|
92
|
+
field_name.to_s + " #{default_operator} " + escape(filter_set(value))
|
88
93
|
end
|
89
94
|
end
|
90
95
|
|
data/lib/momomoto/datatype.rb
CHANGED
data/lib/momomoto/procedure.rb
CHANGED
@@ -5,22 +5,26 @@ module Momomoto
|
|
5
5
|
# It must not be used directly but you should inherit from this class.
|
6
6
|
class Procedure < Base
|
7
7
|
|
8
|
+
# the procedure name of this class
|
9
|
+
momomoto_attribute :procedure_name
|
10
|
+
|
11
|
+
# the columns of the result set this procedure returns
|
12
|
+
# a hash with the field names as keys and the datatype as values
|
13
|
+
momomoto_attribute :columns
|
14
|
+
|
8
15
|
class << self
|
9
16
|
|
10
|
-
def
|
17
|
+
def initialize # :nodoc:
|
18
|
+
return if initialized
|
19
|
+
super
|
11
20
|
|
12
21
|
@procedure_name ||= construct_procedure_name( self.name )
|
13
|
-
@schema_name ||= construct_schema_name( self.name )
|
14
22
|
@parameters ||= database.fetch_procedure_parameters( procedure_name )
|
15
23
|
@columns ||= database.fetch_procedure_columns( procedure_name )
|
16
|
-
@logical_operator ||= "AND"
|
17
24
|
|
18
25
|
const_set( :Row, Class.new( Momomoto::Row ) ) if not const_defined?( :Row )
|
19
26
|
initialize_row( const_get( :Row ), self )
|
20
27
|
|
21
|
-
# mark class as initialized
|
22
|
-
self.initialized = true
|
23
|
-
|
24
28
|
end
|
25
29
|
|
26
30
|
# guesses the procedure name of the procedure this class works on
|
@@ -28,20 +32,6 @@ module Momomoto
|
|
28
32
|
classname.split('::').last.downcase.gsub(/[^a-z_0-9]/, '')
|
29
33
|
end
|
30
34
|
|
31
|
-
# sets the procedure name
|
32
|
-
def procedure_name=( procedure_name )
|
33
|
-
@procedure_name = procedure_name
|
34
|
-
end
|
35
|
-
|
36
|
-
# gets the procedure name
|
37
|
-
def procedure_name( procedure_name = nil )
|
38
|
-
return self.procedure_name=( procedure_name ) if procedure_name
|
39
|
-
if not instance_variable_defined?( :@procedure_name )
|
40
|
-
self.procedure_name = construct_procedure_name( self.name )
|
41
|
-
end
|
42
|
-
@procedure_name
|
43
|
-
end
|
44
|
-
|
45
35
|
# gets the full name of the procedure including schema if set
|
46
36
|
def full_name # :nodoc:
|
47
37
|
"#{ schema_name ? schema_name + '.' : ''}#{procedure_name}"
|
@@ -58,24 +48,10 @@ module Momomoto
|
|
58
48
|
# returns an array of hashes with the field names as keys and the datatype as values
|
59
49
|
def parameters( *p )
|
60
50
|
return self.send( :parameters=, *p ) if not p.empty?
|
61
|
-
|
51
|
+
initialize if not instance_variable_defined?( :@parameters )
|
62
52
|
@parameters
|
63
53
|
end
|
64
54
|
|
65
|
-
# sets the columns of the result set this procedure returns
|
66
|
-
# expects a hash with the field names as keys and the datatype as values
|
67
|
-
def columns=( columns )
|
68
|
-
@columns = columns
|
69
|
-
end
|
70
|
-
|
71
|
-
# gets the columns of the result set this procedure returns
|
72
|
-
# returns a hash with the field names as keys and the datatype as values
|
73
|
-
def columns( c = nil )
|
74
|
-
return self.columns=( c ) if c
|
75
|
-
initialize_procedure if not instance_variable_defined?( :@columns )
|
76
|
-
@columns
|
77
|
-
end
|
78
|
-
|
79
55
|
def compile_parameter( params ) # :nodoc:
|
80
56
|
args = []
|
81
57
|
parameters.each do | parameter |
|
@@ -89,7 +65,6 @@ module Momomoto
|
|
89
65
|
|
90
66
|
# executes the stored procedure
|
91
67
|
def call( params = {}, conditions = {}, options = {} )
|
92
|
-
initialize_procedure unless initialized
|
93
68
|
sql = "SELECT #{columns.keys.join(',')} FROM "
|
94
69
|
sql += "#{full_name}(#{compile_parameter(params)})"
|
95
70
|
sql += compile_where( conditions )
|
data/lib/momomoto/row.rb
CHANGED
data/lib/momomoto/table.rb
CHANGED
@@ -5,63 +5,25 @@ module Momomoto
|
|
5
5
|
# It must not be used directly but you should inherit from this class.
|
6
6
|
class Table < Base
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
# set the default order for selects
|
11
|
-
def default_order=( order )
|
12
|
-
@default_order = order
|
13
|
-
end
|
14
|
-
|
15
|
-
# get the default order for selects
|
16
|
-
def default_order( order = nil )
|
17
|
-
return self.default_order=( order ) if order
|
18
|
-
@default_order
|
19
|
-
end
|
8
|
+
# controls the default order for selects
|
9
|
+
momomoto_attribute :default_order
|
20
10
|
|
21
|
-
|
22
|
-
|
23
|
-
@columns = columns
|
24
|
-
end
|
11
|
+
# the columns of this table
|
12
|
+
momomoto_attribute :columns
|
25
13
|
|
26
|
-
|
27
|
-
|
28
|
-
return self.columns=( columns ) if columns
|
29
|
-
if not instance_variable_defined?( :@columns )
|
30
|
-
initialize_table
|
31
|
-
end
|
32
|
-
@columns
|
33
|
-
end
|
14
|
+
# the table name of this table
|
15
|
+
momomoto_attribute :table_name
|
34
16
|
|
35
|
-
|
36
|
-
|
37
|
-
@table_name = table_name
|
38
|
-
end
|
17
|
+
# array containing the primary key fields of the table
|
18
|
+
momomoto_attribute :primary_keys
|
39
19
|
|
40
|
-
|
41
|
-
def table_name( table_name = nil )
|
42
|
-
return self.table_name=( table_name ) if table_name
|
43
|
-
@table_name
|
44
|
-
end
|
20
|
+
class << self
|
45
21
|
|
46
22
|
# get the full name of table including, if set, schema
|
47
23
|
def full_name
|
48
24
|
"#{ schema_name ? schema_name + '.' : ''}#{table_name}"
|
49
25
|
end
|
50
26
|
|
51
|
-
# set the primary key fields of the table
|
52
|
-
def primary_keys=( keys )
|
53
|
-
@primary_keys = keys
|
54
|
-
end
|
55
|
-
|
56
|
-
# get the primary key fields of the table
|
57
|
-
def primary_keys( keys = nil )
|
58
|
-
return self.primary_keys=( keys ) if keys
|
59
|
-
if not instance_variable_defined?( :@primary_keys )
|
60
|
-
initialize_table
|
61
|
-
end
|
62
|
-
@primary_keys
|
63
|
-
end
|
64
|
-
|
65
27
|
# Searches for records and returns an Array containing the records.
|
66
28
|
# There are a bunch of different use cases as this method is the primary way
|
67
29
|
# to access all rows in the database.
|
@@ -121,7 +83,7 @@ module Momomoto
|
|
121
83
|
# posts.first.title = "new title"
|
122
84
|
# posts.first.write
|
123
85
|
def select( conditions = {}, options = {} )
|
124
|
-
|
86
|
+
initialize unless initialized
|
125
87
|
row_class = build_row_class( options )
|
126
88
|
sql = compile_select( conditions, options )
|
127
89
|
data = []
|
@@ -135,7 +97,7 @@ module Momomoto
|
|
135
97
|
#
|
136
98
|
# Searches for records and returns an array containing the records
|
137
99
|
def select_outer_join( conditions = {}, options = {} )
|
138
|
-
|
100
|
+
initialize unless initialized
|
139
101
|
join_table = options[:join]
|
140
102
|
fields = columns.keys.map{|field| full_name+'."'+field.to_s+'"'}
|
141
103
|
fields += join_table.columns.keys.map{|field| join_table.full_name+'."'+field.to_s+'"'}
|
@@ -166,7 +128,7 @@ module Momomoto
|
|
166
128
|
|
167
129
|
# constructor for a record in this table accepts a hash with presets for the fields of the record
|
168
130
|
def new( fields = {} )
|
169
|
-
|
131
|
+
initialize unless initialized
|
170
132
|
new_row = const_get(:Row).new( [] )
|
171
133
|
new_row.new_record = true
|
172
134
|
# set default values
|
@@ -320,10 +282,11 @@ module Momomoto
|
|
320
282
|
end
|
321
283
|
|
322
284
|
# initializes a table class
|
323
|
-
def
|
285
|
+
def initialize
|
286
|
+
return if initialized
|
287
|
+
super
|
324
288
|
|
325
289
|
@table_name ||= construct_table_name( self.name )
|
326
|
-
@schema_name ||= construct_schema_name( self.name )
|
327
290
|
|
328
291
|
@columns ||= database.fetch_table_columns( table_name(), schema_name() )
|
329
292
|
raise CriticalError, "No fields in table #{table_name}" if columns.keys.empty?
|
@@ -332,14 +295,10 @@ module Momomoto
|
|
332
295
|
@column_order = @columns.keys
|
333
296
|
@default_order ||= nil
|
334
297
|
|
335
|
-
@logical_operator ||= "AND"
|
336
|
-
|
337
298
|
const_set( :Row, Class.new( Momomoto::Row ) ) if not const_defined?( :Row )
|
338
299
|
initialize_row( const_get( :Row ), self )
|
339
300
|
@row_cache = {}
|
340
301
|
|
341
|
-
self.initialized = true
|
342
|
-
|
343
302
|
end
|
344
303
|
|
345
304
|
# Builds the row class for this table when executing #select.
|
@@ -386,6 +345,10 @@ module Momomoto
|
|
386
345
|
sql += compile_order( options[:order] ) if options[:order] || default_order
|
387
346
|
sql += compile_limit( options[:limit] ) if options[:limit]
|
388
347
|
sql += compile_offset( options[:offset] ) if options[:offset]
|
348
|
+
if options[:distinct]
|
349
|
+
raise CriticalError, "condition key '#{options[:distinct]}' not a column in table '#{table_name}'" unless columns.keys.member?( options[:distinct])
|
350
|
+
sql = "SELECT DISTINCT ON(\"#{options[:distinct]}\") " + cols.keys.map{ | field | '"' + field.to_s + '"' }.join( "," ) + " FROM (#{sql}) AS t1"
|
351
|
+
end
|
389
352
|
sql
|
390
353
|
end
|
391
354
|
|
data/test/test.sql
CHANGED
@@ -64,5 +64,7 @@ CREATE TABLE test_time_with_time_zone( id SERIAL, data TIME WITH TIME ZONE, PRIM
|
|
64
64
|
CREATE TABLE test_time_without_time_zone( id SERIAL, data TIME WITHOUT TIME ZONE, PRIMARY KEY(id));
|
65
65
|
CREATE TABLE test_timestamp_with_time_zone( id SERIAL, data TIMESTAMP WITH TIME ZONE, PRIMARY KEY(id));
|
66
66
|
CREATE TABLE test_timestamp_without_time_zone( id SERIAL, data TIMESTAMP WITHOUT TIME ZONE, PRIMARY KEY(id));
|
67
|
+
CREATE TABLE test_int_array( id SERIAL, data int[], PRIMARY KEY(id) );
|
68
|
+
CREATE TABLE test_text_array( id SERIAL, data text[], PRIMARY KEY(id) );
|
67
69
|
|
68
70
|
|
data/test/test_array.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
class TestArray < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_samples
|
5
|
+
c = Class.new( Momomoto::Table )
|
6
|
+
c.table_name = 'test_int_array'
|
7
|
+
[["1","2","3"],nil].each do | value |
|
8
|
+
r = c.new( :data => value )
|
9
|
+
assert_equal( value, r.data )
|
10
|
+
r.write
|
11
|
+
r2 = c.select(:id=>r.id).first
|
12
|
+
assert_equal( value, r2.data )
|
13
|
+
r.delete
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
data/test/test_base.rb
CHANGED
@@ -4,10 +4,11 @@ class TestBase < Test::Unit::TestCase
|
|
4
4
|
def test_logical_operator
|
5
5
|
t1 = Class.new( Momomoto::Table )
|
6
6
|
t1.table_name = 'person'
|
7
|
-
t1.
|
7
|
+
assert_equal( t1.logical_operator, 'AND' )
|
8
|
+
t1.send( :initialize )
|
8
9
|
t2 = Class.new( Momomoto::Table )
|
9
10
|
t2.table_name = 'person'
|
10
|
-
t2.send( :
|
11
|
+
t2.send( :initialize )
|
11
12
|
assert_equal( "AND", t1.logical_operator )
|
12
13
|
assert_equal( "AND", t2.logical_operator )
|
13
14
|
t1.logical_operator = "OR"
|
@@ -25,7 +26,7 @@ class TestBase < Test::Unit::TestCase
|
|
25
26
|
def test_compile_where
|
26
27
|
t = Class.new( Momomoto::Table )
|
27
28
|
t.table_name = 'person'
|
28
|
-
t.send( :
|
29
|
+
t.send( :initialize )
|
29
30
|
assert_equal( " WHERE person_id = '1'" , t.instance_eval do compile_where( :person_id => '1' ) end )
|
30
31
|
assert_equal( " WHERE person_id IN ('1')" , t.instance_eval do compile_where( :person_id => ['1'] ) end )
|
31
32
|
assert_equal( " WHERE person_id IN ('1','2')" , t.instance_eval do compile_where( :person_id => ['1',2] ) end )
|
data/test/test_procedure.rb
CHANGED
@@ -17,15 +17,17 @@ class TestProcedure < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_procedure_name
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
assert_equal( '
|
26
|
-
|
27
|
-
assert_equal( '
|
28
|
-
|
20
|
+
p1 = Class.new( Momomoto::Procedure )
|
21
|
+
p1.procedure_name = 'test_parameter_sql'
|
22
|
+
assert_equal( 'test_parameter_sql', p1.procedure_name )
|
23
|
+
p2 = Class.new( Momomoto::Procedure )
|
24
|
+
p2.procedure_name = 'test_parameter_sql_strict'
|
25
|
+
assert_equal( 'test_parameter_sql_strict', p2.procedure_name )
|
26
|
+
p2.procedure_name( 'proc3' )
|
27
|
+
assert_equal( 'proc3', p2.procedure_name )
|
28
|
+
p2.procedure_name = 'proc4'
|
29
|
+
assert_equal( 'proc4', p2.procedure_name )
|
30
|
+
assert_equal( 'test_parameter_sql', p1.procedure_name )
|
29
31
|
end
|
30
32
|
|
31
33
|
def test_columns_fetching
|
data/test/test_table.rb
CHANGED
@@ -64,6 +64,7 @@ class TestTable < Test::Unit::TestCase
|
|
64
64
|
|
65
65
|
def test_schema_name_getter
|
66
66
|
self.class.const_set( :S, Class.new( Momomoto::Table ) )
|
67
|
+
S.table_name = "test_text"
|
67
68
|
assert_equal( 'public', S.schema_name )
|
68
69
|
S.schema_name = "chunky"
|
69
70
|
assert_equal( "chunky", S.schema_name )
|
@@ -99,10 +100,10 @@ class TestTable < Test::Unit::TestCase
|
|
99
100
|
|
100
101
|
def test_full_name
|
101
102
|
a = Class.new( Momomoto::Table )
|
102
|
-
a.table_name( '
|
103
|
-
assert_equal( 'public.
|
103
|
+
a.table_name( 'test_text' )
|
104
|
+
assert_equal( 'public.test_text', a.full_name )
|
104
105
|
a.schema_name( 'def' )
|
105
|
-
assert_equal( 'def.
|
106
|
+
assert_equal( 'def.test_text', a.full_name )
|
106
107
|
end
|
107
108
|
|
108
109
|
def test_custom_setter
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: momomoto
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date:
|
6
|
+
version: 0.1.15
|
7
|
+
date: 2008-01-13 00:00:00 +01:00
|
8
8
|
summary: Momomoto is an object relational mapper for PostgreSQL.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/momomoto/information_schema/key_column_usage.rb
|
48
48
|
- lib/momomoto/datatype/boolean.rb
|
49
49
|
- lib/momomoto/datatype/date.rb
|
50
|
+
- lib/momomoto/datatype/array.rb
|
50
51
|
- lib/momomoto/datatype/smallint.rb
|
51
52
|
- lib/momomoto/datatype/real.rb
|
52
53
|
- lib/momomoto/datatype/text.rb
|
@@ -67,6 +68,7 @@ files:
|
|
67
68
|
- sql/types.sql
|
68
69
|
- sql/install.sql
|
69
70
|
- test/test_procedure.rb
|
71
|
+
- test/test_array.rb
|
70
72
|
- test/test_boolean.rb
|
71
73
|
- test/test_real.rb
|
72
74
|
- test/test_smallint.rb
|
@@ -109,11 +111,11 @@ requirements:
|
|
109
111
|
- PostgreSQL 8.1.x or greater
|
110
112
|
dependencies:
|
111
113
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
114
|
+
name: postgres
|
113
115
|
version_requirement:
|
114
116
|
version_requirements: !ruby/object:Gem::Version::Requirement
|
115
117
|
requirements:
|
116
118
|
- - ">="
|
117
119
|
- !ruby/object:Gem::Version
|
118
|
-
version: 0.7.
|
120
|
+
version: 0.7.9.2007.12.12
|
119
121
|
version:
|