ANN: Criteria 1.0

Discussion in 'Ruby' started by Ryan Pavlik, Sep 8, 2003.

  1. Ryan Pavlik

    Ryan Pavlik Guest

    Criteria 1.0
    ============

    Criteria is a module for abstracting queries to various data sets.
    For instance, you might have a flat text file, or an array of Ruby
    objects, or a SQL database, and wish to perform the same query on
    any given source, without different versions of code for each.

    This module was inspired by the work of flgr (on #ruby-talk) on
    Junction, and the ENV.var work by h9k (also on #ruby-talk).

    Here are some examples:

    idx1 = SQLTable.new("orders")
    q1 = (idx1.price > idx1.paid) & (idx1.duedate < Time.now.to_i)

    q1.limit = 5
    q1.order = :ASC
    q1.order_by = idx1.name, idx1.age

    puts q1.select

    # => SELECT * FROM orders WHERE ((orders.price > orders.paid) AND
    # (orders.duedate < 1062616643)) LIMIT 5 ORDER BY orders.name,
    # orders.age ASC


    The generic Table superclass with the same query:

    idx2 = Table.new
    q2 = (idx2.price > idx2.paid) & (idx2.duedate < Time.now.to_i)

    puts q2.inspect
    puts q1.inspect

    # => (& (> :price :paid) (< :duedate 1062616719))
    # => (& (> :price :paid) (< :duedate 1062616719))

    The very simple 'mysql' table included works like SQLTable, except
    it actually returns a MysqlRes for immediate use. There are other
    included table types as well.

    You can find Criteria at the following location:

    http://mephle.org/Criteria/

    --
    Ryan Pavlik <>
     
    Ryan Pavlik, Sep 8, 2003
    #1
    1. Advertising

  2. Ryan Pavlik

    Tim Bates Guest

    On Mon, Sep 08, 2003 at 04:28:53PM +0900, Ryan Pavlik wrote:
    > Criteria 1.0
    > ============
    >
    > Criteria is a module for abstracting queries to various data sets.
    > For instance, you might have a flat text file, or an array of Ruby
    > objects, or a SQL database, and wish to perform the same query on
    > any given source, without different versions of code for each.

    <snip>
    > You can find Criteria at the following location:
    >
    > http://mephle.org/Criteria/


    From the above address:
    Basics
    ------

    To use the Critera module, it's helpful to understand how it works.
    The Table superclass is a class with most of the default instance
    methods removed. Instead, when given a method (including any
    operator methods), it generates a Criterion object in
    #method_missing.

    A Criterion is similar to a Table---it's another nearly-blank class,
    except it tracks the method call given to Table. It also chains to
    another Criterion. When evaluated recursively along this chain, the
    syntax of the statement can be restored.


    When I first saw the previous email, I thought - how on earth can he do
    that? It's a way to abstract queries to any sort of interface -
    something I've been trying to do for ages - and from the output it looks
    like it's somehow capturing the Ruby code and parsing it, but no; it's
    so much simpler than that. And done in only 65 lines of Ruby code. That
    is some seriously, seriously funky magic. Ryan, I'm extremely impressed.
    Once more the power of Ruby astounds me. The ability to translate the
    same abstract Ruby query into SQL code or an array lookup is just
    fantastic. Good work.

    One of these days I'm going to have to take a look at Mephle. If it's
    anything like as good as this, I'm in!

    Tim Bates
    --
     
    Tim Bates, Sep 11, 2003
    #2
    1. Advertising

  3. Ryan Pavlik

    Ryan Pavlik Guest

    On Thu, 11 Sep 2003 09:15:29 +0900
    Tim Bates <> wrote:

    <snip>
    > [Criteria] is some seriously, seriously funky magic. Ryan, I'm
    > extremely impressed. Once more the power of Ruby astounds me. The
    > ability to translate the same abstract Ruby query into SQL code or
    > an array lookup is just fantastic. Good work.


    Well, it was highly inspired by flgr's Junction code; that's where
    the basic magic came from. Glad you like it though. =)

    > One of these days I'm going to have to take a look at Mephle. If it's
    > anything like as good as this, I'm in!


    Mephle is less funky magic and more just doing mundane things for you.
    If you do web stuff at all, you'll probably find it takes a lot of
    work out of the process; by 1.0 I hope to be able to say the same
    about arbitrary GUI apps.

    Thanks,

    --
    Ryan Pavlik <>

    "I sure as hell didn't learn anything, if thats what you mean." - 8BT
     
    Ryan Pavlik, Sep 11, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephajn Craig

    Highlight Text based on certain criteria

    Stephajn Craig, Jul 7, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    386
    Axel Dahmen
    Jul 8, 2003
  2. VM
    Replies:
    12
    Views:
    589
    .NETgeek
    Feb 29, 2004
  3. =?Utf-8?B?U2NvdHQgYXQgQ2VkYXIgQ3JlZWs=?=

    Grid to count records meeting certain criteria (region)

    =?Utf-8?B?U2NvdHQgYXQgQ2VkYXIgQ3JlZWs=?=, Feb 9, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    381
    =?Utf-8?B?U2NvdHQgYXQgQ2VkYXIgQ3JlZWs=?=
    Feb 9, 2006
  4. Matt

    Show controls criteria specific

    Matt, Feb 17, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    336
  5. Justin Fowler
    Replies:
    4
    Views:
    409
    Joona I Palaste
    Aug 22, 2003
Loading...

Share This Page