Class: Taggata::DbAdapters::Sequel
- Defined in:
- lib/taggata/db_adapters/sequel.rb
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
- #bulk_insert(klass, values) ⇒ Object
- #destroy(klass, options) ⇒ Object
- #find(klass, options) ⇒ Object
- #find_one(klass, options) ⇒ Object
- #find_tags_without_files ⇒ Object
- #find_untagged_files ⇒ Object
- #initialize_db(db_path) ⇒ Object
- #migrate_db ⇒ Object
- #save(table, hash) ⇒ Object
- #search(klass, options) ⇒ Object
- #transaction(block) ⇒ Object
Instance Method Details
#bulk_insert(klass, values) ⇒ Object
8 9 10 |
# File 'lib/taggata/db_adapters/sequel.rb', line 8 def bulk_insert(klass, values) db[klass.table].multi_insert(values) end |
#destroy(klass, options) ⇒ Object
32 33 34 |
# File 'lib/taggata/db_adapters/sequel.rb', line 32 def destroy(klass, ) db[klass.table].where().delete end |
#find(klass, options) ⇒ Object
36 37 38 |
# File 'lib/taggata/db_adapters/sequel.rb', line 36 def find(klass, ) db[klass.table].where().all end |
#find_one(klass, options) ⇒ Object
40 41 42 |
# File 'lib/taggata/db_adapters/sequel.rb', line 40 def find_one(klass, ) db[klass.table].where().limit(1).first end |
#find_tags_without_files ⇒ Object
25 26 27 28 29 30 |
# File 'lib/taggata/db_adapters/sequel.rb', line 25 def = db[Persistent::FileTag.table].select(:tag_id).map { |hash| hash[:tag_id] } tag_ids = db[Persistent::Tag.table].select(:id).map { |hash| hash[:id] } untagged_ids = tag_ids.reject { |id| .include? id } find(Persistent::Tag, :id => untagged_ids) end |
#find_untagged_files ⇒ Object
18 19 20 21 22 23 |
# File 'lib/taggata/db_adapters/sequel.rb', line 18 def find_untagged_files = db[Persistent::FileTag.table].select(:file_id).map { |hash| hash[:file_id] } file_ids = db[Persistent::File.table].select(:id).map { |hash| hash[:id] } untagged_ids = file_ids.reject { |id| .include? id } find(Taggata::Persistent::File, :id => untagged_ids) end |
#initialize_db(db_path) ⇒ Object
57 58 59 |
# File 'lib/taggata/db_adapters/sequel.rb', line 57 def initialize_db(db_path) @db = ::Sequel.connect db_path end |
#migrate_db ⇒ Object
61 62 63 |
# File 'lib/taggata/db_adapters/sequel.rb', line 61 def migrate_db ::Sequel::Migrator.run(db, self.class.migrations_path, table: 'taggata_schema_info') end |
#save(table, hash) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/taggata/db_adapters/sequel.rb', line 48 def save(table, hash) existing_record = db[table].where(primary_key(table, hash)).limit(1) if existing_record.count == 0 db[table].insert(hash) else existing_record.update(hash) end end |
#search(klass, options) ⇒ Object
44 45 46 |
# File 'lib/taggata/db_adapters/sequel.rb', line 44 def search(klass, ) db[klass.table].where() end |
#transaction(block) ⇒ Object
12 13 14 15 16 |
# File 'lib/taggata/db_adapters/sequel.rb', line 12 def transaction(block) db.transaction do block.call end end |