diff --git a/bin/sql/create-sql-seed-file b/bin/sql/create-sql-seed-file index fe986a3..153bbb2 100755 --- a/bin/sql/create-sql-seed-file +++ b/bin/sql/create-sql-seed-file @@ -15,7 +15,9 @@ require_relative "../../binlib/sql/language" require_relative "../../binlib/sql/chapter" require_relative "../../binlib/sql/verse" require_relative "../../binlib/sql/sql_utils" +require_relative "../../binlib/sql/row_mapper" +extend RowMapper base_dir = File.join("src", "sql") template = File.read File.join(base_dir, "seed.sql.erb") languages = %w[ar en pt fa].map { Language.new(_1) } diff --git a/src/sql/seed.sql.erb b/src/sql/seed.sql.erb index bf7b67f..002a3a4 100644 --- a/src/sql/seed.sql.erb +++ b/src/sql/seed.sql.erb @@ -1,9 +1,13 @@ <% languages.each.with_index(1) do |language, quran_id| %> - INSERT INTO qurans (locale) VALUES(<%= SQLUtils.escape(language.locale) %>); + INSERT INTO qurans (locale) VALUES (<%= SQLUtils.escape(language.locale) %>); <% language.chapters.each do |chapter| %> - INSERT INTO chapters (id, number, name, tr_name, slug, quran_id) VALUES(<%= [chapter_id, chapter.number, chapter.name, chapter.tr_name, chapter.slug, quran_id].join(",") %>); + INSERT INTO chapters ( + id, number, name, tr_name, slug, city, quran_id + ) VALUES ( <%= chapter_row(quran_id, chapter_id, chapter) %> ); <% chapter.verses.each do |verse| %> - INSERT INTO verses (number, quran_id, chapter_id, content) VALUES(<%= [verse.number, quran_id, chapter_id, SQLUtils.escape(verse.content)].join(",") %>); + INSERT INTO verses ( + number, quran_id, chapter_id, content + ) VALUES ( <%= verse_row(verse, quran_id, chapter_id) %> ); <% end %> <% chapter_id += 1 %> <% end %>