Skip to content
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

Additional functions: Delete and Select #2

Open
Lisa999 opened this issue Sep 25, 2017 · 0 comments
Open

Additional functions: Delete and Select #2

Lisa999 opened this issue Sep 25, 2017 · 0 comments

Comments

@Lisa999
Copy link

Lisa999 commented Sep 25, 2017

@classmethod
def delete(cls, where, **fields):
    pkey_field = cls.__fields__[0]
    assert len(where) == 1 and pkey_field in where
    #print("update:", where)

    db = cls.__db__.db
    pkey = where[pkey_field]
    del(db[pkey])
    db.flush()

@classmethod
def select(cls, **fields):
    for v in cls.__db__.db.values():
        row = cls.Row(*ujson.loads(v))
        i = 0
        for k in cls.__fields__:
            if k in fields:
               if row[i] == fields[k]:
                  yield row
            i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant