1
0
Fork 0

Return new inflections

This commit is contained in:
Alex Kotov 2023-03-05 21:11:30 +04:00
parent 9cc8e71d1c
commit bbbc030e67
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 33 additions and 1 deletions

34
main.rb
View File

@ -32,7 +32,8 @@ get '/words/:id' do
part_of_speech: context.part_of_speech_name(word_id),
commentary: word_info[:commentary],
translations: context.translations(word_id),
inflections: word_info[:inflections],
inflections_old: word_info[:inflections],
inflections: context.inflections(word_id),
examples: context.examples(word_id),
})
end
@ -168,6 +169,37 @@ public
end.freeze
end
def inflections(word_id)
word_id = Integer word_id
result = @db_conn.exec_params(
(
<<~SQL
SELECT inflections.descr, word_forms.value
FROM words
INNER JOIN parts
ON parts.id = words.part_id
INNER JOIN inflections
ON inflections.part_id = parts.id
LEFT JOIN word_forms
ON word_forms.inflection_id = inflections.id
WHERE words.id = $1 AND word_forms.word_id = $1
SQL
),
[word_id],
).to_a
result.map do |row|
descr = String(row['descr']).strip.freeze
value = String(row['value']).strip.freeze
{
descr: descr,
value: value,
}
end.freeze
end
def examples(word_id)
word_id = Integer word_id