Fuzzy-Searchable Emoji Picker

This commit is contained in:
Ken Powers 2019-05-24 16:58:27 -07:00 committed by Scott Nonnenberg
parent 2f47a3570b
commit 0e9d549cf3
48 changed files with 1697 additions and 280 deletions

View file

@ -123,6 +123,9 @@ module.exports = {
getAllStickers,
getRecentStickers,
updateEmojiUsage,
getRecentEmojis,
removeAll,
removeAllConfiguration,
@ -735,6 +738,29 @@ async function updateToSchemaVersion13(currentVersion, instance) {
console.log('updateToSchemaVersion13: success!');
}
async function updateToSchemaVersion14(currentVersion, instance) {
if (currentVersion >= 14) {
return;
}
console.log('updateToSchemaVersion14: starting...');
await instance.run('BEGIN TRANSACTION;');
await instance.run(`CREATE TABLE emojis(
shortName STRING PRIMARY KEY,
lastUsage INTEGER
);`);
await instance.run(`CREATE INDEX emojis_lastUsage
ON emojis (
lastUsage
);`);
await instance.run('PRAGMA schema_version = 14;');
await instance.run('COMMIT TRANSACTION;');
console.log('updateToSchemaVersion14: success!');
}
const SCHEMA_VERSIONS = [
updateToSchemaVersion1,
updateToSchemaVersion2,
@ -749,6 +775,7 @@ const SCHEMA_VERSIONS = [
updateToSchemaVersion11,
updateToSchemaVersion12,
updateToSchemaVersion13,
updateToSchemaVersion14,
];
async function updateSchema(instance) {
@ -2182,6 +2209,43 @@ async function getRecentStickers({ limit } = {}) {
return rows || [];
}
// Emojis
async function updateEmojiUsage(shortName, timeUsed = Date.now()) {
await db.run('BEGIN TRANSACTION;');
const rows = await db.get(
'SELECT * FROM emojis WHERE shortName = $shortName;',
{
$shortName: shortName,
}
);
if (rows) {
await db.run(
'UPDATE emojis SET lastUsage = $timeUsed WHERE shortName = $shortName;',
{ $shortName: shortName, $timeUsed: timeUsed }
);
} else {
await db.run(
'INSERT INTO emojis(shortName, lastUsage) VALUES ($shortName, $timeUsed);',
{ $shortName: shortName, $timeUsed: timeUsed }
);
}
await db.run('COMMIT TRANSACTION;');
}
async function getRecentEmojis(limit = 32) {
const rows = await db.all(
'SELECT * FROM emojis ORDER BY lastUsage DESC LIMIT $limit;',
{
$limit: limit,
}
);
return rows || [];
}
// All data in database
async function removeAll() {
let promise;