mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-09-13 13:55:24 +00:00
refactor(database)!: decouple SQLs from backend logic and cache stmts
This decouples SQLs from handler logic, makes it easier for auditing and caching. It also enables the possibility to switch or support multiple database backends.
This commit is contained in:
parent
b955d32099
commit
fafd2de2e3
11 changed files with 769 additions and 669 deletions
|
@ -17,12 +17,6 @@ CREATE TABLE IF NOT EXISTS `user_act_key` (
|
|||
PRIMARY KEY (`uid`, `act_key`)
|
||||
) STRICT, WITHOUT ROWID;
|
||||
|
||||
CREATE VIEW IF NOT EXISTS `valid_user_act_key` AS
|
||||
SELECT `act_key`, `user`.*
|
||||
FROM `user_act_key`
|
||||
JOIN `user` USING (`uid`)
|
||||
WHERE unixepoch() < `expire_time`;
|
||||
|
||||
-- The highest bit of `rid` will be set for peer chat room.
|
||||
-- So simply comparing it against 0 can filter them out.
|
||||
CREATE TABLE IF NOT EXISTS `room` (
|
||||
|
@ -43,6 +37,10 @@ CREATE UNIQUE INDEX IF NOT EXISTS `ix_peer_chat` ON `room`
|
|||
(`peer1`, `peer2`)
|
||||
WHERE `rid` < 0;
|
||||
|
||||
-- RoomAttrs::PUBLIC_READABLE
|
||||
CREATE INDEX IF NOT EXISTS `ix_public_room` ON `room` (`rid`)
|
||||
WHERE `attrs` & 1 != 0;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `room_member` (
|
||||
`rid` INTEGER NOT NULL REFERENCES `room` ON DELETE CASCADE,
|
||||
`uid` INTEGER NOT NULL REFERENCES `user` ON DELETE RESTRICT,
|
||||
|
@ -68,3 +66,11 @@ CREATE TABLE IF NOT EXISTS `msg` (
|
|||
) STRICT;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS `room_latest_msg` ON `msg` (`rid` ASC, `cid` DESC);
|
||||
|
||||
-- Temporary views.
|
||||
|
||||
CREATE TEMP VIEW `valid_user_act_key` AS
|
||||
SELECT `act_key`, `user`.*
|
||||
FROM `user_act_key`
|
||||
JOIN `user` USING (`uid`)
|
||||
WHERE unixepoch() < `expire_time`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue