sql: add "name", "tr_name", and "slug" to chapters table.
This commit is contained in:
parent
6a8a33ac62
commit
5f13718806
4 changed files with 487 additions and 457 deletions
|
@ -1,14 +1,41 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Chapter
|
||||
CHAPTERS = JSON.parse(
|
||||
File.read(
|
||||
File.join('src', 'json', 'chapters-data.json')
|
||||
)
|
||||
)
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
@locale = File.basename(File.dirname(path))
|
||||
end
|
||||
|
||||
def number
|
||||
File.basename(@path, ".json").to_i
|
||||
end
|
||||
|
||||
def name
|
||||
if @locale == "ar"
|
||||
SQLUtils.escape "".dup.concat(*CHAPTERS[number - 1]['codepoints'])
|
||||
else
|
||||
SQLUtils.escape CHAPTERS[number - 1]['translated_name']
|
||||
end
|
||||
end
|
||||
|
||||
def tr_name
|
||||
if @locale == "ar"
|
||||
name
|
||||
else
|
||||
SQLUtils.escape CHAPTERS[number - 1]['transliterated_name']
|
||||
end
|
||||
end
|
||||
|
||||
def slug
|
||||
SQLUtils.escape CHAPTERS[number - 1]['slug']
|
||||
end
|
||||
|
||||
def verses
|
||||
JSON.parse(File.read(@path)).map { Verse.new(*_1) }
|
||||
end
|
||||
|
|
|
@ -6,6 +6,9 @@ CREATE TABLE qurans(
|
|||
CREATE TABLE chapters(
|
||||
id integer primary key autoincrement,
|
||||
number tinyint NOT NULL,
|
||||
name char(50) NOT NULL,
|
||||
tr_name char(50) NOT NULL,
|
||||
slug char(50) NOT NULL,
|
||||
quran_id tinyint NOT NULL,
|
||||
CONSTRAINT chapters_quran_fk FOREIGN KEY (quran_id) REFERENCES qurans (id)
|
||||
);
|
||||
|
|
912
src/sql/seed.sql
912
src/sql/seed.sql
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
|||
<% languages.each.with_index(1) do |language, quran_id| %>
|
||||
INSERT INTO qurans (locale) VALUES(<%= SQLUtils.escape(language.locale) %>);
|
||||
<% language.chapters.each do |chapter| %>
|
||||
INSERT INTO chapters (id, number, quran_id) VALUES(<%= [chapter_id, chapter.number, quran_id].join(",") %>);
|
||||
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(",") %>);
|
||||
<% 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(",") %>);
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue