|
@@ -38,6 +38,7 @@ class Puppet:
|
|
photo_mxc: ContentURI | None
|
|
photo_mxc: ContentURI | None
|
|
name_set: bool
|
|
name_set: bool
|
|
avatar_set: bool
|
|
avatar_set: bool
|
|
|
|
+ contact_info_set: bool
|
|
|
|
|
|
is_registered: bool
|
|
is_registered: bool
|
|
|
|
|
|
@@ -56,6 +57,7 @@ class Puppet:
|
|
self.photo_mxc,
|
|
self.photo_mxc,
|
|
self.name_set,
|
|
self.name_set,
|
|
self.avatar_set,
|
|
self.avatar_set,
|
|
|
|
+ self.contact_info_set,
|
|
self.is_registered,
|
|
self.is_registered,
|
|
self.custom_mxid,
|
|
self.custom_mxid,
|
|
self.access_token,
|
|
self.access_token,
|
|
@@ -63,21 +65,26 @@ class Puppet:
|
|
str(self.base_url) if self.base_url else None,
|
|
str(self.base_url) if self.base_url else None,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ columns: ClassVar[str] = (
|
|
|
|
+ "pk, name, username, photo_id, photo_mxc, name_set, avatar_set, contact_info_set, "
|
|
|
|
+ "is_registered, custom_mxid, access_token, next_batch, base_url"
|
|
|
|
+ )
|
|
|
|
+
|
|
async def insert(self) -> None:
|
|
async def insert(self) -> None:
|
|
- q = (
|
|
|
|
- "INSERT INTO puppet (pk, name, username, photo_id, photo_mxc, name_set, avatar_set,"
|
|
|
|
- " is_registered, custom_mxid, access_token, next_batch, base_url) "
|
|
|
|
- "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)"
|
|
|
|
- )
|
|
|
|
|
|
+ q = f"""
|
|
|
|
+ INSERT INTO puppet ({self.columns})
|
|
|
|
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
|
|
|
+ """
|
|
await self.db.execute(q, *self._values)
|
|
await self.db.execute(q, *self._values)
|
|
|
|
|
|
async def update(self) -> None:
|
|
async def update(self) -> None:
|
|
- q = (
|
|
|
|
- "UPDATE puppet SET name=$2, username=$3, photo_id=$4, photo_mxc=$5, name_set=$6,"
|
|
|
|
- " avatar_set=$7, is_registered=$8, custom_mxid=$9, access_token=$10,"
|
|
|
|
- " next_batch=$11, base_url=$12 "
|
|
|
|
- "WHERE pk=$1"
|
|
|
|
- )
|
|
|
|
|
|
+ q = """
|
|
|
|
+ UPDATE puppet
|
|
|
|
+ SET name=$2, username=$3, photo_id=$4, photo_mxc=$5, name_set=$6, avatar_set=$7,
|
|
|
|
+ contact_info_set=$8, is_registered=$9, custom_mxid=$10, access_token=$11,
|
|
|
|
+ next_batch=$12, base_url=$13
|
|
|
|
+ WHERE pk=$1
|
|
|
|
+ """
|
|
await self.db.execute(q, *self._values)
|
|
await self.db.execute(q, *self._values)
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
@@ -89,11 +96,7 @@ class Puppet:
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
async def get_by_pk(cls, pk: int) -> Puppet | None:
|
|
async def get_by_pk(cls, pk: int) -> Puppet | None:
|
|
- q = (
|
|
|
|
- "SELECT pk, name, username, photo_id, photo_mxc, name_set, avatar_set, is_registered,"
|
|
|
|
- " custom_mxid, access_token, next_batch, base_url "
|
|
|
|
- "FROM puppet WHERE pk=$1"
|
|
|
|
- )
|
|
|
|
|
|
+ q = f"SELECT {cls.columns} FROM puppet WHERE pk=$1"
|
|
row = await cls.db.fetchrow(q, pk)
|
|
row = await cls.db.fetchrow(q, pk)
|
|
if not row:
|
|
if not row:
|
|
return None
|
|
return None
|
|
@@ -101,11 +104,7 @@ class Puppet:
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
async def get_by_custom_mxid(cls, mxid: UserID) -> Puppet | None:
|
|
async def get_by_custom_mxid(cls, mxid: UserID) -> Puppet | None:
|
|
- q = (
|
|
|
|
- "SELECT pk, name, username, photo_id, photo_mxc, name_set, avatar_set, is_registered,"
|
|
|
|
- " custom_mxid, access_token, next_batch, base_url "
|
|
|
|
- "FROM puppet WHERE custom_mxid=$1"
|
|
|
|
- )
|
|
|
|
|
|
+ q = f"SELECT {cls.columns} FROM puppet WHERE custom_mxid=$1"
|
|
row = await cls.db.fetchrow(q, mxid)
|
|
row = await cls.db.fetchrow(q, mxid)
|
|
if not row:
|
|
if not row:
|
|
return None
|
|
return None
|
|
@@ -113,10 +112,6 @@ class Puppet:
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
async def all_with_custom_mxid(cls) -> list[Puppet]:
|
|
async def all_with_custom_mxid(cls) -> list[Puppet]:
|
|
- q = (
|
|
|
|
- "SELECT pk, name, username, photo_id, photo_mxc, name_set, avatar_set, is_registered,"
|
|
|
|
- " custom_mxid, access_token, next_batch, base_url "
|
|
|
|
- "FROM puppet WHERE custom_mxid IS NOT NULL"
|
|
|
|
- )
|
|
|
|
|
|
+ q = f"SELECT {cls.columns} FROM puppet WHERE custom_mxid IS NOT NULL"
|
|
rows = await cls.db.fetch(q)
|
|
rows = await cls.db.fetch(q)
|
|
return [cls._from_row(row) for row in rows]
|
|
return [cls._from_row(row) for row in rows]
|