Skip to content

Add index static value sugar. #595

Closed

Description

@jdoliner

There are at least 2 pieces of static value sugar I think are needed for secondary indexes:

# indexing a field, the following are equivalent
table.index("foo")
table.index("foo", "foo")
table.index("foo", lambda x: x["foo"])

# compound indexes, the following are equivalent
table.index(["foo", "bar"]) # This one seems questionable
table.index("foo_bar", ["foo", "bar"])
table.index("foo_bar", lambda x: [x["foo"], x["bar"]])

The first compound index notation seems questionable to me because it's not an immediately obvious name, on the other hand it's convenient and I can't see any way it's dangerous so it's probably okay.

Presumably these should be done server side rather than in the drivers.

Also we need API tests for this.

Activity

  1. coffeemug commented on Apr 5, 2013

    @coffeemug
    Contributor

    I'd replace index with index_create. I'd drop the compound one you marked as questionable. Everything else seems awesome.

  2. al3xandru commented on Apr 8, 2013

    @al3xandru
    Contributor

    We should try to stay close to the API we provide around databases and tables:

    • index_create
    • index_drop
    • index_list

    For index_create we can probably have the following supported:

    table.index_create("name", lambda doc: doc['name'])
    table.index_create("name", "field_name")  # shortcut for above
    
    # compound
    table.index_create("name", lambda doc: [doc['first_name'], doc['last_name']]) 
    table.index_create("name", ["first_name", "last_name"])
  3. coffeemug commented on Apr 8, 2013

    @coffeemug
    Contributor

    I think table.index_create('name') is a good shortcut since 99% of the time people create indexes on attributes. Having to say table.index_create('foo', 'foo') all the time can get pretty annoying :)

  4. al3xandru commented on Apr 9, 2013

    @al3xandru
    Contributor

    Considering there'll also be the option of naming a basic index (with signature index_create(string, string)), things will get confusing: which is the name of index (first or second parameter)?

  5. coffeemug commented on Apr 17, 2013

    @coffeemug
    Contributor

    Closing as dup of #602.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions