Skip to content

Instantly share code, notes, and snippets.

@rupython
Created January 29, 2019 07:24
Show Gist options
  • Save rupython/e2f125d338fd5e10f56eb62c774fe683 to your computer and use it in GitHub Desktop.
Save rupython/e2f125d338fd5e10f56eb62c774fe683 to your computer and use it in GitHub Desktop.
From: models.py
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