dm-mapping 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/README +2 -2
- data/TODO +1 -1
- data/lib/dm-mapping/adapters/mysql_adapter.rb +1 -1
- data/lib/dm-mapping/adapters/postgres_adapter.rb +73 -0
- data/lib/dm-mapping/adapters/sqlite3_adapter.rb +1 -1
- data/lib/dm-mapping/version.rb +1 -1
- data/test/test_dm-mapping.rb +15 -2
- metadata +3 -2
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.
|
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
|
98
|
+
* at least one do_* adapter
|
99
99
|
|
100
100
|
== INSTALL:
|
101
101
|
|
data/TODO
CHANGED
@@ -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
|
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
|
data/lib/dm-mapping/version.rb
CHANGED
data/test/test_dm-mapping.rb
CHANGED
@@ -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.
|
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-
|
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
|