discourse / mini_sql

a minimal, fast, safe sql executor
MIT License
395 stars 18 forks source link

add method `to_sql` and small refactoring #53

Closed ermolaev closed 1 year ago

ermolaev commented 1 year ago
$mini_sql.to_sql('select ?',  1)
ermolaev commented 1 year ago

Hello @SamSaffron, what do you think of this PR?

SamSaffron commented 1 year ago

I think it looks good, we are adding one call frame?

ermolaev commented 1 year ago

yes, to_sql is public method, we already have to_sql in builder

this PR unifies the public API and shortens the code, for example

SQL = MINI_SQL.build(<<~SQL).to_sql(state: LineItem::STATE::IN_DELIVERY)
  SELECT * from line_items WHERE order_id = :order_id AND state = :state
SQL

SQL = MINI_SQL.to_sql(<<~SQL, LineItem::STATE::IN_DELIVERY)
  SELECT * from line_items WHERE order_id = :order_id AND state = ?
SQL

MINI_SQL.prepared.query(SQL, order_id: order.id)