renamed model follow to pleb
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `Follow` table. If the table is not empty, all the data it contains will be lost.
|
||||
- A unique constraint covering the columns `[pubkey]` on the table `Account` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- DropTable
|
||||
PRAGMA foreign_keys=off;
|
||||
DROP TABLE "Follow";
|
||||
PRAGMA foreign_keys=on;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Pleb" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"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
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Pleb_pubkey_key" ON "Pleb"("pubkey");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Pleb_pubkey_idx" ON "Pleb"("pubkey");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Account_pubkey_key" ON "Account"("pubkey");
|
||||
@@ -12,27 +12,29 @@ generator client {
|
||||
|
||||
model Account {
|
||||
id Int @id @default(autoincrement())
|
||||
pubkey String
|
||||
pubkey String @unique
|
||||
privkey String @unique
|
||||
active Boolean @default(false)
|
||||
metadata String
|
||||
|
||||
// related
|
||||
follows Follow[]
|
||||
plebs Pleb[]
|
||||
messages Message[]
|
||||
notes Note[]
|
||||
|
||||
@@index([pubkey])
|
||||
}
|
||||
|
||||
model Follow {
|
||||
model Pleb {
|
||||
id Int @id @default(autoincrement())
|
||||
pubkey String
|
||||
pubkey String @unique
|
||||
kind Int
|
||||
metadata String
|
||||
|
||||
Account Account @relation(fields: [accountId], references: [id])
|
||||
accountId Int
|
||||
|
||||
@@index([pubkey])
|
||||
}
|
||||
|
||||
model Note {
|
||||
|
||||
@@ -33,17 +33,17 @@ struct CreateAccountData {
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetFollowData {
|
||||
struct GetPlebData {
|
||||
account_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetFollowPubkeyData {
|
||||
struct GetPlebPubkeyData {
|
||||
pubkey: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct CreateFollowData {
|
||||
struct CreatePlebData {
|
||||
pubkey: String,
|
||||
kind: i32,
|
||||
metadata: String,
|
||||
@@ -102,9 +102,9 @@ async fn create_account(db: DbState<'_>, data: CreateAccountData) -> Result<acco
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_follows(db: DbState<'_>, data: GetFollowData) -> Result<Vec<follow::Data>, ()> {
|
||||
db.follow()
|
||||
.find_many(vec![follow::account_id::equals(data.account_id)])
|
||||
async fn get_plebs(db: DbState<'_>, data: GetPlebData) -> Result<Vec<pleb::Data>, ()> {
|
||||
db.pleb()
|
||||
.find_many(vec![pleb::account_id::equals(data.account_id)])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
@@ -112,12 +112,12 @@ async fn get_follows(db: DbState<'_>, data: GetFollowData) -> Result<Vec<follow:
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_follow_by_pubkey(
|
||||
async fn get_pleb_by_pubkey(
|
||||
db: DbState<'_>,
|
||||
data: GetFollowPubkeyData,
|
||||
) -> Result<Option<follow::Data>, ()> {
|
||||
db.follow()
|
||||
.find_first(vec![follow::pubkey::equals(data.pubkey)])
|
||||
data: GetPlebPubkeyData,
|
||||
) -> Result<Option<pleb::Data>, ()> {
|
||||
db.pleb()
|
||||
.find_first(vec![pleb::pubkey::equals(data.pubkey)])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
@@ -125,8 +125,8 @@ async fn get_follow_by_pubkey(
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn create_follow(db: DbState<'_>, data: CreateFollowData) -> Result<follow::Data, ()> {
|
||||
db.follow()
|
||||
async fn create_pleb(db: DbState<'_>, data: CreatePlebData) -> Result<pleb::Data, ()> {
|
||||
db.pleb()
|
||||
.create(
|
||||
data.pubkey,
|
||||
data.kind,
|
||||
@@ -215,9 +215,9 @@ async fn main() {
|
||||
collect_types![
|
||||
get_accounts,
|
||||
create_account,
|
||||
get_follows,
|
||||
get_follow_by_pubkey,
|
||||
create_follow,
|
||||
get_plebs,
|
||||
get_pleb_by_pubkey,
|
||||
create_pleb,
|
||||
create_note,
|
||||
get_notes,
|
||||
get_latest_notes,
|
||||
@@ -256,9 +256,9 @@ async fn main() {
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
get_accounts,
|
||||
create_account,
|
||||
get_follows,
|
||||
get_follow_by_pubkey,
|
||||
create_follow,
|
||||
get_plebs,
|
||||
get_pleb_by_pubkey,
|
||||
create_pleb,
|
||||
create_note,
|
||||
get_notes,
|
||||
get_latest_notes,
|
||||
|
||||
Reference in New Issue
Block a user