dm-mapping 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,14 @@
1
1
  = dm-mapper changes history
2
2
 
3
+ === dm-mapping 0.5.0, 2008-08-14
4
+ * feature added
5
+ - added mysql support.
6
+ - reflect size 65535 in TEXT for sqlite3.
7
+ * bug fixed
8
+ - reflect VARCHAR(size) instead of default size in sqlite3.
9
+ * misc
10
+ - renamed sqlite3adapter to sqlite3_adapter.
11
+
3
12
  === dm-mapping 0.4.1, 2008-08-14
4
13
  * removed type hack, replaced with rejecting special type to lookup.
5
14
 
data/NOTICE CHANGED
@@ -1,9 +1,30 @@
1
- = notice for other stuffs
1
+ = notice and thanks
2
2
 
3
3
  * dm-mapping is a plugin of DataMapper
4
4
  > sudo gem install dm-core
5
5
  http://datamapper.org
6
6
 
7
7
  * this project skeleton is built through Mr Bones
8
- > sudo gem install bones
9
8
  http://codeforpeople.rubyforge.org/bones/
9
+
10
+ * thanks to Rails team with ActiveRecord, it's inspiring.
11
+ and some SQL snippets are borrowed from it.
12
+ http://rubyonrails.org
13
+
14
+ * Ruby the great language
15
+ http://www.ruby-lang.org
16
+
17
+ * Rubygems the great package management
18
+ http://rubygems.org
19
+
20
+ * Rake the great task automation
21
+ http://rake.rubyforge.org
22
+
23
+ * Facets the great ruby library collection
24
+ http://facets.rubyforge.org/
25
+
26
+ * Rubyforge for distributing ruby gems
27
+ http://rubyforge.org
28
+
29
+ * Github for hosting git
30
+ http://github.com
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = dm-mapping 0.4.1
1
+ = dm-mapping 0.5.0
2
2
  by Lin Jen-Shin (a.k.a. godfat-真常[http://godfat.org])
3
3
  godfat (XD) godfat.org
4
4
 
@@ -18,9 +18,6 @@ by Lin Jen-Shin (a.k.a. godfat-真常[http://godfat.org])
18
18
  require 'dm-mapping'
19
19
  dm = DataMapper.setup :default, 'sqlite3:db/development.sqlite3'
20
20
 
21
- dm.object_id == DataMapper.repository.adapter.object_id
22
- # => true
23
-
24
21
  class User
25
22
  include DataMapper::Resource
26
23
  # mapping all
@@ -45,21 +42,26 @@ by Lin Jen-Shin (a.k.a. godfat-真常[http://godfat.org])
45
42
 
46
43
  # there's no guarantee of the order in fields array
47
44
  User.fields.sort
48
- # => [['created_at', DateTime, {}],
49
- ['email', String, {:size => 255, :default => 'nospam@nospam.tw'}],
50
- ['id', Integer, {:serial => true}],
51
- ['salt_first', String, {:size => 50}],
52
- ['salt_second', String, {:size => 50}]]
45
+ # => [['created_at', DateTime, {:nullable => true}],
46
+ ['email', String, {:nullable => true, :size => 255,
47
+ :default => 'nospam@nospam.tw'}],
48
+ ['id', Integer, {:nullable => false, :serial => true,
49
+ :key => true}],
50
+ ['salt_first', String, {:nullable => true, :size => 50}],
51
+ ['salt_second', String, {:nullable => true, :size => 50}]]
53
52
 
54
53
  dm.fields('users').sort == User.fields.sort
55
54
  # => true
56
55
 
57
56
  dm.storages_and_fields
58
- # => {'users' => [['id', Integer, {:serial => true}],
59
- ['email', String, {:default => 'nospam@nospam.tw'}],
60
- ['created_at', DateTime, {}],
61
- ['salt_first', String, {:size => 50}],
62
- ['salt_second', String, {:size => 50}]]}
57
+ # => {'users' => [['id', Integer, {:nullable => false,
58
+ :serial => true,
59
+ :key => true}],
60
+ ['email', String, {:nullable => true,
61
+ :default => 'nospam@nospam.tw'}],
62
+ ['created_at', DateTime, {:nullable => true}],
63
+ ['salt_first', String, {:nullable => true, :size => 50}],
64
+ ['salt_second', String, {:nullable => true, :size => 50}]]}
63
65
 
