blob: 5ee2f16d66be03e2fd53c1165d55d02b526cfb03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
from time import time
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.sql import text
class Base(DeclarativeBase):
pass
db = SQLAlchemy(model_class=Base)
def user_new(nick):
sql = "INSERT \
INTO users (nick, created) \
VALUES (:nick, :created) \
RETURNING id ;"
result = db.session.execute(
text(sql), { "nick":nick, "created":int(time()) }
)
db.session.commit()
return result.fetchone()[0]
def user_get_nick(id):
sql = "SELECT nick \
FROM users \
WHERE id=(:id);"
return db.session.execute(text(sql), { "id":id }).fetchone()[0]
def user_exists(nick):
sql = "SELECT COUNT(id) \
FROM users \
WHERE nick=(:nick);"
return db.session.execute(text(sql), { "nick":nick }).scalar()
|