Class: MusicStory::Repository::Sequel
- Inherits:
-
Object
- Object
- MusicStory::Repository::Sequel
- Defined in:
- lib/music_story/repository/sequel.rb
Instance Attribute Summary collapse
-
#artist_repo ⇒ Object
readonly
Returns the value of attribute artist_repo.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#genre_repo ⇒ Object
readonly
Returns the value of attribute genre_repo.
Instance Method Summary collapse
- #create_tables! ⇒ Object
- #drop_tables! ⇒ Object
-
#initialize(db) ⇒ Sequel
constructor
A new instance of Sequel.
Constructor Details
#initialize(db) ⇒ Sequel
Returns a new instance of Sequel.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/music_story/repository/sequel.rb', line 3 def initialize(db) db = Sequel.connect(db) unless db.is_a?(Sequel::Database) @db = db @artist_repo = Repository::ArtistSequel.new(db) @genre_repo = Repository::GenreSequel.new(db) [:similar_artists, :influenced_by_artists, :successor_artists].each do |prop| @artist_repo.mapper(prop).target_repo = @artist_repo end [:main_genres, :secondary_genres, :influenced_by_genres].each do |prop| @artist_repo.mapper(prop).target_repo = @genre_repo end end |
Instance Attribute Details
#artist_repo ⇒ Object (readonly)
Returns the value of attribute artist_repo.
16 17 18 |
# File 'lib/music_story/repository/sequel.rb', line 16 def artist_repo @artist_repo end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
16 17 18 |
# File 'lib/music_story/repository/sequel.rb', line 16 def db @db end |
#genre_repo ⇒ Object (readonly)
Returns the value of attribute genre_repo.
16 17 18 |
# File 'lib/music_story/repository/sequel.rb', line 16 def genre_repo @genre_repo end |
Instance Method Details
#create_tables! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/music_story/repository/sequel.rb', line 24 def create_tables! @db.create_table(:artist_associations, :ignore_index_errors=>true) do Integer :from_artist_id, :null=>false Integer :to_artist_id, :null=>false String :relation, :size=>16 primary_key [:from_artist_id, :relation, :to_artist_id] index [:to_artist_id], :name=>:to_artist_id end @db.create_table(:artist_genres, :ignore_index_errors=>true) do Integer :artist_id, :null=>false Integer :genre_id, :null=>false String :relation, :size=>16 primary_key [:artist_id, :relation, :genre_id] index [:genre_id], :name=>:genre_id end @db.create_table(:artists, :ignore_index_errors=>true) do primary_key :id String :name, :null=>false, :size=>255 String :forename, :size=>255 String :real_name, :size=>255 String :role, :size=>64 String :type, :size=>64 String :country, :size=>64 String :summary_html, :text=>true String :bio_html, :text=>true String :image_filename, :text=>true index [:name], :name=>:name end @db.create_table(:genres) do primary_key :id String :name, :null=>false, :size=>255 end end |
#drop_tables! ⇒ Object
18 19 20 21 22 |
# File 'lib/music_story/repository/sequel.rb', line 18 def drop_tables! [:genres, :artist_associations, :artist_genres, :artists].each do |table| begin ; @db.drop_table(table) ; rescue ; end end end |