revert prisma-client-rust, move back to tauri-sql
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
[alias]
|
||||
prisma = "run -p prisma-cli --"
|
||||
1
src-tauri/.env
Normal file
1
src-tauri/.env
Normal file
@@ -0,0 +1 @@
|
||||
DATABASE_URL="/Users/phong/Library/Application Support/com.uselume.xyz"
|
||||
1
src-tauri/.env-main
Normal file
1
src-tauri/.env-main
Normal file
@@ -0,0 +1 @@
|
||||
DATABASE_ENV=<database url>
|
||||
3
src-tauri/.gitignore
vendored
3
src-tauri/.gitignore
vendored
@@ -1,6 +1,3 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# prisma
|
||||
src/db.rs
|
||||
|
||||
2302
src-tauri/Cargo.lock
generated
2302
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,3 @@
|
||||
[workspace]
|
||||
members = ["prisma-cli"]
|
||||
|
||||
[package]
|
||||
name = "lume"
|
||||
version = "0.2.5"
|
||||
@@ -20,11 +17,13 @@ tauri-build = { version = "1.2", features = [] }
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.2", features = ["clipboard-read-text", "clipboard-write-text", "http-request", "os-all", "shell-open", "system-tray", "window-close", "window-start-dragging"] }
|
||||
prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.7", default-features = false, features = ["sqlite", "migrations", "mocking", "specta"] }
|
||||
specta = "1.0.0"
|
||||
tauri-specta = { version = "1.0.0", features = ["typescript"] }
|
||||
tokio = { version = "1.26.0", features = ["macros"] }
|
||||
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
|
||||
sqlx-cli = {version = "0.6.3", default-features = false, features = ["sqlite"] }
|
||||
|
||||
[dependencies.tauri-plugin-sql]
|
||||
git = "https://github.com/tauri-apps/plugins-workspace"
|
||||
branch = "dev"
|
||||
features = ["sqlite"]
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
objc = "0.2.7"
|
||||
|
||||
59
src-tauri/migrations/20230418013219_initial_data.sql
Normal file
59
src-tauri/migrations/20230418013219_initial_data.sql
Normal file
@@ -0,0 +1,59 @@
|
||||
-- Add migration script here
|
||||
-- create accounts table
|
||||
-- is_active (multi-account feature), value:
|
||||
-- 0: false
|
||||
-- 1: true
|
||||
CREATE TABLE
|
||||
accounts (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
pubkey TEXT NOT NULL UNIQUE,
|
||||
privkey TEXT NOT NULL,
|
||||
is_active INTEGER NOT NULL DEFAULT 0,
|
||||
follows TEXT,
|
||||
channels TEXT,
|
||||
chats TEXT,
|
||||
metadata TEXT,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- create plebs table
|
||||
CREATE TABLE
|
||||
plebs (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
pubkey TEXT NOT NULL UNIQUE,
|
||||
metadata TEXT,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- create notes table
|
||||
CREATE TABLE
|
||||
notes (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
event_id TEXT NOT NULL UNIQUE,
|
||||
account_id INTEGER NOT NULL,
|
||||
pubkey TEXT NOT NULL,
|
||||
kind INTEGER NOT NULL DEFAULT 1,
|
||||
tags TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL,
|
||||
parent_id TEXT,
|
||||
FOREIGN KEY (account_id) REFERENCES accounts (id)
|
||||
);
|
||||
|
||||
-- create channels table
|
||||
CREATE TABLE
|
||||
channels (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
event_id TEXT NOT NULL UNIQUE,
|
||||
metadata TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- create settings table
|
||||
CREATE TABLE
|
||||
settings (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
key TEXT NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
@@ -1,9 +0,0 @@
|
||||
[package]
|
||||
name = "prisma-cli"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.7", default-features = false, features = ["sqlite", "migrations", "mocking", "specta"] }
|
||||
@@ -1,3 +0,0 @@
|
||||
fn main() {
|
||||
prisma_client_rust_cli::run();
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "Account" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"pubkey" TEXT NOT NULL,
|
||||
"privkey" TEXT NOT NULL,
|
||||
"active" BOOLEAN NOT NULL DEFAULT false,
|
||||
"metadata" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Follow" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"pubkey" TEXT NOT NULL,
|
||||
"kind" INTEGER NOT NULL,
|
||||
"metadata" TEXT NOT NULL,
|
||||
"accountId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Follow_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Note" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"eventId" TEXT NOT NULL,
|
||||
"pubkey" TEXT NOT NULL,
|
||||
"kind" INTEGER NOT NULL,
|
||||
"tags" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"parent_id" TEXT NOT NULL,
|
||||
"parent_comment_id" TEXT NOT NULL,
|
||||
"createdAt" INTEGER NOT NULL,
|
||||
"accountId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Note_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Message" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"pubkey" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"tags" TEXT NOT NULL,
|
||||
"createdAt" INTEGER NOT NULL,
|
||||
"accountId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Message_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Relay" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"url" TEXT NOT NULL,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Setting" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"key" TEXT NOT NULL,
|
||||
"value" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Account_privkey_key" ON "Account"("privkey");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Account_pubkey_idx" ON "Account"("pubkey");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Note_eventId_key" ON "Note"("eventId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Note_eventId_idx" ON "Note"("eventId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Message_pubkey_idx" ON "Message"("pubkey");
|
||||
@@ -1,11 +0,0 @@
|
||||
-- DropIndex
|
||||
DROP INDEX "Message_pubkey_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Note_eventId_idx";
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Message_pubkey_createdAt_idx" ON "Message"("pubkey", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Note_eventId_createdAt_idx" ON "Note"("eventId", "createdAt");
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
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");
|
||||
@@ -1,5 +0,0 @@
|
||||
-- DropIndex
|
||||
DROP INDEX "Pleb_pubkey_idx";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Pleb_pubkey_key";
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
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;
|
||||
@@ -1,12 +0,0 @@
|
||||
-- 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");
|
||||
@@ -1,12 +0,0 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "Chat" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"pubkey" TEXT NOT NULL,
|
||||
"createdAt" INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Chat_pubkey_key" ON "Chat"("pubkey");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Chat_pubkey_idx" ON "Chat"("pubkey");
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `accountId` to the `Chat` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `accountId` to the `Channel` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_Chat" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"pubkey" TEXT NOT NULL,
|
||||
"createdAt" INTEGER NOT NULL,
|
||||
"accountId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Chat_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Chat" ("createdAt", "id", "pubkey") SELECT "createdAt", "id", "pubkey" FROM "Chat";
|
||||
DROP TABLE "Chat";
|
||||
ALTER TABLE "new_Chat" RENAME TO "Chat";
|
||||
CREATE UNIQUE INDEX "Chat_pubkey_key" ON "Chat"("pubkey");
|
||||
CREATE INDEX "Chat_pubkey_idx" ON "Chat"("pubkey");
|
||||
CREATE TABLE "new_Channel" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"eventId" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"accountId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Channel_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Channel" ("content", "eventId", "id") SELECT "content", "eventId", "id" FROM "Channel";
|
||||
DROP TABLE "Channel";
|
||||
ALTER TABLE "new_Channel" RENAME TO "Channel";
|
||||
CREATE UNIQUE INDEX "Channel_eventId_key" ON "Channel"("eventId");
|
||||
CREATE INDEX "Channel_eventId_idx" ON "Channel"("eventId");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
||||
@@ -1,17 +0,0 @@
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_Channel" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"eventId" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"active" BOOLEAN NOT NULL DEFAULT false,
|
||||
"accountId" INTEGER NOT NULL,
|
||||
CONSTRAINT "Channel_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Channel" ("accountId", "content", "eventId", "id") SELECT "accountId", "content", "eventId", "id" FROM "Channel";
|
||||
DROP TABLE "Channel";
|
||||
ALTER TABLE "new_Channel" RENAME TO "Channel";
|
||||
CREATE UNIQUE INDEX "Channel_eventId_key" ON "Channel"("eventId");
|
||||
CREATE INDEX "Channel_eventId_idx" ON "Channel"("eventId");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
||||
@@ -1,3 +0,0 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "sqlite"
|
||||
@@ -1,104 +0,0 @@
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = "file:../../lume.db"
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "cargo prisma"
|
||||
// The location to generate the client. Is relative to the position of the schema
|
||||
output = "../src/db.rs"
|
||||
module_path = "db"
|
||||
}
|
||||
|
||||
model Account {
|
||||
id Int @id @default(autoincrement())
|
||||
pubkey String @unique
|
||||
privkey String @unique
|
||||
active Boolean @default(false)
|
||||
metadata String
|
||||
|
||||
// related
|
||||
plebs Pleb[]
|
||||
messages Message[]
|
||||
notes Note[]
|
||||
chats Chat[]
|
||||
channels Channel[]
|
||||
|
||||
@@index([pubkey])
|
||||
}
|
||||
|
||||
model Pleb {
|
||||
id Int @id @default(autoincrement())
|
||||
plebId String @unique
|
||||
pubkey String
|
||||
kind Int
|
||||
metadata String
|
||||
|
||||
Account Account @relation(fields: [accountId], references: [id])
|
||||
accountId Int
|
||||
}
|
||||
|
||||
model Note {
|
||||
id Int @id @default(autoincrement())
|
||||
eventId String @unique
|
||||
pubkey String
|
||||
kind Int
|
||||
tags String
|
||||
content String
|
||||
parent_id String
|
||||
parent_comment_id String
|
||||
createdAt Int
|
||||
|
||||
Account Account @relation(fields: [accountId], references: [id])
|
||||
accountId Int
|
||||
|
||||
@@index([eventId, createdAt])
|
||||
}
|
||||
|
||||
model Message {
|
||||
id Int @id @default(autoincrement())
|
||||
pubkey String
|
||||
content String
|
||||
tags String
|
||||
createdAt Int
|
||||
|
||||
Account Account @relation(fields: [accountId], references: [id])
|
||||
accountId Int
|
||||
|
||||
@@index([pubkey, createdAt])
|
||||
}
|
||||
|
||||
model Chat {
|
||||
id Int @id @default(autoincrement())
|
||||
pubkey String @unique
|
||||
createdAt Int
|
||||
|
||||
Account Account @relation(fields: [accountId], references: [id])
|
||||
accountId Int
|
||||
|
||||
@@index([pubkey])
|
||||
}
|
||||
|
||||
model Channel {
|
||||
id Int @id @default(autoincrement())
|
||||
eventId String @unique
|
||||
content String
|
||||
active Boolean @default(false)
|
||||
|
||||
Account Account @relation(fields: [accountId], references: [id])
|
||||
accountId Int
|
||||
|
||||
@@index([eventId])
|
||||
}
|
||||
|
||||
model Relay {
|
||||
id Int @id @default(autoincrement())
|
||||
url String
|
||||
active Boolean @default(true)
|
||||
}
|
||||
|
||||
model Setting {
|
||||
id Int @id @default(autoincrement())
|
||||
key String
|
||||
value String
|
||||
}
|
||||
@@ -8,392 +8,27 @@
|
||||
extern crate objc;
|
||||
|
||||
use tauri::{Manager, WindowEvent};
|
||||
use tauri_plugin_sql::{Migration, MigrationKind};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use window_ext::WindowExt;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod window_ext;
|
||||
|
||||
#[allow(warnings, unused)]
|
||||
mod db;
|
||||
|
||||
use db::*;
|
||||
use prisma_client_rust::Direction;
|
||||
use serde::Deserialize;
|
||||
use specta::{collect_types, Type};
|
||||
use std::{sync::Arc, vec};
|
||||
use tauri::State;
|
||||
use tauri_specta::ts;
|
||||
|
||||
type DbState<'a> = State<'a, Arc<PrismaClient>>;
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct CreateAccountData {
|
||||
pubkey: String,
|
||||
privkey: String,
|
||||
metadata: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetPlebData {
|
||||
account_id: i32,
|
||||
kind: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetPlebPubkeyData {
|
||||
pubkey: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct CreatePlebData {
|
||||
pleb_id: String,
|
||||
pubkey: String,
|
||||
kind: i32,
|
||||
metadata: String,
|
||||
account_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct CreateNoteData {
|
||||
event_id: String,
|
||||
pubkey: String,
|
||||
kind: i32,
|
||||
tags: String,
|
||||
content: String,
|
||||
parent_id: String,
|
||||
parent_comment_id: String,
|
||||
created_at: i32,
|
||||
account_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetNoteByIdData {
|
||||
event_id: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetNoteData {
|
||||
date: i32,
|
||||
limit: i32,
|
||||
offset: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetLatestNoteData {
|
||||
date: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct CreateChatData {
|
||||
pubkey: String,
|
||||
created_at: i32,
|
||||
account_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetChatData {
|
||||
account_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct CreateChannelData {
|
||||
event_id: String,
|
||||
content: String,
|
||||
account_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetChannelData {
|
||||
limit: i32,
|
||||
offset: i32,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct GetActiveChannelData {
|
||||
active: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Type)]
|
||||
struct UpdateChannelData {
|
||||
event_id: String,
|
||||
active: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Serialize)]
|
||||
struct Payload {
|
||||
args: Vec<String>,
|
||||
cwd: String,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_accounts(db: DbState<'_>) -> Result<Vec<account::Data>, ()> {
|
||||
db.account()
|
||||
.find_many(vec![account::active::equals(false)])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn create_account(db: DbState<'_>, data: CreateAccountData) -> Result<account::Data, ()> {
|
||||
db.account()
|
||||
.create(data.pubkey, data.privkey, data.metadata, vec![])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_plebs(db: DbState<'_>, data: GetPlebData) -> Result<Vec<pleb::Data>, ()> {
|
||||
db.pleb()
|
||||
.find_many(vec![
|
||||
pleb::account_id::equals(data.account_id),
|
||||
pleb::kind::equals(data.kind),
|
||||
])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_pleb_by_pubkey(
|
||||
db: DbState<'_>,
|
||||
data: GetPlebPubkeyData,
|
||||
) -> Result<Option<pleb::Data>, ()> {
|
||||
db.pleb()
|
||||
.find_first(vec![pleb::pubkey::equals(data.pubkey)])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[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()
|
||||
.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
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn create_note(db: DbState<'_>, data: CreateNoteData) -> Result<note::Data, ()> {
|
||||
let event_id = data.event_id.clone();
|
||||
let content = data.content.clone();
|
||||
|
||||
db.note()
|
||||
.upsert(
|
||||
note::event_id::equals(event_id),
|
||||
note::create(
|
||||
data.event_id,
|
||||
data.pubkey,
|
||||
data.kind,
|
||||
data.tags,
|
||||
data.content,
|
||||
data.parent_id,
|
||||
data.parent_comment_id,
|
||||
data.created_at,
|
||||
account::id::equals(data.account_id),
|
||||
vec![],
|
||||
),
|
||||
vec![note::content::set(content)],
|
||||
)
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_notes(db: DbState<'_>, data: GetNoteData) -> Result<Vec<note::Data>, ()> {
|
||||
db.note()
|
||||
.find_many(vec![note::created_at::lte(data.date)])
|
||||
.order_by(note::created_at::order(Direction::Desc))
|
||||
.take(data.limit.into())
|
||||
.skip(data.offset.into())
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_latest_notes(db: DbState<'_>, data: GetLatestNoteData) -> Result<Vec<note::Data>, ()> {
|
||||
db.note()
|
||||
.find_many(vec![note::created_at::gt(data.date)])
|
||||
.order_by(note::created_at::order(Direction::Desc))
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_note_by_id(db: DbState<'_>, data: GetNoteByIdData) -> Result<Option<note::Data>, ()> {
|
||||
db.note()
|
||||
.find_unique(note::event_id::equals(data.event_id))
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn count_total_notes(db: DbState<'_>) -> Result<i64, ()> {
|
||||
db.note().count(vec![]).exec().await.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn count_total_channels(db: DbState<'_>) -> Result<i64, ()> {
|
||||
db.channel().count(vec![]).exec().await.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn count_total_chats(db: DbState<'_>) -> Result<i64, ()> {
|
||||
db.chat().count(vec![]).exec().await.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn create_channel(db: DbState<'_>, data: CreateChannelData) -> Result<channel::Data, ()> {
|
||||
db.channel()
|
||||
.upsert(
|
||||
channel::event_id::equals(data.event_id.clone()),
|
||||
channel::create(
|
||||
data.event_id,
|
||||
data.content,
|
||||
account::id::equals(data.account_id),
|
||||
vec![],
|
||||
),
|
||||
vec![],
|
||||
)
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn update_channel(db: DbState<'_>, data: UpdateChannelData) -> Result<channel::Data, ()> {
|
||||
db.channel()
|
||||
.update(
|
||||
channel::event_id::equals(data.event_id), // Unique filter
|
||||
vec![channel::active::set(data.active)], // Vec of updates
|
||||
)
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_channels(db: DbState<'_>, data: GetChannelData) -> Result<Vec<channel::Data>, ()> {
|
||||
db.channel()
|
||||
.find_many(vec![])
|
||||
.take(data.limit.into())
|
||||
.skip(data.offset.into())
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_active_channels(
|
||||
db: DbState<'_>,
|
||||
data: GetActiveChannelData,
|
||||
) -> Result<Vec<channel::Data>, ()> {
|
||||
db.channel()
|
||||
.find_many(vec![channel::active::equals(data.active)])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn create_chat(db: DbState<'_>, data: CreateChatData) -> Result<chat::Data, ()> {
|
||||
db.chat()
|
||||
.upsert(
|
||||
chat::pubkey::equals(data.pubkey.clone()),
|
||||
chat::create(
|
||||
data.pubkey,
|
||||
data.created_at,
|
||||
account::id::equals(data.account_id),
|
||||
vec![],
|
||||
),
|
||||
vec![],
|
||||
)
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
async fn get_chats(db: DbState<'_>, data: GetChatData) -> Result<Vec<chat::Data>, ()> {
|
||||
db.chat()
|
||||
.find_many(vec![chat::account_id::equals(data.account_id)])
|
||||
.exec()
|
||||
.await
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let db = PrismaClient::_builder().build().await.unwrap();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
ts::export(
|
||||
collect_types![
|
||||
get_accounts,
|
||||
create_account,
|
||||
get_plebs,
|
||||
get_pleb_by_pubkey,
|
||||
create_pleb,
|
||||
create_note,
|
||||
get_notes,
|
||||
get_latest_notes,
|
||||
get_note_by_id,
|
||||
create_channel,
|
||||
update_channel,
|
||||
get_channels,
|
||||
get_active_channels,
|
||||
create_chat,
|
||||
get_chats
|
||||
],
|
||||
"../src/utils/bindings.ts",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
db._db_push().await.unwrap();
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
let main_window = app.get_window("main").unwrap();
|
||||
// set inset for traffic lights (macos)
|
||||
#[cfg(target_os = "macos")]
|
||||
main_window.position_traffic_lights(8.0, 20.0);
|
||||
let main_window = app.get_window("main").unwrap();
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
main_window.position_traffic_lights(8.0, 20.0); // set inset for traffic lights (macos)
|
||||
|
||||
Ok(())
|
||||
})
|
||||
@@ -411,27 +46,19 @@ async fn main() {
|
||||
_ => {}
|
||||
}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
get_accounts,
|
||||
create_account,
|
||||
get_plebs,
|
||||
get_pleb_by_pubkey,
|
||||
create_pleb,
|
||||
create_note,
|
||||
get_notes,
|
||||
get_latest_notes,
|
||||
get_note_by_id,
|
||||
count_total_notes,
|
||||
count_total_channels,
|
||||
count_total_chats,
|
||||
create_channel,
|
||||
update_channel,
|
||||
get_channels,
|
||||
get_active_channels,
|
||||
create_chat,
|
||||
get_chats
|
||||
])
|
||||
.manage(Arc::new(db))
|
||||
.plugin(
|
||||
tauri_plugin_sql::Builder::default()
|
||||
.add_migrations(
|
||||
"sqlite:lume.db",
|
||||
vec![Migration {
|
||||
version: 20230418013219,
|
||||
description: "initial data",
|
||||
sql: include_str!("../migrations/20230418013219_initial_data.sql"),
|
||||
kind: MigrationKind::Up,
|
||||
}],
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
|
||||
println!("{}, {argv:?}, {cwd}", app.package_info().name);
|
||||
app
|
||||
|
||||
Reference in New Issue
Block a user