added create channel to sql and browse channels page

This commit is contained in:
Ren Amamiya
2023-04-10 11:29:06 +07:00
parent 549cc991a9
commit 213d7514d2
7 changed files with 95 additions and 6 deletions

View File

@@ -0,0 +1,12 @@
-- CreateTable
CREATE TABLE "Channel" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"eventId" TEXT NOT NULL,
"content" TEXT NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "Channel_eventId_key" ON "Channel"("eventId");
-- CreateIndex
CREATE INDEX "Channel_eventId_idx" ON "Channel"("eventId");

View File

@@ -66,6 +66,14 @@ model Message {
@@index([pubkey, createdAt])
}
model Channel {
id Int @id @default(autoincrement())
eventId String @unique
content String
@@index([eventId])
}
model Relay {
id Int @id @default(autoincrement())
url String

View File

@@ -81,6 +81,12 @@ struct GetLatestNoteData {
date: i32,
}
#[derive(Deserialize, Type)]
struct CreateChannelData {
event_id: String,
content: String,
}
#[tauri::command]
#[specta::specta]
async fn get_accounts(db: DbState<'_>) -> Result<Vec<account::Data>, ()> {
@@ -215,6 +221,16 @@ async fn count_total_notes(db: DbState<'_>) -> Result<i64, ()> {
db.note().count(vec![]).exec().await.map_err(|_| ())
}
#[tauri::command]
#[specta::specta]
async fn create_channel(db: DbState<'_>, data: CreateChannelData) -> Result<channel::Data, ()> {
db.channel()
.create(data.event_id, data.content, vec![])
.exec()
.await
.map_err(|_| ())
}
#[tokio::main]
async fn main() {
let db = PrismaClient::_builder().build().await.unwrap();
@@ -230,7 +246,8 @@ async fn main() {
create_note,
get_notes,
get_latest_notes,
get_note_by_id
get_note_by_id,
create_channel
],
"../src/utils/bindings.ts",
)
@@ -272,7 +289,8 @@ async fn main() {
get_notes,
get_latest_notes,
get_note_by_id,
count_total_notes
count_total_notes,
create_channel
])
.manage(Arc::new(db))
.run(tauri::generate_context!())