From fb38880cbca70a1c3478ecdad542ee0ff9dea523 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 2 Sep 2022 15:45:24 -0300 Subject: [PATCH] sql/: update seed.sql.erb, and create-sql-seed-file. --- bin/sql/create-sql-seed-file | 2 ++ src/sql/seed.sql.erb | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) 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 %>