1
0
Fork 0

Translate a part of speech

This commit is contained in:
Alex Kotov 2023-02-18 14:40:01 +04:00
parent 8096d98904
commit e0a9a2624b
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
1 changed files with 12 additions and 4 deletions

16
main.rb
View File

@ -22,7 +22,7 @@ before do
end
get '/words/:id' do
Context.call db_pool: $DB_POOL, user_lang_id: nil do |context|
Context.call db_pool: $DB_POOL, user_lang_id: 2 do |context|
word_id = Integer params[:id]
json({
@ -76,15 +76,23 @@ public
column = @db_conn.exec_params(
(
<<~SQL
SELECT parts.english_name
SELECT part_names.value
FROM words
INNER JOIN parts
ON words.part_id = parts.id
WHERE words.id = $1
INNER JOIN part_names
ON part_names.part_id = parts.id
WHERE
words.id = $1
AND (
part_names.name_lang_id = $2
OR
$2 IS NULL
)
LIMIT 1
SQL
),
[word_id],
[word_id, user_lang_id],
).values.first&.first
str = String(column).strip.freeze