Add support for postgres instead of mysql. Change sql accourdingly. blob + varbinary -> bytea. No support for UNSIGNED or CREATE INDEX IF NOT EXISTS.

This commit is contained in:
Erik Johnston 2015-04-14 13:53:20 +01:00
parent 3c741682e5
commit 58d8339966
21 changed files with 153 additions and 140 deletions

View file

@ -105,14 +105,12 @@ class RoomStore(SQLBaseStore):
# We use non printing ascii character US (\x1F) as a separator
sql = (
"SELECT r.room_id, n.name, t.topic, "
"group_concat(a.room_alias, '\x1F') "
"FROM rooms AS r "
"LEFT JOIN (%(topic)s) AS t ON t.room_id = r.room_id "
"LEFT JOIN (%(name)s) AS n ON n.room_id = r.room_id "
"INNER JOIN room_aliases AS a ON a.room_id = r.room_id "
"WHERE r.is_public = ? "
"GROUP BY r.room_id "
"SELECT r.room_id, max(n.name), max(t.topic)"
" FROM rooms AS r"
" LEFT JOIN (%(topic)s) AS t ON t.room_id = r.room_id"
" LEFT JOIN (%(name)s) AS n ON n.room_id = r.room_id"
" WHERE r.is_public = ?"
" GROUP BY r.room_id"
) % {
"topic": topic_subquery,
"name": name_subquery,
@ -120,7 +118,22 @@ class RoomStore(SQLBaseStore):
txn.execute(sql, (is_public,))
return txn.fetchall()
rows = txn.fetchall()
for i, row in enumerate(rows):
room_id = row[0]
aliases = self._simple_select_onecol_txn(
txn,
table="room_aliases",
keyvalues={
"room_id": room_id
},
retcol="room_alias",
)
rows[i] = list(row) + [aliases]
return rows
rows = yield self.runInteraction(
"get_rooms", f
@ -131,9 +144,10 @@ class RoomStore(SQLBaseStore):
"room_id": r[0],
"name": r[1],
"topic": r[2],
"aliases": r[3].split("\x1F"),
"aliases": r[3],
}
for r in rows
if r[3] # We only return rooms that have at least one alias.
]
defer.returnValue(ret)