Class: DataMapper::Adapters::Tokyo::CabinetAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- DataMapper::Adapters::Tokyo::CabinetAdapter
- Defined in:
- lib/dm-tokyo-adapter/cabinet.rb
Overview
A DataMapper Tokyo Cabinet table store adapter.
tokyocabinet.sourceforge.net/spex-en.html#features_tctdb
The Tokyo Cabinet table storage engine doesn’t require a predefined schema and as such properties in your resource are only used by the adapter for typecasting. There is no need to migrate your resource when you create, update or delete properties.
See
- DataMapper::Adapters::Tokyo::Query
-
Table Query.
Direct Known Subclasses
Instance Method Summary collapse
- #create(resources) ⇒ Object
- #delete(collection) ⇒ Object
- #read(query) ⇒ Object
- #update(attributes, collection) ⇒ Object
Instance Method Details
#create(resources) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dm-tokyo-adapter/cabinet.rb', line 17 def create(resources) resources.map do |resource| model = resource.model with_connection(resource.model) do |connection| initialize_serial(resource, connection.generate_unique_id) connection[key(resource)] = attributes(resource, :field) end end.size end |
#delete(collection) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/dm-tokyo-adapter/cabinet.rb', line 42 def delete(collection) with_connection(collection.query.model) do |connection| collection.each do |record| connection.delete(key(record)) end.size end end |
#read(query) ⇒ Object
28 29 30 31 32 |
# File 'lib/dm-tokyo-adapter/cabinet.rb', line 28 def read(query) with_connection(query.model) do |connection| Tokyo::Query.new(connection, query).read end end |
#update(attributes, collection) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/dm-tokyo-adapter/cabinet.rb', line 34 def update(attributes, collection) with_connection(collection.query.model) do |connection| collection.each do |record| connection[key(record)] = attributes(record, :field) end.size end end |