Created
January 29, 2019 07:24
-
-
Save rupython/e2f125d338fd5e10f56eb62c774fe683 to your computer and use it in GitHub Desktop.
From: models.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import peewee | |
db = peewee.SqliteDatabase('users.db') | |
class BaseModel(peewee.Model): | |
class Meta: | |
database = db | |
class User(BaseModel): | |
user_id = peewee.IntegerField(unique=True) | |
phone = peewee.TextField() | |
@classmethod | |
def user_exists(cls, uid): | |
return cls.select().where(cls.user_id == uid).exists() | |
@classmethod | |
def add_user(cls, uid, phone): | |
if cls.user_exists(uid): | |
return False | |
return cls.create(user_id=uid, phone=phone) | |
db.create_tables([User], safe=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment