dm-mapping 0.6.2 → 0.7.0

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/CHANGES CHANGED
@@ -1,5 +1,12 @@
1
1
  = dm-mapper changes history
2
2
 
3
+ === dm-mapping 0.7.0, 2008-09-01
4
+ * feature added
5
+ - added postgres support.
6
+ * bug fixed
7
+ - fixed key mapping in mysql adapter. PRI and MUL are all keys.
8
+ - use DM::Text.size as default text size in sqlite3.
9
+
3
10
  === dm-mapping 0.6.2, 2008-08-30
4
11
  * mapping more data types for mysql.
5
12
  * don't map TINYINT to TrueClass with mysql, skip it in type_map.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = dm-mapping 0.6.2
1
+ = dm-mapping 0.7.0
2
2
  by Lin Jen-Shin (a.k.a. godfat-真常[http://godfat.org])
3
3
  godfat (XD) godfat.org
4
4
 
@@ -95,7 +95,7 @@ by Lin Jen-Shin (a.k.a. godfat-真常[http://godfat.org])
95
95
  == REQUIREMENTS:
96
96
 
97
97
  * dm-core 0.9.3 or later
98
- * at least one do_* adapter (currently supports sqlite3 and mysql)
98
+ * at least one do_* adapter
99
99
 
100
100
  == INSTALL:
101
101
 
data/TODO CHANGED
@@ -1,5 +1,5 @@
1
1
  = dm-mapping todo list
2
2
 
3
3
  * better doc...
4
- * 0.7 postgresql adapter
4
+ * 0.7.1 for more data types for postgresql adapter
5
5
  * 0.8 automatic determine model relationship
@@ -32,7 +32,7 @@ module DataMapper
32
32
 
33
33
  def dmm_attributes field, attrs = {}
34
34
  attrs[:serial] = true if field.extra == 'auto_increment'
35
- attrs[:key] = true if field.column_key == 'PRI'
35
+ attrs[:key] = true if field.column_key != ''
36
36
  attrs[:nullable] = field.is_nullable == 'YES'
37
37
  attrs[:default] = field.column_default if field.column_default
38
38
  attrs[:size] = field.character_maximum_length if
@@ -0,0 +1,73 @@
1
+
2
+ require 'dm-mapping/adapters/abstract_adapter'
3
+
4
+ module DataMapper
5
+ module Adapters
6
+ class PostgresAdapter < DataObjectsAdapter #:nodoc: all
7
+ module Migration
8
+ def storages
9
+ sql = <<-SQL.compress_lines
10
+ SELECT table_name FROM "information_schema"."tables"
11
+ WHERE table_schema = current_schema()
12
+ SQL
13
+
14
+ query(sql)
15
+ end
16
+
17
+ private
18
+ def dmm_query_storage storage
19
+ sql = <<-SQL.compress_lines
20
+ SELECT column_name FROM "information_schema"."key_column_usage"
21
+ WHERE table_schema = current_schema() AND table_name = ?
22
+ SQL
23
+
24
+ keys = query(sql, storage).to_set
25
+
26
+ sql = <<-SQL.compress_lines
27
+ SELECT column_name, column_default, is_nullable,
28
+ character_maximum_length, udt_name
29
+ FROM "information_schema"."columns"
30
+ WHERE table_schema = current_schema() AND table_name = ?
31
+ SQL
32
+
33
+ query(sql, storage).map{ |struct|
34
+ struct.instance_eval <<-END_EVAL
35
+ def key?
36
+ #{keys.member?(struct.column_name)}
37
+ end
38
+ END_EVAL
39
+ struct
40
+ }
41
+ end
42
+
43
+ def dmm_field_name field
44
+ field.column_name
45
+ end
46
+
47
+ def dmm_primitive field
48
+ field.udt_name
49
+ end
50
+
51
+ def dmm_attributes field, attrs = {}
52
+ # strip data type
53
+ field.column_default.gsub!(/(.*?)::[\w\s]*/, '\1') if field.column_default
54
+
55
+ attrs[:serial] = true if field.column_default =~ /nextval\('\w+_seq'\)/
56
+ attrs[:key] = true if field.key?
57
+ attrs[:nullable] = field.is_nullable == 'YES'
58
+ # strip string quotation
59
+ attrs[:default] = field.column_default.gsub(/^'(.*?)'$/, '\1') if
60
+ field.column_default && !attrs[:serial]
61
+
62
+ if field.character_maximum_length
63
+ attrs[:size] = field.character_maximum_length
64
+ elsif field.udt_name.upcase == 'TEXT'
65
+ attrs[:size] = DM::Text.size
66
+ end
67
+
68
+ attrs
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -36,7 +36,7 @@ module DataMapper
36
36
  attrs[:default] = field.dflt_value[1..-2] if field.dflt_value
37
37
 
38
38
  if field.type.upcase == 'TEXT'
39
- attrs[:size] = 65535
39
+ attrs[:size] = DM::Text.size
40
40
  else
41
41
  ergo = field.type.match(/\((\d+)\)/)
42
42
  size = ergo && ergo[1].to_i
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Mapping
3
- VERSION = '0.6.2' unless defined?(DataMapper::Mapping::VERSION)
3
+ VERSION = '0.7.0' unless defined?(DataMapper::Mapping::VERSION)
4
4
  end
5
5
  end
@@ -9,18 +9,31 @@ require 'test/abstract'
9
9
  end
10
10
  }
11
11
 
12
+ # cost 1 second to run
12
13
  class Sqlite3Test < Test::Unit::TestCase
13
14
  include Abstract
14
15
 
15
16
  def setup_data_mapper
16
17
  DataMapper.setup(:default, 'sqlite3:tmp.sqlite3')
17
18
  end
18
- end
19
+ end if defined?(DataObjects::Sqlite3)
19
20
 
21
+
22
+ # cost 2 seconds to run
20
23
  class MysqlTest < Test::Unit::TestCase
21
24
  include Abstract
22
25
 
23
26
  def setup_data_mapper
24
27
  DataMapper.setup(:default, 'mysql://dm-mapping:godfat@localhost/dm-mapping')
25
28
  end
26
- end
29
+ end if defined?(DataObjects::Mysql)
30
+
31
+
32
+ # cost 3 seconds to run
33
+ class PostgresTest < Test::Unit::TestCase
34
+ include Abstract
35
+
36
+ def setup_data_mapper
37
+ DataMapper.setup(:default, 'postgres://dm-mapping:godfat@localhost/dm-mapping')
38
+ end
39
+ end if defined?(DataObjects::Postgres)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Lin Jen-Shin (a.k.a. godfat \xE7\x9C\x9F\xE5\xB8\xB8)"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-30 00:00:00 +08:00
12
+ date: 2008-09-01 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -56,6 +56,7 @@ files:
56
56
  - lib/dm-mapping.rb
57
57
  - lib/dm-mapping/adapters/abstract_adapter.rb
58
58
  - lib/dm-mapping/adapters/mysql_adapter.rb
59
+ - lib/dm-mapping/adapters/postgres_adapter.rb
59
60
  - lib/dm-mapping/adapters/sqlite3_adapter.rb
60
61
  - lib/dm-mapping/model.rb
61
62
  - lib/dm-mapping/type_map.rb