in crashclouseau/models.py [0:0]
def get_id(info):
if not info:
return 1
info = info[0]
email, real, nick = info
sel = db.select(db.literal(email), db.literal(real), db.literal(nick)).where(
~db.exists().where(
db.and_(
HGAuthor.email == email,
HGAuthor.real == real,
HGAuthor.nick == nick,
)
)
)
ins = (
db.insert(HGAuthor)
.from_select([HGAuthor.email, HGAuthor.real, HGAuthor.nick], sel)
.returning(HGAuthor.id)
.cte("inserted")
)
rs = (
db.session.query(HGAuthor.id)
.filter(
HGAuthor.email == email, HGAuthor.real == real, HGAuthor.nick == nick
)
.union_all(
db.session.query(HGAuthor.id)
.select_from(ins)
.filter(Signature.id == ins.c.id)
)
)
first = rs.first()
if first is None:
first = rs.first()
id = first[0]
db.session.commit()
return id