New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to add (define) composite index #88

Closed
socketpair opened this Issue Oct 25, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@socketpair

socketpair commented Oct 25, 2014

Today, you have composite_key -> add UNIQUE check to the table. I did not found in documentation how I can create composite index, which allows duplicate values and allows effective range queries, which is not true for unique checks.

@socketpair socketpair changed the title from Add composite index creation to Add ability to add (define) composite index Oct 26, 2014

@kozlovsky kozlovsky self-assigned this Oct 28, 2014

@kozlovsky kozlovsky closed this in cfecb30 Oct 29, 2014

@kozlovsky

This comment has been minimized.

Show comment
Hide comment
@kozlovsky

kozlovsky Oct 29, 2014

Member

I added composite_index() which works the same way as composite_key(), but defines non-unique index instead:

class Person(db.Entity):
    id = PrimaryKey(int, auto=True)  # primary key
    passport_id = Required(str, unique=True)  # simple unique index
    name = Required(unicode, index=True)  # simple non-unique index
    age = Required(int)
    composite_key(name, age)  # unique composite index
    composite_index(age, name)  # non-unique composite index
Member

kozlovsky commented Oct 29, 2014

I added composite_index() which works the same way as composite_key(), but defines non-unique index instead:

class Person(db.Entity):
    id = PrimaryKey(int, auto=True)  # primary key
    passport_id = Required(str, unique=True)  # simple unique index
    name = Required(unicode, index=True)  # simple non-unique index
    age = Required(int)
    composite_key(name, age)  # unique composite index
    composite_index(age, name)  # non-unique composite index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment