lsbardel / python-stdnet

Object-data mapper and advanced query manager for non relational databases
http://lsbardel.github.com/python-stdnet/
BSD 3-Clause "New" or "Revised" License
120 stars 20 forks source link

`unique` and/or `primary_key` have no effect on Redis #73

Open SamuelMarks opened 10 years ago

SamuelMarks commented 10 years ago

Test-case

from stdnet.odm import StdModel, CharField, Router

class Bar(StdModel):
    foo = CharField(primary_key=True, unique=True)

if __name__ == '__main__':
    models = Router('redis://localhost:6379?db=1')
    models.register(Bar)

    with models.session().begin() as transaction:
        transaction.add(models.bar.new(foo="Hello world"))
        transaction.add(models.bar.new(foo="Goodbye world"))
    with models.session().begin() as transaction:
        transaction.add(models.bar.new(foo="Hello world"))
        transaction.add(models.bar.new(foo="Goodbye world"))

    for f in models.bar.query().all():
        print '%r = %s' % (f, f.foo)

Output

Bar: Bar object = Hello world
Bar: Bar object = Goodbye world
Bar: Bar object = Hello world
Bar: Bar object = Goodbye world

FYI: I am running python-stdnet 0.8.2 on Python 2.7.5+ with Redis 2.8.2 on Ubuntu. Additionally have tried with python-stdnet 0.9a3.

lsbardel commented 10 years ago

Replace CharField with SymbolField

SamuelMarks commented 10 years ago

Thanks, that fixed the problem.

Why does CharField support unique and primary_key; if neither work?

lsbardel commented 10 years ago

It shouldn't you are right.