mirror of
https://github.com/SantaSpeen/RoyaltyIT-tg-bot.git
synced 2026-02-16 02:20:42 +00:00
DataBase models
This commit is contained in:
32
src/SqlModels.py
Normal file
32
src/SqlModels.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from peewee import Model, SqliteDatabase, IntegerField, DoubleField, DoesNotExist
|
||||
|
||||
conn = SqliteDatabase('sqlite3.db')
|
||||
|
||||
|
||||
class BaseModel(Model):
|
||||
class Meta:
|
||||
database = conn
|
||||
|
||||
|
||||
class Users(BaseModel):
|
||||
|
||||
id = IntegerField(null=True)
|
||||
user_id = IntegerField()
|
||||
warns = IntegerField(null=True, default=0)
|
||||
muted_until = DoubleField(null=True, default=0.0)
|
||||
banned_until = DoubleField(null=True, default=0.0)
|
||||
|
||||
class Meta:
|
||||
table_name = 'users'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
user = Users.get(Users.id == 1)
|
||||
except DoesNotExist:
|
||||
user = Users(user_id=1292)
|
||||
|
||||
user.warns += 1
|
||||
user.save()
|
||||
|
||||
print("test:", user.warns)
|
||||
11
src/sl3.sql
Normal file
11
src/sl3.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
DROP TABLE IF EXISTS `users`;
|
||||
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||
UNIQUE,
|
||||
user_id INTEGER UNIQUE
|
||||
NOT NULL,
|
||||
warns INTEGER DEFAULT (0),
|
||||
muted_until DOUBLE DEFAULT (0.0),
|
||||
banned_until DOUBLE DEFAULT (0.0)
|
||||
);
|
||||
Reference in New Issue
Block a user