added useMetadata and refactor user component
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
-- DropIndex
|
||||
DROP INDEX "Pleb_pubkey_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Pleb_pubkey_key";
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `plebId` to the `Pleb` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_Pleb" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"plebId" TEXT NOT NULL,
|
||||
"pubkey" TEXT NOT NULL,
|
||||
"kind" INTEGER NOT NULL,
|
||||
"metadata" TEXT NOT NULL,
|
||||
"accountId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Pleb_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Pleb" ("accountId", "id", "kind", "metadata", "pubkey") SELECT "accountId", "id", "kind", "metadata", "pubkey" FROM "Pleb";
|
||||
DROP TABLE "Pleb";
|
||||
ALTER TABLE "new_Pleb" RENAME TO "Pleb";
|
||||
CREATE UNIQUE INDEX "Pleb_plebId_key" ON "Pleb"("plebId");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
||||
@@ -27,14 +27,13 @@ model Account {
|
||||
|
||||
model Pleb {
|
||||
id Int @id @default(autoincrement())
|
||||
pubkey String @unique
|
||||
plebId String @unique
|
||||
pubkey String
|
||||
kind Int
|
||||
metadata String
|
||||
|
||||
Account Account @relation(fields: [accountId], references: [id])
|
||||
accountId Int
|
||||
|
||||
@@index([pubkey])
|
||||
}
|
||||
|
||||
model Note {
|
||||
|
||||
@@ -19,7 +19,7 @@ mod db;
|
||||
use db::*;
|
||||
use serde::Deserialize;
|
||||
use specta::{collect_types, Type};
|
||||
use std::sync::Arc;
|
||||
use std::{sync::Arc, vec};
|
||||
use tauri::State;
|
||||
use tauri_specta::ts;
|
||||
|
||||
@@ -44,6 +44,7 @@ struct GetPlebPubkeyData {
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct CreatePlebData {
|
||||
pleb_id: String,
|
||||
pubkey: String,
|
||||
kind: i32,
|
||||
metadata: String,
|
||||
@@ -126,13 +127,21 @@ async fn get_pleb_by_pubkey(
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn create_pleb(db: DbState<'_>, data: CreatePlebData) -> Result<pleb::Data, ()> {
|
||||
let pleb_id = data.pleb_id.clone();
|
||||
let metadata = data.metadata.clone();
|
||||
|
||||
db.pleb()
|
||||
.create(
|
||||
data.pubkey,
|
||||
data.kind,
|
||||
data.metadata,
|
||||
account::id::equals(data.account_id),
|
||||
vec![],
|
||||
.upsert(
|
||||
pleb::pleb_id::equals(pleb_id),
|
||||
pleb::create(
|
||||
data.pleb_id,
|
||||
data.pubkey,
|
||||
data.kind,
|
||||
data.metadata,
|
||||
account::id::equals(data.account_id),
|
||||
vec![],
|
||||
),
|
||||
vec![pleb::metadata::set(metadata)],
|
||||
)
|
||||
.exec()
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user