completed migrate to tauri-sql
This commit is contained in:
@@ -20,6 +20,12 @@ export async function getActiveAccount() {
|
||||
return result[0];
|
||||
}
|
||||
|
||||
// get all accounts
|
||||
export async function getAccounts() {
|
||||
const db = await connect();
|
||||
return await db.select(`SELECT * FROM accounts ORDER BY created_at DESC;`);
|
||||
}
|
||||
|
||||
// create account
|
||||
export async function createAccount(pubkey: string, privkey: string, metadata: string) {
|
||||
const db = await connect();
|
||||
@@ -36,12 +42,25 @@ export async function updateAccount(column: string, value: string | string[], pu
|
||||
return await db.execute(`UPDATE accounts SET ${column} = '${JSON.stringify(value)}' WHERE pubkey = "${pubkey}";`);
|
||||
}
|
||||
|
||||
// get all plebs
|
||||
export async function getPlebs() {
|
||||
const db = await connect();
|
||||
return await db.select(`SELECT * FROM plebs ORDER BY created_at DESC;`);
|
||||
}
|
||||
|
||||
// create pleb
|
||||
export async function createPleb(pubkey: string, metadata: string) {
|
||||
const db = await connect();
|
||||
return await db.execute('INSERT OR IGNORE INTO plebs (pubkey, metadata) VALUES (?, ?);', [pubkey, metadata]);
|
||||
}
|
||||
|
||||
// count total notes
|
||||
export async function countTotalChannels() {
|
||||
const db = await connect();
|
||||
const result = await db.select('SELECT COUNT(*) AS "total" FROM channels;');
|
||||
return result[0];
|
||||
}
|
||||
|
||||
// count total notes
|
||||
export async function countTotalNotes() {
|
||||
const db = await connect();
|
||||
@@ -50,15 +69,72 @@ export async function countTotalNotes() {
|
||||
}
|
||||
|
||||
// get all notes
|
||||
export async function getNotes(time: string, limit: number, offset: number) {
|
||||
export async function getNotes(time: number, limit: number, offset: number) {
|
||||
const db = await connect();
|
||||
return await db.select(
|
||||
`SELECT * FROM notes WHERE created_at <= "${time}" ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`
|
||||
);
|
||||
}
|
||||
|
||||
// get note by id
|
||||
export async function getNoteByID(event_id) {
|
||||
const db = await connect();
|
||||
const result = await db.select(`SELECT * FROM notes WHERE event_id = "${event_id}";`);
|
||||
return result[0];
|
||||
}
|
||||
|
||||
// get all latest notes
|
||||
export async function getLatestNotes(time) {
|
||||
export async function getLatestNotes(time: number) {
|
||||
const db = await connect();
|
||||
return await db.select(`SELECT * FROM cache_notes WHERE created_at > "${time}" ORDER BY created_at DESC;`);
|
||||
}
|
||||
|
||||
// create note
|
||||
export async function createNote(
|
||||
event_id: string,
|
||||
account_id: number,
|
||||
pubkey: string,
|
||||
kind: number,
|
||||
tags: string[],
|
||||
content: string,
|
||||
created_at: number,
|
||||
parent_id: string
|
||||
) {
|
||||
const db = await connect();
|
||||
return await db.execute(
|
||||
'INSERT OR IGNORE INTO notes (event_id, account_id, pubkey, kind, tags, content, created_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);',
|
||||
[event_id, account_id, pubkey, kind, tags, content, created_at, parent_id]
|
||||
);
|
||||
}
|
||||
|
||||
// get all channels
|
||||
export async function getChannels(limit: number, offset: number) {
|
||||
const db = await connect();
|
||||
return await db.select(`SELECT * FROM channels ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`);
|
||||
}
|
||||
|
||||
// create channel
|
||||
export async function createChannel(event_id: string, metadata: string, created_at: number) {
|
||||
const db = await connect();
|
||||
return await db.execute('INSERT OR IGNORE INTO channels (event_id, metadata, created_at) VALUES (?, ?, ?);', [
|
||||
event_id,
|
||||
metadata,
|
||||
created_at,
|
||||
]);
|
||||
}
|
||||
|
||||
// get all chats
|
||||
export async function getChats(account_id: number) {
|
||||
const db = await connect();
|
||||
return await db.select(`SELECT * FROM chats WHERE account_id <= "${account_id}" ORDER BY created_at DESC;`);
|
||||
}
|
||||
|
||||
// create chat
|
||||
export async function createChat(account_id: number, pubkey: string, created_at: number) {
|
||||
const db = await connect();
|
||||
return await db.execute('INSERT OR IGNORE INTO chats (account_id, pubkey, created_at) VALUES (?, ?, ?);', [
|
||||
account_id,
|
||||
pubkey,
|
||||
created_at,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user