Skip to content

Instantly share code, notes, and snippets.

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