mirror of
https://github.com/discourse/discourse.git
synced 2025-06-21 00:03:51 +08:00
DEV: Small API changes for interacting with PG during migrations (#32976)
This commit is contained in:
@ -27,16 +27,20 @@ module Migrations::Database::Adapter
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def query_first(sql)
|
def query_first_row(sql)
|
||||||
@connection.exec(sql).first
|
@connection.exec(sql).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def query_value(sql, column)
|
def query_value(sql, column = nil)
|
||||||
query_first(sql)[column]
|
if (row = query_first_row(sql))
|
||||||
|
column ? row[column.to_sym] : row.values.first
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def count(sql)
|
def count(sql)
|
||||||
query_first(sql).values.first.to_i
|
query_value(sql).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
|
Reference in New Issue
Block a user