wip
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
import Database from 'tauri-plugin-sql-api';
|
||||
|
||||
import { Account } from '@utils/types';
|
||||
|
||||
async function connect(): Promise<Database> {
|
||||
let db: null | Database = null;
|
||||
|
||||
if (db) {
|
||||
return db;
|
||||
}
|
||||
|
||||
try {
|
||||
db = await Database.load('sqlite:lume.db');
|
||||
} catch (e) {
|
||||
throw new Error('Failed to connect to database, error: ', e);
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
export async function checkActiveAccount() {
|
||||
const db = await connect();
|
||||
const result: Array<Account> = await db.select(
|
||||
'SELECT * FROM accounts WHERE is_active = 1;'
|
||||
);
|
||||
|
||||
return result.length > 0;
|
||||
}
|
||||
@@ -24,3 +24,9 @@ export function getRepostID(tags: NDKTag[]) {
|
||||
|
||||
return quoteID;
|
||||
}
|
||||
|
||||
// get random n elements from array
|
||||
export function getMultipleRandom(arr: string[], num: number) {
|
||||
const shuffled = [...arr].sort(() => 0.5 - Math.random());
|
||||
return shuffled.slice(0, num);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user