On Jun 2, 5:10 am, Shawn <[EMAIL PROTECTED]> wrote:
> I hope some of the points I've made tonight, and the above intended
> use case, will merit further consideration for moving the literal
> method from Dataset to Database.

class Sequel::Database
  def literal(v)
    dataset.literal(v)
  end
end

It's not that hard, it gets you exactly what you want.  I've already
explained why literal is a Dataset method and not a Database method.
Having it as a Database method makes your life easier if you want to
access the database directly, but Sequel doesn't encourage that
behavior.  As for the speed difference, in the general case, having it
as a Dataset method is faster, since it is usually called from a
dataset.  If speed is a huge concern, you'd be using the direct
database connection to get it as fast as ruby can make it, or another
language if you wanted it to go faster than is possible with ruby.

You need to realize that your whole line of reasoning is based on an
edge case that Sequel doesn't encourage.  The work around to support
your desired API is the 5 lines of code displayed above.  Does it
waste cycles to create unnecessary datasets, yes, but by the same
token it wastes cycles to call a Database method when the vast
majority of use is inside Dataset.

Not too mention you shouldn't need to use the literal method to escape
data even when using the DB directly:

  DB['SELECT * FROM items WHERE id = ?', 1].all

If you look at the code, it creates a dataset and calls literal on it,
so your use case has already been considered.  Also, DB#[] returns a
dataset, so you have probably been using datasets without realizing
it:

  DB['SELECT * FROM items WHERE name = ?', "bl'ah"]
  => #<Sequel::Postgres::Dataset: "SELECT * FROM items WHERE name =
'bl''ah'">

Do you still think it is worth the effort to change Sequel just to
satisfy your particular use case?  Or will the simple workaround I
provided be sufficient?

Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to sequel-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to