sql/: update seed.sql.erb, and create-sql-seed-file.
This commit is contained in:
parent
f763a9b7b3
commit
fb38880cbc
2 changed files with 9 additions and 3 deletions
|
@ -15,7 +15,9 @@ require_relative "../../binlib/sql/language"
|
||||||
require_relative "../../binlib/sql/chapter"
|
require_relative "../../binlib/sql/chapter"
|
||||||
require_relative "../../binlib/sql/verse"
|
require_relative "../../binlib/sql/verse"
|
||||||
require_relative "../../binlib/sql/sql_utils"
|
require_relative "../../binlib/sql/sql_utils"
|
||||||
|
require_relative "../../binlib/sql/row_mapper"
|
||||||
|
|
||||||
|
extend RowMapper
|
||||||
base_dir = File.join("src", "sql")
|
base_dir = File.join("src", "sql")
|
||||||
template = File.read File.join(base_dir, "seed.sql.erb")
|
template = File.read File.join(base_dir, "seed.sql.erb")
|
||||||
languages = %w[ar en pt fa].map { Language.new(_1) }
|
languages = %w[ar en pt fa].map { Language.new(_1) }
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
<% languages.each.with_index(1) do |language, quran_id| %>
|
<% 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| %>
|
<% 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| %>
|
<% 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 %>
|
<% end %>
|
||||||
<% chapter_id += 1 %>
|
<% chapter_id += 1 %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue