Created
January 29, 2019 07:30
-
-
Save rupython/58e668a5d1e9adc82168b7c0808b0393 to your computer and use it in GitHub Desktop.
From: Павел
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