64
66
  # there's no guarantee of the order in returned array
65
67
  dm.auto_genclass!
@@ -74,7 +76,7 @@ by Lin Jen-Shin (a.k.a. godfat-真常[http://godfat.org])
74
76
  == REQUIREMENTS:
75
77
 
76
78
  * dm-core 0.9.3
77
- * at least one do_* adapter (currently only sqlite3 is supported)
79
+ * at least one do_* adapter (currently supports sqlite3 and mysql)
78
80
 
79
81
  == INSTALL:
80
82
 
data/TODO CHANGED
@@ -1,5 +1,4 @@
1
1
  = dm-mapping todo list
2
2
 
3
- * automatic determine model relationship
4
- * mysql adapter in 0.5
5
- * postgresql adapter in 0.6
3
+ * 0.6 postgresql adapter
4
+ * 0.7 automatic determine model relationship
data/dm-mapping.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |s|
3
3
  s.name = %q{dm-mapping}
4
- s.version = "0.4.1"
4
+ s.version = "0.5.0"
5
5
 
6
6
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
7
  s.authors = ["Lin Jen-Shin (a.k.a. godfat \347\234\237\345\270\270)"]
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.description = %q{DataMapper plugin that helps you manipulate an existing database. It creates mappings between existing columns and model's properties.}
10
10
  s.email = %q{godfat (XD) godfat.org}
11
11
  s.extra_rdoc_files = ["CHANGES", "LICENSE", "NOTICE", "README", "TODO", "dm-mapping.gemspec"]
12
- s.files = ["CHANGES", "LICENSE", "NOTICE", "README", "Rakefile", "TODO", "dm-mapping.gemspec", "lib/dm-mapping.rb", "lib/dm-mapping/adapters/abstract_adapter.rb", "lib/dm-mapping/adapters/sqlite3adapter.rb", "lib/dm-mapping/model.rb", "lib/dm-mapping/type_map.rb", "lib/dm-mapping/version.rb", "tasks/ann.rake", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/manifest.rake", "tasks/notes.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/spec.rake", "tasks/svn.rake", "tasks/test.rake", "test/test_sqlite3.rb"]
12
+ s.files = ["CHANGES", "LICENSE", "NOTICE", "README", "Rakefile", "TODO", "dm-mapping.gemspec", "lib/dm-mapping.rb", "lib/dm-mapping/adapters/abstract_adapter.rb", "lib/dm-mapping/adapters/mysql_adapter.rb", "lib/dm-mapping/adapters/sqlite3_adapter.rb", "lib/dm-mapping/model.rb", "lib/dm-mapping/type_map.rb", "lib/dm-mapping/version.rb", "tasks/ann.rake", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/manifest.rake", "tasks/notes.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/spec.rake", "tasks/svn.rake", "tasks/test.rake", "test/abstract.rb", "test/test_dm-mapping.rb"]
13
13
  s.has_rdoc = true
14
14
  s.homepage = %q{http://github.com/godfat/dm-mapping}
15
15
  s.rdoc_options = ["--diagram", "--charset=utf-8", "--inline-source", "--line-numbers", "--promiscuous", "--main", "README"]
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.rubyforge_project = %q{ludy}
18
18
  s.rubygems_version = %q{1.2.0}
19
19
  s.summary = %q{DataMapper plugin that helps you manipulate an existing database. It creates mappings between existing columns and model's properties.}
20
- s.test_files = ["test/test_sqlite3.rb"]
20
+ s.test_files = ["test/test_dm-mapping.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -18,7 +18,12 @@ module DataMapper
18
18
  # ['salt_first', String, {}],
19
19
  # ['salt_second', String, {}]]
20
20
  def fields storage
21
- raise NotImplementedError
21
+ dmm_query_storage(storage).map{ |field|
22
+ type, chain = self.class.type_map.
23
+ lookup_primitive(dmm_primitive(field))
24
+
25
+ [dmm_field_name(field), type, dmm_attributes(field)]
26
+ }
22
27
  end
23
28
 
24
29
  # returns a hash with storage names in keys and
@@ -58,6 +63,11 @@ module DataMapper
58
63
  scope.const_set(Extlib::Inflection.classify(storage), model)
59
64
  }
60
65
  end
66
+
67
+ private
68
+ def dmm_query_storage
69
+ raise NotImplementError.new("#{self.class}#fields is not implemented.")
70
+ end
61
71
  end
62
72
  end
63
73
  end
@@ -0,0 +1,47 @@
1
+
2
+ require 'dm-mapping/adapters/abstract_adapter'
3
+ require 'dm-mapping/type_map'
4
+
5
+ module DataMapper
6
+ module Adapters
7
+ class MysqlAdapter < DataObjectsAdapter #:nodoc: all
8
+ module Migration
9
+ def storages
10
+ query 'SHOW TABLES'
11
+ end
12
+
13
+ private
14
+ # construct needed table metadata
15
+ def dmm_query_storage storage
16
+ sql = <<-SQL.compress_lines
17
+ SELECT column_name, column_default, is_nullable, data_type,
18
+ character_maximum_length, column_key, extra
19
+ FROM `information_schema`.`columns`
20
+ WHERE `table_schema` = ? AND `table_name` = ?
21
+ SQL
22
+
23
+ query(sql, db_name, storage)
24
+ end
25
+
26
+ def dmm_field_name field
27
+ field.column_name
28
+ end
29
+
30
+ def dmm_primitive field
31
+ field.data_type
32
+ end
33
+
34
+ def dmm_attributes field, attrs = {}
35
+ attrs[:serial] = true if field.extra == 'auto_increment'
36
+ attrs[:key] = true if field.column_key == 'PRI'
37
+ attrs[:nullable] = field.is_nullable == 'YES'
38
+ attrs[:default] = field.column_default if field.column_default
39
+ attrs[:size] = field.character_maximum_length if
40
+ field.character_maximum_length
41
+
42
+ attrs
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,52 @@
1
+
2
+ require 'dm-mapping/adapters/abstract_adapter'
3
+ require 'dm-mapping/type_map'
4
+
5
+ module DataMapper
6
+ module Adapters
7
+ class Sqlite3Adapter < DataObjectsAdapter #:nodoc: all
8
+ module Migration
9
+ def storages
10
+ # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177
11
+ sql = <<-SQL.compress_lines
12
+ SELECT name
13
+ FROM sqlite_master
14
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
15
+ SQL
16
+ # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 181
17
+
18
+ query sql
19
+ end
20
+
21
+ private
22
+ alias_method :dmm_query_storage, :query_table
23
+ def dmm_field_name field
24
+ field.name
25
+ end
26
+
27
+ def dmm_primitive field
28
+ field.type.gsub(/\(\d+\)/, '')
29
+ end
30
+
31
+ def dmm_attributes field, attrs = {}
32
+ if field.pk != 0
33
+ attrs[:key] = true
34
+ attrs[:serial] = true if supports_serial?
35
+ end
36
+ attrs[:nullable] = field.notnull != 99
37
+ attrs[:default] = field.dflt_value[1..-2] if field.dflt_value
38
+
39
+ if field.type.upcase == 'TEXT'
40
+ attrs[:size] = 65535
41
+ else
42
+ ergo = field.type.match(/\((\d+)\)/)
43
+ size = ergo && ergo[1].to_i
44
+ attrs[:size] = size if size
45
+ end
46
+
47
+ attrs
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -7,7 +7,7 @@ module DataMapper
7
7
  # # => { DateTime => {:auto_validation => true} }
8
8
  def lookup_primitive primitive, type_map = self
9
9
  type_map.chains.find{ |type, chain|
10
- primitive == chain.primitive &&
10
+ primitive.upcase == chain.primitive &&
11
11
  [Integer, Float, BigDecimal,
12
12
  String, TrueClass, FalseClass,
13
13
  DateTime, Date, Time,
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Mapping
3
- VERSION = '0.4.1' unless defined?(DataMapper::Mapping::VERSION)
3
+ VERSION = '0.5.0' unless defined?(DataMapper::Mapping::VERSION)
4
4
  end
5
5
  end
data/lib/dm-mapping.rb CHANGED
@@ -11,8 +11,9 @@ module DataMapper
11
11
  class << self
12
12
  # ensure the using adapter is extended by dm-mapping
13
13
  def ensure_required_dm_mapping_adapter
14
- adapter_name = repository.adapter.class.to_s.split('::').last.downcase
15
- require "dm-mapping/adapters/#{adapter_name}"
14
+ require 'extlib'
15
+ adapter_name = repository.adapter.class.to_s.split('::').last
16
+ require "dm-mapping/adapters/#{Extlib::Inflection.underscore(adapter_name)}"
16
17
  end
17
18
 
18
19
  # dirty hack that hook requirement after setup.
@@ -1,17 +1,38 @@
1
1
 
2
- require 'test/unit'
3
-
4
2
  require 'rubygems'
5
3
  require 'data_mapper'
6
4
  require 'dm-mapping'
7
5
 
8
- class DMMTest < Test::Unit::TestCase
6
+ module Abstract
7
+ def setup_data_mapper
8
+ raise 'please provide an clean database because it is a destructive test!!'
9
+ end
10
+
11
+ AttrCommon = {:nullable => true}
12
+ AttrCommonPK = {:serial => true, :key => true, :nullable => false}
13
+ AttrText = {:size => 65535}.merge AttrCommon
14
+
15
+ def user_fields
16
+ [['created_at', DateTime, AttrCommon],
17
+ ['id', Integer, AttrCommonPK],
18
+ ['login', String, {:size => 70}.merge(AttrCommon)],
19
+ ['sig', DM::Text, AttrText]]
20
+ end
21
+
22
+ def comment_fields
23
+ [['body', DM::Text, AttrText],
24
+ ['id', Integer, AttrCommonPK],
25
+ ['title', String, {:size => 50, :default => 'default title'}.
26
+ merge(AttrCommon)],
27
+ ['user_id', Integer, AttrCommon]]
28
+ end
29
+
9
30
  class User
10
31
  include DataMapper::Resource
11
32
  has n, :comments
12
33
 
13
34
  property :id, Integer, :serial => true
14
- property :login, String
35
+ property :login, String, :size => 70
15
36
  property :sig, Text
16
37
  property :created_at, DateTime
17
38
  end
@@ -21,19 +42,10 @@ class DMMTest < Test::Unit::TestCase
21
42
  belongs_to :user
22
43
 
23
44
  property :id, Integer, :serial => true
24
- property :title, String, :default => 'default title'
45
+ property :title, String, :size => 50, :default => 'default title'
25
46
  property :body, Text
26
47
  end
27
48
 
28
-
29
- # override it to test with another adapter
30
- # NOTE:
31
- # please provide an clean database because it is a destructive test!!
32
- def setup_data_mapper
33
- DataMapper.setup(:default, 'sqlite3:tmp.db')
34
- end
35
-
36
-
37
49
  class Model; end
38
50
 
39
51
  def create_fake_model
@@ -49,23 +61,9 @@ class DMMTest < Test::Unit::TestCase
49
61
  Comment.auto_migrate!
50
62
  end
51
63
 
52
- def user_fields
53
- [['created_at', DateTime, {}],
54
- ['id', Integer, {:serial => true}],
55
- ['login', String, {:size => 50}],
56
- ['sig', DM::Text, {}]]
57
- end
58
-
59
- def comment_fields
60
- [['body', DM::Text, {}],
61
- ['id', Integer, {:serial => true}],
62
- ['title', String, {:size => 50, :default => 'default title'}],
63
- ['user_id', Integer, {}]]
64
- end
65
-
66
64
  def test_storages
67
- assert_equal ['dmm_test_comments', 'dmm_test_users'], dm.storages.sort
68
- assert_equal comment_fields, dm.fields('dmm_test_comments').sort
65
+ assert_equal ['abstract_comments', 'abstract_users'], dm.storages.sort
66
+ assert_equal comment_fields, dm.fields('abstract_comments').sort
69
67
  end
70
68
 
71
69
  def test_create_comment
@@ -77,10 +75,10 @@ class DMMTest < Test::Unit::TestCase
77
75
  def test_mapping_all
78
76
  test_create_comment # for fixtures
79
77
  model, local_dm = create_fake_model
80
- model.storage_names[:default] = 'dmm_test_comments'
78
+ model.storage_names[:default] = 'abstract_comments'
81
79
 
82
- assert_equal ['dmm_test_comments', 'dmm_test_users'], local_dm.storages.sort
83
- assert_equal 'dmm_test_comments', model.storage_name
80
+ assert_equal ['abstract_comments', 'abstract_users'], local_dm.storages.sort
81
+ assert_equal 'abstract_comments', model.storage_name
84
82
 
85
83
  assert_equal 1, model.count
86
84
  assert_equal comment_fields, model.fields.sort
@@ -92,7 +90,7 @@ class DMMTest < Test::Unit::TestCase
92
90
 
93
91
  def test_mapping_and_create
94
92
  model, local_dm = create_fake_model
95
- model.storage_names[:default] = 'dmm_test_comments'
93
+ model.storage_names[:default] = 'abstract_comments'
96
94
  model.send :mapping
97
95
 
98
96
  model.create(:title => 'orz')
@@ -104,8 +102,9 @@ class DMMTest < Test::Unit::TestCase
104
102
  end
105
103
 
106
104
  def test_storages_and_fields
107
- assert_equal user_fields, dm.fields('dmm_test_users').sort
108
- assert_equal( {'dmm_test_users' => user_fields, 'dmm_test_comments' => comment_fields},
105
+ assert_equal user_fields, dm.fields('abstract_users').sort
106
+ assert_equal( {'abstract_users' => user_fields,
107
+ 'abstract_comments' => comment_fields},
109
108
  dm.storages_and_fields.inject({}){ |r, i|
110
109
  key, value = i
111
110
  r[key] = value.sort
@@ -115,7 +114,7 @@ class DMMTest < Test::Unit::TestCase
115
114
 
116
115
  def test_mapping_type
117
116
  model, local_dm = create_fake_model
118
- model.storage_names[:default] = 'dmm_test_comments'
117
+ model.storage_names[:default] = 'abstract_comments'
119
118
  model.send :mapping, Integer
120
119
 
121
120
  assert_equal ['id', 'user_id'], model.properties.map(&:name).map(&:to_s).sort
@@ -123,7 +122,7 @@ class DMMTest < Test::Unit::TestCase
123
122
 
124
123
  def test_mapping_multiple
125
124
  model, local_dm = create_fake_model
126
- model.storage_names[:default] = 'dmm_test_users'
125
+ model.storage_names[:default] = 'abstract_users'
127
126
  model.send :mapping, :login, Integer
128
127
 
129
128
  assert_equal ['id', 'login'], model.properties.map(&:name).map(&:to_s).sort
@@ -131,7 +130,7 @@ class DMMTest < Test::Unit::TestCase
131
130
 
132
131
  def test_mapping_regexp
133
132
  model, local_dm = create_fake_model
134
- model.storage_names[:default] = 'dmm_test_comments'
133
+ model.storage_names[:default] = 'abstract_comments'
135
134
  model.send :mapping, /id$/
136
135
 
137
136
  assert_equal ['id', 'user_id'], model.properties.map(&:name).map(&:to_s).sort
@@ -144,16 +143,12 @@ class DMMTest < Test::Unit::TestCase
144
143
  end
145
144
 
146
145
  def test_auto_genclass
147
- for_test_auto_genclass
148
- for_test_auto_genclass Object
149
- end
150
-
151
- def for_test_auto_genclass scope = DataMapper::Mapping
152
- assert_equal ["#{scope == Object ? '' : "#{scope}::"}DmmTestComment",
153
- "#{scope == Object ? '' : "#{scope}::"}DmmTestUser"],
146
+ scope = self.class
147
+ assert_equal ["#{scope == Object ? '' : "#{scope}::"}AbstractComment",
148
+ "#{scope == Object ? '' : "#{scope}::"}AbstractUser"],
154
149
  dm.auto_genclass!(scope).map(&:to_s).sort
155
150
 
156
- comment = scope.const_get('DmmTestComment')
151
+ comment = scope.const_get('AbstractComment')
157
152
 
158
153
  assert_equal comment_fields, comment.fields.sort
159
154
 
@@ -0,0 +1,23 @@
1
+
2
+ require 'test/unit'
3
+ require 'test/abstract'
4
+
5
+ require 'dm-core/adapters/sqlite3_adapter'
6
+ require 'dm-core/adapters/mysql_adapter'
7
+ require 'dm-core/adapters/postgres_adapter'
8
+
9
+ class Sqlite3Test < Test::Unit::TestCase
10
+ include Abstract
11
+
12
+ def setup_data_mapper
13
+ DataMapper.setup(:default, 'sqlite3:tmp.sqlite3')
14
+ end
15
+ end
16
+
17
+ class MysqlTest < Test::Unit::TestCase
18
+ include Abstract
19
+
20
+ def setup_data_mapper
21
+ DataMapper.setup(:default, 'mysql://dm-mapping:godfat@localhost/dm-mapping')
22
+ end
23
+ end
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.1
4
+ version: 0.5.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-14 00:00:00 +08:00
12
+ date: 2008-08-15 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -55,7 +55,8 @@ files:
55
55
  - dm-mapping.gemspec
56
56
  - lib/dm-mapping.rb
57
57
  - lib/dm-mapping/adapters/abstract_adapter.rb
58
- - lib/dm-mapping/adapters/sqlite3adapter.rb
58
+ - lib/dm-mapping/adapters/mysql_adapter.rb
59
+ - lib/dm-mapping/adapters/sqlite3_adapter.rb
59
60
  - lib/dm-mapping/model.rb
60
61
  - lib/dm-mapping/type_map.rb
61
62
  - lib/dm-mapping/version.rb
@@ -72,7 +73,8 @@ files:
72
73
  - tasks/spec.rake
73
74
  - tasks/svn.rake
74
75
  - tasks/test.rake
75
- - test/test_sqlite3.rb
76
+ - test/abstract.rb
77
+ - test/test_dm-mapping.rb
76
78
  has_rdoc: true
77
79
  homepage: http://github.com/godfat/dm-mapping
78
80
  post_install_message:
@@ -106,4 +108,4 @@ signing_key:
106
108
  specification_version: 2
107
109
  summary: DataMapper plugin that helps you manipulate an existing database. It creates mappings between existing columns and model's properties.
108
110
  test_files:
109
- - test/test_sqlite3.rb
111
+ - test/test_dm-mapping.rb
@@ -1,37 +0,0 @@
1
-
2
- require 'dm-mapping/adapters/abstract_adapter'
3
- require 'dm-mapping/type_map'
4
-
5
- module DataMapper
6
- module Adapters
7
- class Sqlite3Adapter < DataObjectsAdapter #:nodoc: all
8
- module Migration
9
- def storages
10
- # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 177
11
- sql = <<-SQL
12
- SELECT name
13
- FROM sqlite_master
14
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
15
- SQL
16
- # activerecord-2.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb: 181
17
-
18
- query sql
19
- end
20
-
21
- def fields table
22
- query_table(table).map{ |field|
23
- type, chain = self.class.type_map.
24
- lookup_primitive(field.type.gsub(/\(\d+\)/, '').upcase)
25
-
26
- attrs = {}
27
- attrs[:serial] = true if field.pk != 0
28
- attrs[:nullable] = true if field.notnull != 0 && !attrs[:serial]
29
- attrs[:default] = field.dflt_value[1..-2] if field.dflt_value
30
-
31
- [field.name, type, attrs.merge(chain.attributes)]
32
- }
33
- end
34
- end
35
- end
36
- end
37
- end