Normalize messages table
This commit is contained in:
parent
9bec59b70a
commit
630a1fcc89
18 changed files with 490 additions and 240 deletions
|
@ -4,8 +4,8 @@
|
|||
import { assert } from 'chai';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { getMostRecentAddressableNondisappearingMessages } from '../../sql/Server';
|
||||
import type { WritableDB, ReadableDB, MessageType } from '../../sql/Interface';
|
||||
import { sql, jsonToObject } from '../../sql/util';
|
||||
import { createDB, insertData, updateToVersion } from './helpers';
|
||||
|
||||
import type { MessageAttributesType } from '../../model-types';
|
||||
|
@ -26,6 +26,28 @@ function generateMessage(json: MessageAttributesType) {
|
|||
};
|
||||
}
|
||||
|
||||
// Snapshot before: 1270
|
||||
export function getMostRecentAddressableNondisappearingMessages(
|
||||
db: ReadableDB,
|
||||
conversationId: string,
|
||||
limit = 5
|
||||
): Array<MessageType> {
|
||||
const [query, parameters] = sql`
|
||||
SELECT json FROM messages
|
||||
INDEXED BY messages_by_date_addressable_nondisappearing
|
||||
WHERE
|
||||
expireTimer IS NULL AND
|
||||
conversationId IS ${conversationId} AND
|
||||
isAddressableMessage = 1
|
||||
ORDER BY received_at DESC, sent_at DESC
|
||||
LIMIT ${limit};
|
||||
`;
|
||||
|
||||
const rows = db.prepare(query).all(parameters);
|
||||
|
||||
return rows.map(row => jsonToObject(row.json));
|
||||
}
|
||||
|
||||
describe('SQL/updateToSchemaVersion1080', () => {
|
||||
let db: WritableDB;
|
||||
beforeEach(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue