diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock index af3fd0917..d7a550d47 100644 Binary files a/apps/desktop/src-tauri/Cargo.lock and b/apps/desktop/src-tauri/Cargo.lock differ diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 2fe95eaaf..86a2f7563 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -18,7 +18,7 @@ swift-rs = "0.2.3" tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next", features = ["api-all"] } swift-rs = "0.2.3" sdcorelib = { path = "../../../packages/core" } -tauri-plugin-shadows = { git = "https://github.com/tauri-apps/tauri-plugin-shadows", features = ["tauri-impl"] } +# tauri-plugin-shadows = { git = "https://github.com/tauri-apps/tauri-plugin-shadows", features = ["tauri-impl"] } # Universal Dependencies anyhow = "1.0.44" @@ -37,7 +37,7 @@ sha256 = "1.0.2" once_cell = "1.8.0" int-enum = "0.4.0" async-std = "1.10.0" -tokio = {version = "1.15.0", features= ["sync"] } +tokio = { version = "1.17.0", features = ["sync"] } [features] default = [ "custom-protocol" ] diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 781f121b5..246cff8f7 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -1,17 +1,18 @@ use sdcorelib; use tauri::api::path; use tauri::Manager; -use tauri_plugin_shadows::Shadows; +// use tauri_plugin_shadows::Shadows; mod commands; mod menu; -fn main() { +#[tokio::main] +async fn main() { + let data_dir = path::data_dir().unwrap_or(std::path::PathBuf::from("./")); + let mut core_receiver = sdcorelib::configure(data_dir).await; + tauri::Builder::default() .setup(|app| { - let data_dir = path::data_dir().unwrap_or(std::path::PathBuf::from("./")); - let mut core_receiver = sdcorelib::configure(data_dir); - let app = app.handle(); tauri::async_runtime::spawn(async move { diff --git a/packages/core/.gitignore b/packages/core/.gitignore index ea8c4bf7f..8742b31ae 100644 --- a/packages/core/.gitignore +++ b/packages/core/.gitignore @@ -1 +1,2 @@ /target +*.db* \ No newline at end of file diff --git a/packages/core/Cargo.lock b/packages/core/Cargo.lock index 57f63f251..cc01dfb90 100644 Binary files a/packages/core/Cargo.lock and b/packages/core/Cargo.lock differ diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index 40ee5ad24..37fc51e15 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -33,6 +33,7 @@ rusqlite = "0.25.3" refinery = { version = "0.6.0", features = ["rusqlite"] } sqlx = { version = "0.5.7", features = ["sqlite"] } sea-orm = { version = "^0.6.0", features = [ "sqlx-sqlite", "runtime-async-std-rustls", "macros", "debug-print"], default-features = false } +prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust.git", branch = "master" } walkdir = "^2.3.2" bytesize = "1.1.0" env_logger = "0.9.0" @@ -43,4 +44,5 @@ uuid = "0.8" thumbnailer = "0.4.0" mime = "0.3.16" -tokio = {version = "1.15.0", features=["sync"]} \ No newline at end of file +tokio = { version = "1.17.0", features = ["sync", "rt"] } +include_dir = {version = "0.7.2", features = ["glob"]} diff --git a/packages/core/prisma/migrations/20220303102833_/migration.sql b/packages/core/prisma/migrations/20220303102833_/migration.sql new file mode 100644 index 000000000..ffa7a9dd5 --- /dev/null +++ b/packages/core/prisma/migrations/20220303102833_/migration.sql @@ -0,0 +1,117 @@ +-- CreateTable +CREATE TABLE "libraries" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "uuid" TEXT NOT NULL, + "name" TEXT NOT NULL, + "remote_id" TEXT, + "is_primary" BOOLEAN NOT NULL DEFAULT true, + "encryption" INTEGER NOT NULL DEFAULT 0, + "total_file_count" INTEGER NOT NULL DEFAULT 0, + "total_bytes_used" TEXT NOT NULL DEFAULT '0', + "total_byte_capacity" TEXT NOT NULL DEFAULT '0', + "total_unique_bytes" TEXT NOT NULL DEFAULT '0', + "date_created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "timezone" TEXT +); + +-- CreateTable +CREATE TABLE "clients" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "uuid" TEXT NOT NULL, + "name" TEXT NOT NULL, + "platform" INTEGER NOT NULL DEFAULT 0, + "version" TEXT, + "online" BOOLEAN DEFAULT true, + "last_seen" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "timezone" TEXT, + "date_created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- CreateTable +CREATE TABLE "locations" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT, + "path" TEXT, + "total_capacity" INTEGER, + "available_capacity" INTEGER, + "is_removable" BOOLEAN NOT NULL DEFAULT true, + "is_ejectable" BOOLEAN NOT NULL DEFAULT true, + "is_root_filesystem" BOOLEAN NOT NULL DEFAULT true, + "is_online" BOOLEAN NOT NULL DEFAULT true, + "date_created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- CreateTable +CREATE TABLE "files" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "is_dir" BOOLEAN NOT NULL DEFAULT false, + "location_id" INTEGER NOT NULL, + "materialized_path" TEXT NOT NULL, + "name" TEXT NOT NULL, + "extension" TEXT, + "path_integrity_hash" TEXT NOT NULL, + "quick_integrity_hash" TEXT, + "full_integrity_hash" TEXT, + "size_in_bytes" TEXT NOT NULL, + "encryption" INTEGER NOT NULL DEFAULT 0, + "date_created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "date_modified" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "date_indexed" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "ipfs_id" TEXT, + "parent_id" INTEGER, + CONSTRAINT "files_location_id_fkey" FOREIGN KEY ("location_id") REFERENCES "locations" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT "files_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "files" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "tags" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT, + "encryption" INTEGER DEFAULT 0, + "total_files" INTEGER DEFAULT 0, + "redundancy_goal" INTEGER DEFAULT 1, + "date_created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "date_modified" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- CreateTable +CREATE TABLE "tags_on_files" ( + "date_created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "tag_id" INTEGER NOT NULL, + "file_id" INTEGER NOT NULL, + + PRIMARY KEY ("tag_id", "file_id"), + CONSTRAINT "tags_on_files_file_id_fkey" FOREIGN KEY ("file_id") REFERENCES "files" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT "tags_on_files_tag_id_fkey" FOREIGN KEY ("tag_id") REFERENCES "tags" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION +); + +-- CreateTable +CREATE TABLE "jobs" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "client_id" INTEGER NOT NULL, + "action" INTEGER NOT NULL, + "status" INTEGER NOT NULL DEFAULT 0, + "percentage_complete" INTEGER NOT NULL DEFAULT 0, + "task_count" INTEGER NOT NULL DEFAULT 1, + "completed_task_count" INTEGER NOT NULL DEFAULT 0, + "date_created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "date_modified" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT "jobs_client_id_fkey" FOREIGN KEY ("client_id") REFERENCES "clients" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION +); + +-- CreateTable +CREATE TABLE "spaces" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT NOT NULL, + "encryption" INTEGER DEFAULT 0, + "date_created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "date_modified" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "libraryId" INTEGER, + CONSTRAINT "spaces_libraryId_fkey" FOREIGN KEY ("libraryId") REFERENCES "libraries" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "clients_uuid_key" ON "clients"("uuid"); + +-- CreateIndex +CREATE UNIQUE INDEX "files_path_integrity_hash_key" ON "files"("path_integrity_hash"); diff --git a/packages/core/prisma/migrations/migration_lock.toml b/packages/core/prisma/migrations/migration_lock.toml new file mode 100644 index 000000000..e5e5c4705 --- /dev/null +++ b/packages/core/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file diff --git a/packages/core/prisma/migrations/migration_table/migration.sql b/packages/core/prisma/migrations/migration_table/migration.sql new file mode 100644 index 000000000..b24c95e1e --- /dev/null +++ b/packages/core/prisma/migrations/migration_table/migration.sql @@ -0,0 +1,10 @@ +-- CreateTable +CREATE TABLE "_migrations" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT NOT NULL, + "checksum" TEXT NOT NULL, + "steps_applied" INTEGER NOT NULL DEFAULT 0, + "applied_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); +-- CreateIndex +CREATE UNIQUE INDEX "_migrations_checksum_key" ON "_migrations"("checksum"); \ No newline at end of file diff --git a/packages/core/prisma/schema.prisma b/packages/core/prisma/schema.prisma index 049c4086e..634d034ec 100644 --- a/packages/core/prisma/schema.prisma +++ b/packages/core/prisma/schema.prisma @@ -1,6 +1,21 @@ datasource db { provider = "sqlite" - url = "file:/Users/jamie/Library/Application Support/spacedrive/library.db" + url = "file:dev.db" +} + +generator client { + provider = "prisma-client-rust" + output = "../src/prisma.rs" +} + +model Migration { + id Int @id @default(autoincrement()) + name String + checksum String @unique + steps_applied Int @default(0) + applied_at DateTime @default(now()) + + @@map("_migrations") } model Library { @@ -23,7 +38,7 @@ model Library { model Client { id Int @id @default(autoincrement()) - uuid String @unique() + uuid String @unique name String platform Int @default(0) version String? @@ -53,53 +68,57 @@ model Location { } model File { - id Int @id @default(autoincrement()) - is_dir Boolean @default(false) - location_id Int - materialized_path String - name String - extension String? - meta_integrity_hash String @unique() - sampled_byte_integrity_hash String? - byte_integrity_hash String? - size_in_bytes String - encryption Int @default(0) - ipfs_id String? - date_created DateTime @default(now()) - date_modified DateTime @default(now()) - date_indexed DateTime @default(now()) - directory_id Int? - parent_id Int? - locations Location? @relation(fields: [location_id], references: [id], onDelete: NoAction, onUpdate: NoAction) - files File? @relation("file_to_file_parent_id", fields: [parent_id], references: [id], onDelete: NoAction, onUpdate: NoAction) - other_files File[] @relation("file_to_file_parent_id") - tags_files TagFile[] @ignore + id Int @id @default(autoincrement()) + is_dir Boolean @default(false) + location_id Int + materialized_path String + name String + extension String? + path_integrity_hash String @unique // combo of location_id, materialized_path, name, extension + quick_integrity_hash String? // 100 * 100 byte samples + full_integrity_hash String? // full byte to byte hash + size_in_bytes String + encryption Int @default(0) + date_created DateTime @default(now()) + date_modified DateTime @default(now()) + date_indexed DateTime @default(now()) + ipfs_id String? + location Location? @relation(fields: [location_id], references: [id], onDelete: NoAction, onUpdate: NoAction) + + parent File? @relation("directory_files", fields: [parent_id], references: [id]) + parent_id Int? + children File[] @relation("directory_files") + + file_tags TagOnFile[] @@map("files") } model Tag { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) name String? - encryption Int? @default(0) - total_files Int? @default(0) - redundancy_goal Int? @default(1) - date_created DateTime @default(now()) - date_modified DateTime @default(now()) - tags_files TagFile[] @ignore + encryption Int? @default(0) + total_files Int? @default(0) + redundancy_goal Int? @default(1) + date_created DateTime @default(now()) + date_modified DateTime @default(now()) + + tag_files TagOnFile[] @@map("tags") } -model TagFile { - tag_id Int - file_id Int +model TagOnFile { date_created DateTime @default(now()) - file File @relation(fields: [file_id], references: [id], onDelete: NoAction, onUpdate: NoAction) - tag Tag @relation(fields: [tag_id], references: [id], onDelete: NoAction, onUpdate: NoAction) + + tag_id Int + tag Tag @relation(fields: [tag_id], references: [id], onDelete: NoAction, onUpdate: NoAction) + + file_id Int + file File @relation(fields: [file_id], references: [id], onDelete: NoAction, onUpdate: NoAction) @@id([tag_id, file_id]) - @@map("tags_files") + @@map("tags_on_files") } model Job { diff --git a/packages/core/src/db/connection.rs b/packages/core/src/db/connection.rs index 394f4cb13..5dfef1625 100644 --- a/packages/core/src/db/connection.rs +++ b/packages/core/src/db/connection.rs @@ -1,8 +1,14 @@ +use crate::file::checksum::sha256_digest; +use crate::prisma::{Migration, PrismaClient}; use crate::state::{self}; use anyhow::Result; +use data_encoding::HEXLOWER; +use include_dir::{include_dir, Dir}; use once_cell::sync::OnceCell; -use rusqlite::Connection; use sea_orm::{Database, DatabaseConnection}; +use sha256::digest; +use std::ffi::OsStr; +use std::io::{BufReader, Read}; pub static DB: OnceCell = OnceCell::new(); @@ -23,6 +29,10 @@ pub async fn db() -> Result<&'static DatabaseConnection, String> { .unwrap(); DB.set(db).unwrap_or_default(); + // TODO: Error handling when brendan adds it to prisma-client-rust + + // let client = PrismaClient::new_with_url(&format!("file:{}", &path)).await; + // DB.set(client).unwrap_or_default(); Ok(DB.get().unwrap()) } else { @@ -30,21 +40,136 @@ pub async fn db() -> Result<&'static DatabaseConnection, String> { } } -pub async fn init(db_url: &str) -> Result<(), sqlx::Error> { - // establish connection, this is only used to create the db if missing - // replace in future - let mut connection = Connection::open(&db_url).unwrap(); +const INIT_MIGRATION: &str = include_str!("../../prisma/migrations/migration_table/migration.sql"); +static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/prisma/migrations"); - // migrate db - mod embedded_primary { - use refinery::embed_migrations; - embed_migrations!("src/db/migrations"); +pub async fn init(db_url: &str) -> Result<(), sqlx::Error> { + let client = PrismaClient::new_with_url(&format!("file:{}", &db_url)).await; + + match client + ._query_raw::( + "SELECT name FROM sqlite_master WHERE type='table' AND name='_migrations'", + ) + .await + { + Ok(data) => { + if data.len() == 0 { + println!("Migration table does not exist"); + + client._execute_raw(INIT_MIGRATION).await; + + let value: Vec = client + ._query_raw( + "SELECT name FROM sqlite_master WHERE type='table' AND name='_migrations'", + ) + .await + .unwrap(); + + println!("Migration table created: {:?}", value); + } else { + println!("Migration table exists: {:?}", data); + } + + let mut migration_subdirs = MIGRATIONS_DIR + .dirs() + .filter(|subdir| { + subdir + .path() + .file_name() + .map(|name| name != OsStr::new("migration_table")) + .unwrap_or(false) + }) + .collect::>(); + + migration_subdirs.sort_by(|a, b| { + let a_name = a.path().file_name().unwrap().to_str().unwrap(); + let b_name = b.path().file_name().unwrap().to_str().unwrap(); + + let a_time = a_name[..15].parse::().unwrap(); + let b_time = b_name[..15].parse::().unwrap(); + + a_time.cmp(&b_time) + }); + + for subdir in migration_subdirs { + println!("{:?}", subdir.path()); + let migration_file = subdir + .get_file(subdir.path().join("./migration.sql")) + .unwrap(); + let migration_sql = migration_file.contents_utf8().unwrap(); + + let digest = sha256_digest(BufReader::new(migration_file.contents()))?; + // create a lowercase hash from + let checksum = HEXLOWER.encode(digest.as_ref()); + let name = subdir.path().file_name().unwrap().to_str().unwrap(); + + // get existing migration by checksum, if it doesn't exist run the migration + let existing_migration = client + .migration() + .find_unique(Migration::checksum().equals(checksum.clone())) + .exec() + .await; + + if existing_migration.is_none() { + println!("Running migration: {}", name); + + let steps = migration_sql.split(";").collect::>(); + let steps = &steps[0..steps.len() - 1]; + + client + .migration() + .create_one( + Migration::name().set(name.to_string()), + Migration::checksum().set(checksum.clone()), + vec![], + ) + .exec() + .await; + + for (i, step) in steps.iter().enumerate() { + match client._execute_raw(&format!("{};", step)).await { + Ok(_) => { + println!("Step {} ran successfully", i); + client + .migration() + .find_unique(Migration::checksum().equals(checksum.clone())) + .update(vec![Migration::steps_applied().set(i as i64 + 1)]) + .exec() + .await; + } + Err(e) => { + println!("Error running migration: {}", name); + println!("{}", e); + break; + } + } + } + + println!("Migration {} recorded successfully", name); + } else { + println!("Migration {} already exists", name); + } + } + } + Err(err) => { + panic!("Failed to check migration table existence: {:?}", err); + } } - embedded_primary::migrations::runner() - .run(&mut connection) - .unwrap(); + // // establish connection, this is only used to create the db if missing + // // replace in future + // let mut connection = Connection::open(&db_url).unwrap(); - connection.close().unwrap(); + // // migrate db + // mod embedded_primary { + // use refinery::embed_migrations; + // embed_migrations!("src/db/migrations"); + // }= + + // embedded_primary::migrations::runner() + // .run(&mut connection) + // .unwrap(); + + // connection.close().unwrap(); Ok(()) } diff --git a/packages/core/src/file/checksum.rs b/packages/core/src/file/checksum.rs index 6a9427804..dfab4346d 100644 --- a/packages/core/src/file/checksum.rs +++ b/packages/core/src/file/checksum.rs @@ -5,7 +5,7 @@ use std::io; use std::io::{BufReader, Read}; use std::time::Instant; -fn sha256_digest(mut reader: R) -> io::Result { +pub fn sha256_digest(mut reader: R) -> io::Result { let mut context = Context::new(&SHA256); let mut buffer = [0; 1024]; loop { diff --git a/packages/core/src/lib.rs b/packages/core/src/lib.rs index b41c7da7d..0fc8f2018 100644 --- a/packages/core/src/lib.rs +++ b/packages/core/src/lib.rs @@ -4,7 +4,9 @@ pub mod file; pub mod library; pub mod native; pub mod state; +pub mod tx; // pub mod p2p; +pub mod prisma; pub mod util; use futures::executor::block_on; @@ -59,7 +61,7 @@ pub async fn core_send_stream>(stream: T) { .await; } -pub fn configure(mut data_dir: std::path::PathBuf) -> mpsc::Receiver { +pub async fn configure(mut data_dir: std::path::PathBuf) -> mpsc::Receiver { data_dir = data_dir.join("spacedrive"); let (event_sender, event_receiver) = mpsc::channel(100); @@ -81,42 +83,41 @@ pub fn configure(mut data_dir: std::path::PathBuf) -> mpsc::Receiver { + println!("Created new library: {:?}", library); + } + Err(e) => { + println!("Error creating library: {:?}", e); + } + } + } else { + for library in client_config.libraries.iter() { + // init database for library + match library::loader::load(&library.library_path, &library.library_id).await { Ok(library) => { - println!("Created new library: {:?}", library); + println!("Loaded library: {:?}", library); } Err(e) => { - println!("Error creating library: {:?}", e); - } - } - } else { - for library in client_config.libraries.iter() { - // init database for library - match library::loader::load(&library.library_path, &library.library_id).await { - Ok(library) => { - println!("Loaded library: {:?}", library); - } - Err(e) => { - println!("Error loading library: {:?}", e); - } + println!("Error loading library: {:?}", e); } } } + } - // init client - match library::client::create().await { - Ok(_) => {} - Err(e) => { - println!("Error initializing client: {:?}", e); - } - }; - // activate p2p listeners - // p2p::listener::listen(None); - }); - + // init client + match library::client::create().await { + Ok(_) => {} + Err(e) => { + println!("Error initializing client: {:?}", e); + } + }; + // activate p2p listeners + // p2p::listener::listen(None); + println!("Spacedrive online"); // env_logger::builder() diff --git a/packages/core/src/prisma.rs b/packages/core/src/prisma.rs new file mode 100644 index 000000000..c28ba6437 --- /dev/null +++ b/packages/core/src/prisma.rs @@ -0,0 +1,10392 @@ +// Code generated by Prisma Client Rust. DO NOT EDIT. + +use prisma_client_rust::chrono; +use prisma_client_rust::datamodel::parse_configuration; +use prisma_client_rust::prisma_models::InternalDataModelBuilder; +use prisma_client_rust::query::*; +use prisma_client_rust::query_core::{ + executor, schema_builder, BuildMode, CoreError, QueryExecutor, QuerySchema, +}; +use prisma_client_rust::serde_json; +use prisma_client_rust::DeleteResult; +use serde::{Deserialize, Serialize}; +use std::path::Path; +use std::sync::Arc; +pub struct PrismaClient { + executor: Box, + query_schema: Arc, +} +impl PrismaClient { + pub async fn new() -> Self { + let datamodel_str = "datasource db {\n provider = \"sqlite\"\n url = \"file:dev.db\"\n}\n\ngenerator client {\n provider = \"prisma-client-rust\"\n output = \"../src/prisma.rs\"\n}\n\nmodel Migration {\n id Int @id @default(autoincrement())\n name String\n checksum String @unique\n steps_applied Int @default(0)\n applied_at DateTime @default(now())\n\n @@map(\"_migrations\")\n}\n\nmodel Library {\n id Int @id @default(autoincrement())\n uuid String\n name String\n remote_id String?\n is_primary Boolean @default(true)\n encryption Int @default(0)\n total_file_count Int @default(0)\n total_bytes_used String @default(\"0\")\n total_byte_capacity String @default(\"0\")\n total_unique_bytes String @default(\"0\")\n date_created DateTime @default(now())\n timezone String?\n spaces Space[]\n\n @@map(\"libraries\")\n}\n\nmodel Client {\n id Int @id @default(autoincrement())\n uuid String @unique\n name String\n platform Int @default(0)\n version String?\n online Boolean? @default(true)\n last_seen DateTime @default(now())\n timezone String?\n date_created DateTime @default(now())\n jobs Job[]\n\n @@map(\"clients\")\n}\n\nmodel Location {\n id Int @id @default(autoincrement())\n name String?\n path String?\n total_capacity Int?\n available_capacity Int?\n is_removable Boolean @default(true)\n is_ejectable Boolean @default(true)\n is_root_filesystem Boolean @default(true)\n is_online Boolean @default(true)\n date_created DateTime @default(now())\n files File[]\n\n @@map(\"locations\")\n}\n\nmodel File {\n id Int @id @default(autoincrement())\n is_dir Boolean @default(false)\n location_id Int\n materialized_path String\n name String\n extension String?\n path_integrity_hash String @unique // combo of location_id, materialized_path, name, extension\n quick_integrity_hash String? // 100 * 100 byte samples\n full_integrity_hash String? // full byte to byte hash\n size_in_bytes String\n encryption Int @default(0)\n date_created DateTime @default(now())\n date_modified DateTime @default(now())\n date_indexed DateTime @default(now())\n ipfs_id String?\n\n location Location? @relation(fields: [location_id], references: [id], onDelete: NoAction, onUpdate: NoAction)\n\n parent File? @relation(\"directory_files\", fields: [parent_id], references: [id])\n parent_id Int?\n children File[] @relation(\"directory_files\")\n\n file_tags TagOnFile[]\n @@map(\"files\")\n}\n\nmodel Tag {\n id Int @id @default(autoincrement())\n name String?\n encryption Int? @default(0)\n total_files Int? @default(0)\n redundancy_goal Int? @default(1)\n date_created DateTime @default(now())\n date_modified DateTime @default(now())\n\n tag_files TagOnFile[]\n\n @@map(\"tags\")\n}\n\nmodel TagOnFile {\n date_created DateTime @default(now())\n\n tag_id Int\n tag Tag @relation(fields: [tag_id], references: [id], onDelete: NoAction, onUpdate: NoAction)\n\n file_id Int\n file File @relation(fields: [file_id], references: [id], onDelete: NoAction, onUpdate: NoAction)\n\n @@id([tag_id, file_id])\n @@map(\"tags_on_files\")\n}\n\nmodel Job {\n id Int @id @default(autoincrement())\n client_id Int\n action Int\n status Int @default(0)\n percentage_complete Int @default(0)\n task_count Int @default(1)\n completed_task_count Int @default(0)\n date_created DateTime @default(now())\n date_modified DateTime @default(now())\n clients Client @relation(fields: [client_id], references: [id], onDelete: NoAction, onUpdate: NoAction)\n\n @@map(\"jobs\")\n}\n\nmodel Space {\n id Int @id @default(autoincrement())\n name String\n encryption Int? @default(0)\n date_created DateTime @default(now())\n date_modified DateTime @default(now())\n\n Library Library? @relation(fields: [libraryId], references: [id])\n libraryId Int?\n @@map(\"spaces\")\n}\n" ; + let config = parse_configuration(datamodel_str).unwrap().subject; + let source = config + .datasources + .first() + .expect("Pleasy supply a datasource in your schema.prisma file"); + let url = if let Some(url) = source.load_shadow_database_url().unwrap() { + url + } else { + source.load_url(|key| std::env::var(key).ok()).unwrap() + }; + let url = if url.starts_with("file:") { + let path = url.split(":").nth(1).unwrap(); + if Path::new("./schema.prisma").exists() { + url + } else if Path::new("./prisma/schema.prisma").exists() { + format!("file:./prisma/{}", path) + } else { + url + } + } else { + url + }; + let (db_name, executor) = executor::load(&source, &[], &url).await.unwrap(); + let internal_model = InternalDataModelBuilder::new(&datamodel_str).build(db_name); + let query_schema = Arc::new(schema_builder::build( + internal_model, + BuildMode::Modern, + true, + source.capabilities(), + vec![], + source.referential_integrity(), + )); + executor.primary_connector().get_connection().await.unwrap(); + Self { + executor, + query_schema, + } + } + pub async fn new_with_url(url: &str) -> Self { + let datamodel_str = "datasource db {\n provider = \"sqlite\"\n url = \"file:dev.db\"\n}\n\ngenerator client {\n provider = \"prisma-client-rust\"\n output = \"../src/prisma.rs\"\n}\n\nmodel Migration {\n id Int @id @default(autoincrement())\n name String\n checksum String @unique\n steps_applied Int @default(0)\n applied_at DateTime @default(now())\n\n @@map(\"_migrations\")\n}\n\nmodel Library {\n id Int @id @default(autoincrement())\n uuid String\n name String\n remote_id String?\n is_primary Boolean @default(true)\n encryption Int @default(0)\n total_file_count Int @default(0)\n total_bytes_used String @default(\"0\")\n total_byte_capacity String @default(\"0\")\n total_unique_bytes String @default(\"0\")\n date_created DateTime @default(now())\n timezone String?\n spaces Space[]\n\n @@map(\"libraries\")\n}\n\nmodel Client {\n id Int @id @default(autoincrement())\n uuid String @unique\n name String\n platform Int @default(0)\n version String?\n online Boolean? @default(true)\n last_seen DateTime @default(now())\n timezone String?\n date_created DateTime @default(now())\n jobs Job[]\n\n @@map(\"clients\")\n}\n\nmodel Location {\n id Int @id @default(autoincrement())\n name String?\n path String?\n total_capacity Int?\n available_capacity Int?\n is_removable Boolean @default(true)\n is_ejectable Boolean @default(true)\n is_root_filesystem Boolean @default(true)\n is_online Boolean @default(true)\n date_created DateTime @default(now())\n files File[]\n\n @@map(\"locations\")\n}\n\nmodel File {\n id Int @id @default(autoincrement())\n is_dir Boolean @default(false)\n location_id Int\n materialized_path String\n name String\n extension String?\n path_integrity_hash String @unique // combo of location_id, materialized_path, name, extension\n quick_integrity_hash String? // 100 * 100 byte samples\n full_integrity_hash String? // full byte to byte hash\n size_in_bytes String\n encryption Int @default(0)\n date_created DateTime @default(now())\n date_modified DateTime @default(now())\n date_indexed DateTime @default(now())\n ipfs_id String?\n\n location Location? @relation(fields: [location_id], references: [id], onDelete: NoAction, onUpdate: NoAction)\n\n parent File? @relation(\"directory_files\", fields: [parent_id], references: [id])\n parent_id Int?\n children File[] @relation(\"directory_files\")\n\n file_tags TagOnFile[]\n @@map(\"files\")\n}\n\nmodel Tag {\n id Int @id @default(autoincrement())\n name String?\n encryption Int? @default(0)\n total_files Int? @default(0)\n redundancy_goal Int? @default(1)\n date_created DateTime @default(now())\n date_modified DateTime @default(now())\n\n tag_files TagOnFile[]\n\n @@map(\"tags\")\n}\n\nmodel TagOnFile {\n date_created DateTime @default(now())\n\n tag_id Int\n tag Tag @relation(fields: [tag_id], references: [id], onDelete: NoAction, onUpdate: NoAction)\n\n file_id Int\n file File @relation(fields: [file_id], references: [id], onDelete: NoAction, onUpdate: NoAction)\n\n @@id([tag_id, file_id])\n @@map(\"tags_on_files\")\n}\n\nmodel Job {\n id Int @id @default(autoincrement())\n client_id Int\n action Int\n status Int @default(0)\n percentage_complete Int @default(0)\n task_count Int @default(1)\n completed_task_count Int @default(0)\n date_created DateTime @default(now())\n date_modified DateTime @default(now())\n clients Client @relation(fields: [client_id], references: [id], onDelete: NoAction, onUpdate: NoAction)\n\n @@map(\"jobs\")\n}\n\nmodel Space {\n id Int @id @default(autoincrement())\n name String\n encryption Int? @default(0)\n date_created DateTime @default(now())\n date_modified DateTime @default(now())\n\n Library Library? @relation(fields: [libraryId], references: [id])\n libraryId Int?\n @@map(\"spaces\")\n}\n" ; + let config = parse_configuration(datamodel_str).unwrap().subject; + let source = config + .datasources + .first() + .expect("Pleasy supply a datasource in your schema.prisma file"); + let (db_name, executor) = executor::load(&source, &[], &url).await.unwrap(); + let internal_model = InternalDataModelBuilder::new(&datamodel_str).build(db_name); + let query_schema = Arc::new(schema_builder::build( + internal_model, + BuildMode::Modern, + true, + source.capabilities(), + vec![], + source.referential_integrity(), + )); + executor.primary_connector().get_connection().await.unwrap(); + Self { + executor, + query_schema, + } + } + pub async fn _query_raw( + &self, + query: &str, + ) -> Result, CoreError> { + let query = Query { + ctx: QueryContext::new(&self.executor, self.query_schema.clone()), + operation: "mutation".into(), + method: "queryRaw".into(), + inputs: vec![ + Input { + name: "query".into(), + value: Some(query.into()), + ..Default::default() + }, + Input { + name: "parameters".into(), + value: Some("[]".into()), + ..Default::default() + }, + ], + name: "".into(), + model: "".into(), + outputs: vec![], + }; + query.perform().await + } + pub async fn _execute_raw(&self, query: &str) -> Result { + let query = Query { + ctx: QueryContext::new(&self.executor, self.query_schema.clone()), + operation: "mutation".into(), + method: "executeRaw".into(), + inputs: vec![ + Input { + name: "query".into(), + value: Some(query.into()), + ..Default::default() + }, + Input { + name: "parameters".into(), + value: Some("[]".into()), + ..Default::default() + }, + ], + name: "".into(), + model: "".into(), + outputs: vec![], + }; + query.perform().await.map(|result: i64| result) + } + pub fn migration(&self) -> MigrationActions { + MigrationActions { client: &self } + } + pub fn library(&self) -> LibraryActions { + LibraryActions { client: &self } + } + pub fn client(&self) -> ClientActions { + ClientActions { client: &self } + } + pub fn location(&self) -> LocationActions { + LocationActions { client: &self } + } + pub fn file(&self) -> FileActions { + FileActions { client: &self } + } + pub fn tag(&self) -> TagActions { + TagActions { client: &self } + } + pub fn tag_on_file(&self) -> TagOnFileActions { + TagOnFileActions { client: &self } + } + pub fn job(&self) -> JobActions { + JobActions { client: &self } + } + pub fn space(&self) -> SpaceActions { + SpaceActions { client: &self } + } +} +fn migration_outputs() -> Vec { + vec![ + Output::new("id"), + Output::new("name"), + Output::new("checksum"), + Output::new("steps_applied"), + Output::new("applied_at"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MigrationData { + #[serde(rename = "id")] + pub id: i64, + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "checksum")] + pub checksum: String, + #[serde(rename = "steps_applied")] + pub steps_applied: i64, + #[serde(rename = "applied_at")] + pub applied_at: chrono::DateTime, +} +impl MigrationData {} +pub struct Migration; +impl Migration { + pub fn id() -> MigrationIdField { + MigrationIdField {} + } + pub fn name() -> MigrationNameField { + MigrationNameField {} + } + pub fn checksum() -> MigrationChecksumField { + MigrationChecksumField {} + } + pub fn steps_applied() -> MigrationStepsAppliedField { + MigrationStepsAppliedField {} + } + pub fn applied_at() -> MigrationAppliedAtField { + MigrationAppliedAtField {} + } + pub fn not(params: Vec) -> MigrationWhereParam { + MigrationWhereParam::Not(params) + } + pub fn or(params: Vec) -> MigrationWhereParam { + MigrationWhereParam::Or(params) + } + pub fn and(params: Vec) -> MigrationWhereParam { + MigrationWhereParam::And(params) + } +} +pub struct MigrationIdField {} +pub struct MigrationSetId(i64); +impl From for MigrationSetParam { + fn from(value: MigrationSetId) -> Self { + Self::Id(value.0) + } +} +impl MigrationIdField { + pub fn lt(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::IdLT(value) + } + pub fn gt(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::IdGT(value) + } + pub fn lte(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::IdLTE(value) + } + pub fn gte(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::IdGTE(value) + } + pub fn equals(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::IdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + MigrationSetId(value).into() + } +} +pub struct MigrationNameField {} +pub struct MigrationSetName(String); +impl From for MigrationSetParam { + fn from(value: MigrationSetName) -> Self { + Self::Name(value.0) + } +} +impl MigrationNameField { + pub fn contains(&self, value: String) -> MigrationWhereParam { + MigrationWhereParam::NameContains(value) + } + pub fn has_prefix(&self, value: String) -> MigrationWhereParam { + MigrationWhereParam::NameHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> MigrationWhereParam { + MigrationWhereParam::NameHasSuffix(value) + } + pub fn equals(&self, value: String) -> MigrationWhereParam { + MigrationWhereParam::NameEquals(value) + } + pub fn set>(&self, value: String) -> T { + MigrationSetName(value).into() + } +} +pub struct MigrationChecksumField {} +pub struct MigrationSetChecksum(String); +impl From for MigrationSetParam { + fn from(value: MigrationSetChecksum) -> Self { + Self::Checksum(value.0) + } +} +impl MigrationChecksumField { + pub fn contains(&self, value: String) -> MigrationWhereParam { + MigrationWhereParam::ChecksumContains(value) + } + pub fn has_prefix(&self, value: String) -> MigrationWhereParam { + MigrationWhereParam::ChecksumHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> MigrationWhereParam { + MigrationWhereParam::ChecksumHasSuffix(value) + } + pub fn equals(&self, value: String) -> MigrationWhereParam { + MigrationWhereParam::ChecksumEquals(value) + } + pub fn set>(&self, value: String) -> T { + MigrationSetChecksum(value).into() + } +} +pub struct MigrationStepsAppliedField {} +pub struct MigrationSetStepsApplied(i64); +impl From for MigrationSetParam { + fn from(value: MigrationSetStepsApplied) -> Self { + Self::StepsApplied(value.0) + } +} +impl MigrationStepsAppliedField { + pub fn lt(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::StepsAppliedLT(value) + } + pub fn gt(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::StepsAppliedGT(value) + } + pub fn lte(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::StepsAppliedLTE(value) + } + pub fn gte(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::StepsAppliedGTE(value) + } + pub fn equals(&self, value: i64) -> MigrationWhereParam { + MigrationWhereParam::StepsAppliedEquals(value) + } + pub fn set>(&self, value: i64) -> T { + MigrationSetStepsApplied(value).into() + } +} +pub struct MigrationAppliedAtField {} +pub struct MigrationSetAppliedAt(chrono::DateTime); +impl From for MigrationSetParam { + fn from(value: MigrationSetAppliedAt) -> Self { + Self::AppliedAt(value.0) + } +} +impl MigrationAppliedAtField { + pub fn before(&self, value: chrono::DateTime) -> MigrationWhereParam { + MigrationWhereParam::AppliedAtBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> MigrationWhereParam { + MigrationWhereParam::AppliedAtAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> MigrationWhereParam { + MigrationWhereParam::AppliedAtBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> MigrationWhereParam { + MigrationWhereParam::AppliedAtAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> MigrationWhereParam { + MigrationWhereParam::AppliedAtEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + MigrationSetAppliedAt(value).into() + } +} +pub enum MigrationWhereParam { + IdLT(i64), + IdGT(i64), + IdLTE(i64), + IdGTE(i64), + IdEquals(i64), + NameContains(String), + NameHasPrefix(String), + NameHasSuffix(String), + NameEquals(String), + ChecksumContains(String), + ChecksumHasPrefix(String), + ChecksumHasSuffix(String), + ChecksumEquals(String), + StepsAppliedLT(i64), + StepsAppliedGT(i64), + StepsAppliedLTE(i64), + StepsAppliedGTE(i64), + StepsAppliedEquals(i64), + AppliedAtBefore(chrono::DateTime), + AppliedAtAfter(chrono::DateTime), + AppliedAtBeforeEquals(chrono::DateTime), + AppliedAtAfterEquals(chrono::DateTime), + AppliedAtEquals(chrono::DateTime), + Not(Vec), + Or(Vec), + And(Vec), +} +impl MigrationWhereParam { + pub fn field(self) -> Field { + match self { + Self::IdLT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdLTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdEquals(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameContains(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasPrefix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasSuffix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameEquals(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ChecksumContains(value) => Field { + name: "checksum".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ChecksumHasPrefix(value) => Field { + name: "checksum".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ChecksumHasSuffix(value) => Field { + name: "checksum".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ChecksumEquals(value) => Field { + name: "checksum".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StepsAppliedLT(value) => Field { + name: "steps_applied".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StepsAppliedGT(value) => Field { + name: "steps_applied".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StepsAppliedLTE(value) => Field { + name: "steps_applied".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StepsAppliedGTE(value) => Field { + name: "steps_applied".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StepsAppliedEquals(value) => Field { + name: "steps_applied".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AppliedAtBefore(value) => Field { + name: "applied_at".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AppliedAtAfter(value) => Field { + name: "applied_at".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AppliedAtBeforeEquals(value) => Field { + name: "applied_at".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AppliedAtAfterEquals(value) => Field { + name: "applied_at".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AppliedAtEquals(value) => Field { + name: "applied_at".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct MigrationWith { + pub param: MigrationWithParam, +} +pub enum MigrationWithParam {} +impl From for MigrationWith { + fn from(param: MigrationWithParam) -> Self { + Self { param } + } +} +impl MigrationWithParam { + pub fn output(self) -> Output { + match self {} + } +} +pub enum MigrationSetParam { + Id(i64), + Name(String), + Checksum(String), + StepsApplied(i64), + AppliedAt(chrono::DateTime), +} +impl MigrationSetParam { + pub fn field(self) -> Field { + match self { + Self::Id(value) => Field { + name: "id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Name(value) => Field { + name: "name".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Checksum(value) => Field { + name: "checksum".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::StepsApplied(value) => Field { + name: "steps_applied".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::AppliedAt(value) => Field { + name: "applied_at".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + } + } +} +pub struct MigrationFindMany<'a> { + query: Query<'a>, +} +impl<'a> MigrationFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> MigrationDelete<'a> { + MigrationDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "Migration".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> MigrationUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + MigrationUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct MigrationFindFirst<'a> { + query: Query<'a>, +} +impl<'a> MigrationFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct MigrationFindUnique<'a> { + query: Query<'a>, +} +impl<'a> MigrationFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> MigrationDelete<'a> { + MigrationDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "Migration".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> MigrationUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + MigrationUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct MigrationCreateOne<'a> { + query: Query<'a>, +} +impl<'a> MigrationCreateOne<'a> { + pub async fn exec(self) -> MigrationData { + self.query.perform::().await.unwrap() + } +} +pub struct MigrationUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> MigrationUpdateUnique<'a> { + pub async fn exec(self) -> MigrationData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct MigrationUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> MigrationUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct MigrationDelete<'a> { + query: Query<'a>, +} +impl<'a> MigrationDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct MigrationActions<'a> { + client: &'a PrismaClient, +} +impl<'a> MigrationActions<'a> { + pub fn find_unique(&self, param: MigrationWhereParam) -> MigrationFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "Migration".into(), + outputs: migration_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + MigrationFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> MigrationFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "Migration".into(), + outputs: migration_outputs(), + inputs, + }; + MigrationFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> MigrationFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "Migration".into(), + outputs: migration_outputs(), + inputs, + }; + MigrationFindMany { query } + } + pub fn create_one( + &self, + name: MigrationSetName, + checksum: MigrationSetChecksum, + params: Vec, + ) -> MigrationCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + input_fields.push(MigrationSetParam::from(name).field()); + input_fields.push(MigrationSetParam::from(checksum).field()); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "Migration".into(), + outputs: migration_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + MigrationCreateOne { query } + } +} +fn library_outputs() -> Vec { + vec![ + Output::new("id"), + Output::new("uuid"), + Output::new("name"), + Output::new("remote_id"), + Output::new("is_primary"), + Output::new("encryption"), + Output::new("total_file_count"), + Output::new("total_bytes_used"), + Output::new("total_byte_capacity"), + Output::new("total_unique_bytes"), + Output::new("date_created"), + Output::new("timezone"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct LibraryData { + #[serde(rename = "id")] + pub id: i64, + #[serde(rename = "uuid")] + pub uuid: String, + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "remote_id")] + pub remote_id: Option, + #[serde(rename = "is_primary")] + pub is_primary: bool, + #[serde(rename = "encryption")] + pub encryption: i64, + #[serde(rename = "total_file_count")] + pub total_file_count: i64, + #[serde(rename = "total_bytes_used")] + pub total_bytes_used: String, + #[serde(rename = "total_byte_capacity")] + pub total_byte_capacity: String, + #[serde(rename = "total_unique_bytes")] + pub total_unique_bytes: String, + #[serde(rename = "date_created")] + pub date_created: chrono::DateTime, + #[serde(rename = "timezone")] + pub timezone: Option, + #[serde(rename = "spaces")] + spaces: Option>, +} +impl LibraryData { + pub fn spaces(&self) -> Result<&Vec, String> { + match self.spaces.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access spaces but did not fetch it using the .with() syntax" + .to_string(), + ), + } + } +} +pub struct Library; +impl Library { + pub fn id() -> LibraryIdField { + LibraryIdField {} + } + pub fn uuid() -> LibraryUuidField { + LibraryUuidField {} + } + pub fn name() -> LibraryNameField { + LibraryNameField {} + } + pub fn remote_id() -> LibraryRemoteIdField { + LibraryRemoteIdField {} + } + pub fn is_primary() -> LibraryIsPrimaryField { + LibraryIsPrimaryField {} + } + pub fn encryption() -> LibraryEncryptionField { + LibraryEncryptionField {} + } + pub fn total_file_count() -> LibraryTotalFileCountField { + LibraryTotalFileCountField {} + } + pub fn total_bytes_used() -> LibraryTotalBytesUsedField { + LibraryTotalBytesUsedField {} + } + pub fn total_byte_capacity() -> LibraryTotalByteCapacityField { + LibraryTotalByteCapacityField {} + } + pub fn total_unique_bytes() -> LibraryTotalUniqueBytesField { + LibraryTotalUniqueBytesField {} + } + pub fn date_created() -> LibraryDateCreatedField { + LibraryDateCreatedField {} + } + pub fn timezone() -> LibraryTimezoneField { + LibraryTimezoneField {} + } + pub fn spaces() -> LibrarySpacesField { + LibrarySpacesField {} + } + pub fn not(params: Vec) -> LibraryWhereParam { + LibraryWhereParam::Not(params) + } + pub fn or(params: Vec) -> LibraryWhereParam { + LibraryWhereParam::Or(params) + } + pub fn and(params: Vec) -> LibraryWhereParam { + LibraryWhereParam::And(params) + } +} +pub struct LibraryIdField {} +pub struct LibrarySetId(i64); +impl From for LibrarySetParam { + fn from(value: LibrarySetId) -> Self { + Self::Id(value.0) + } +} +impl LibraryIdField { + pub fn lt(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::IdLT(value) + } + pub fn gt(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::IdGT(value) + } + pub fn lte(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::IdLTE(value) + } + pub fn gte(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::IdGTE(value) + } + pub fn equals(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::IdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + LibrarySetId(value).into() + } +} +pub struct LibraryUuidField {} +pub struct LibrarySetUuid(String); +impl From for LibrarySetParam { + fn from(value: LibrarySetUuid) -> Self { + Self::Uuid(value.0) + } +} +impl LibraryUuidField { + pub fn contains(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::UuidContains(value) + } + pub fn has_prefix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::UuidHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::UuidHasSuffix(value) + } + pub fn equals(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::UuidEquals(value) + } + pub fn set>(&self, value: String) -> T { + LibrarySetUuid(value).into() + } +} +pub struct LibraryNameField {} +pub struct LibrarySetName(String); +impl From for LibrarySetParam { + fn from(value: LibrarySetName) -> Self { + Self::Name(value.0) + } +} +impl LibraryNameField { + pub fn contains(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::NameContains(value) + } + pub fn has_prefix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::NameHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::NameHasSuffix(value) + } + pub fn equals(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::NameEquals(value) + } + pub fn set>(&self, value: String) -> T { + LibrarySetName(value).into() + } +} +pub struct LibraryRemoteIdField {} +pub struct LibrarySetRemoteId(String); +impl From for LibrarySetParam { + fn from(value: LibrarySetRemoteId) -> Self { + Self::RemoteId(value.0) + } +} +impl LibraryRemoteIdField { + pub fn contains(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::RemoteIdContains(value) + } + pub fn has_prefix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::RemoteIdHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::RemoteIdHasSuffix(value) + } + pub fn equals(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::RemoteIdEquals(value) + } + pub fn set>(&self, value: String) -> T { + LibrarySetRemoteId(value).into() + } +} +pub struct LibraryIsPrimaryField {} +pub struct LibrarySetIsPrimary(bool); +impl From for LibrarySetParam { + fn from(value: LibrarySetIsPrimary) -> Self { + Self::IsPrimary(value.0) + } +} +impl LibraryIsPrimaryField { + pub fn equals(&self, value: bool) -> LibraryWhereParam { + LibraryWhereParam::IsPrimaryEquals(value) + } + pub fn set>(&self, value: bool) -> T { + LibrarySetIsPrimary(value).into() + } +} +pub struct LibraryEncryptionField {} +pub struct LibrarySetEncryption(i64); +impl From for LibrarySetParam { + fn from(value: LibrarySetEncryption) -> Self { + Self::Encryption(value.0) + } +} +impl LibraryEncryptionField { + pub fn lt(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::EncryptionLT(value) + } + pub fn gt(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::EncryptionGT(value) + } + pub fn lte(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::EncryptionLTE(value) + } + pub fn gte(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::EncryptionGTE(value) + } + pub fn equals(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::EncryptionEquals(value) + } + pub fn set>(&self, value: i64) -> T { + LibrarySetEncryption(value).into() + } +} +pub struct LibraryTotalFileCountField {} +pub struct LibrarySetTotalFileCount(i64); +impl From for LibrarySetParam { + fn from(value: LibrarySetTotalFileCount) -> Self { + Self::TotalFileCount(value.0) + } +} +impl LibraryTotalFileCountField { + pub fn lt(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::TotalFileCountLT(value) + } + pub fn gt(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::TotalFileCountGT(value) + } + pub fn lte(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::TotalFileCountLTE(value) + } + pub fn gte(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::TotalFileCountGTE(value) + } + pub fn equals(&self, value: i64) -> LibraryWhereParam { + LibraryWhereParam::TotalFileCountEquals(value) + } + pub fn set>(&self, value: i64) -> T { + LibrarySetTotalFileCount(value).into() + } +} +pub struct LibraryTotalBytesUsedField {} +pub struct LibrarySetTotalBytesUsed(String); +impl From for LibrarySetParam { + fn from(value: LibrarySetTotalBytesUsed) -> Self { + Self::TotalBytesUsed(value.0) + } +} +impl LibraryTotalBytesUsedField { + pub fn contains(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalBytesUsedContains(value) + } + pub fn has_prefix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalBytesUsedHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalBytesUsedHasSuffix(value) + } + pub fn equals(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalBytesUsedEquals(value) + } + pub fn set>(&self, value: String) -> T { + LibrarySetTotalBytesUsed(value).into() + } +} +pub struct LibraryTotalByteCapacityField {} +pub struct LibrarySetTotalByteCapacity(String); +impl From for LibrarySetParam { + fn from(value: LibrarySetTotalByteCapacity) -> Self { + Self::TotalByteCapacity(value.0) + } +} +impl LibraryTotalByteCapacityField { + pub fn contains(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalByteCapacityContains(value) + } + pub fn has_prefix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalByteCapacityHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalByteCapacityHasSuffix(value) + } + pub fn equals(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalByteCapacityEquals(value) + } + pub fn set>(&self, value: String) -> T { + LibrarySetTotalByteCapacity(value).into() + } +} +pub struct LibraryTotalUniqueBytesField {} +pub struct LibrarySetTotalUniqueBytes(String); +impl From for LibrarySetParam { + fn from(value: LibrarySetTotalUniqueBytes) -> Self { + Self::TotalUniqueBytes(value.0) + } +} +impl LibraryTotalUniqueBytesField { + pub fn contains(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalUniqueBytesContains(value) + } + pub fn has_prefix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalUniqueBytesHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalUniqueBytesHasSuffix(value) + } + pub fn equals(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TotalUniqueBytesEquals(value) + } + pub fn set>(&self, value: String) -> T { + LibrarySetTotalUniqueBytes(value).into() + } +} +pub struct LibraryDateCreatedField {} +pub struct LibrarySetDateCreated(chrono::DateTime); +impl From for LibrarySetParam { + fn from(value: LibrarySetDateCreated) -> Self { + Self::DateCreated(value.0) + } +} +impl LibraryDateCreatedField { + pub fn before(&self, value: chrono::DateTime) -> LibraryWhereParam { + LibraryWhereParam::DateCreatedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> LibraryWhereParam { + LibraryWhereParam::DateCreatedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> LibraryWhereParam { + LibraryWhereParam::DateCreatedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> LibraryWhereParam { + LibraryWhereParam::DateCreatedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> LibraryWhereParam { + LibraryWhereParam::DateCreatedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + LibrarySetDateCreated(value).into() + } +} +pub struct LibraryTimezoneField {} +pub struct LibrarySetTimezone(String); +impl From for LibrarySetParam { + fn from(value: LibrarySetTimezone) -> Self { + Self::Timezone(value.0) + } +} +impl LibraryTimezoneField { + pub fn contains(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TimezoneContains(value) + } + pub fn has_prefix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TimezoneHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TimezoneHasSuffix(value) + } + pub fn equals(&self, value: String) -> LibraryWhereParam { + LibraryWhereParam::TimezoneEquals(value) + } + pub fn set>(&self, value: String) -> T { + LibrarySetTimezone(value).into() + } +} +pub struct LibrarySpacesField {} +pub struct LibraryLinkSpaces(Vec); +impl From for LibrarySetParam { + fn from(value: LibraryLinkSpaces) -> Self { + Self::LinkSpaces(value.0.into_iter().map(|v| v.into()).collect()) + } +} +impl LibrarySpacesField { + pub fn some(&self, value: Vec) -> LibraryWhereParam { + LibraryWhereParam::SpacesSome(value) + } + pub fn every(&self, value: Vec) -> LibraryWhereParam { + LibraryWhereParam::SpacesEvery(value) + } + pub fn link>(&self, value: Vec) -> T { + LibraryLinkSpaces(value).into() + } + pub fn unlink(&self, params: Vec) -> LibrarySetParam { + LibrarySetParam::UnlinkSpaces(params) + } + pub fn fetch(&self, params: Vec) -> LibraryWith { + LibraryWithParam::Spaces(params).into() + } +} +pub enum LibraryWhereParam { + IdLT(i64), + IdGT(i64), + IdLTE(i64), + IdGTE(i64), + IdEquals(i64), + UuidContains(String), + UuidHasPrefix(String), + UuidHasSuffix(String), + UuidEquals(String), + NameContains(String), + NameHasPrefix(String), + NameHasSuffix(String), + NameEquals(String), + RemoteIdContains(String), + RemoteIdHasPrefix(String), + RemoteIdHasSuffix(String), + RemoteIdEquals(String), + IsPrimaryEquals(bool), + EncryptionLT(i64), + EncryptionGT(i64), + EncryptionLTE(i64), + EncryptionGTE(i64), + EncryptionEquals(i64), + TotalFileCountLT(i64), + TotalFileCountGT(i64), + TotalFileCountLTE(i64), + TotalFileCountGTE(i64), + TotalFileCountEquals(i64), + TotalBytesUsedContains(String), + TotalBytesUsedHasPrefix(String), + TotalBytesUsedHasSuffix(String), + TotalBytesUsedEquals(String), + TotalByteCapacityContains(String), + TotalByteCapacityHasPrefix(String), + TotalByteCapacityHasSuffix(String), + TotalByteCapacityEquals(String), + TotalUniqueBytesContains(String), + TotalUniqueBytesHasPrefix(String), + TotalUniqueBytesHasSuffix(String), + TotalUniqueBytesEquals(String), + DateCreatedBefore(chrono::DateTime), + DateCreatedAfter(chrono::DateTime), + DateCreatedBeforeEquals(chrono::DateTime), + DateCreatedAfterEquals(chrono::DateTime), + DateCreatedEquals(chrono::DateTime), + TimezoneContains(String), + TimezoneHasPrefix(String), + TimezoneHasSuffix(String), + TimezoneEquals(String), + SpacesSome(Vec), + SpacesEvery(Vec), + Not(Vec), + Or(Vec), + And(Vec), +} +impl LibraryWhereParam { + pub fn field(self) -> Field { + match self { + Self::IdLT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdLTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdEquals(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::UuidContains(value) => Field { + name: "uuid".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::UuidHasPrefix(value) => Field { + name: "uuid".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::UuidHasSuffix(value) => Field { + name: "uuid".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::UuidEquals(value) => Field { + name: "uuid".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameContains(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasPrefix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasSuffix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameEquals(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RemoteIdContains(value) => Field { + name: "remote_id".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RemoteIdHasPrefix(value) => Field { + name: "remote_id".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RemoteIdHasSuffix(value) => Field { + name: "remote_id".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RemoteIdEquals(value) => Field { + name: "remote_id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IsPrimaryEquals(value) => Field { + name: "is_primary".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionLT(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionGT(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionLTE(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionGTE(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionEquals(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFileCountLT(value) => Field { + name: "total_file_count".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFileCountGT(value) => Field { + name: "total_file_count".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFileCountLTE(value) => Field { + name: "total_file_count".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFileCountGTE(value) => Field { + name: "total_file_count".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFileCountEquals(value) => Field { + name: "total_file_count".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalBytesUsedContains(value) => Field { + name: "total_bytes_used".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalBytesUsedHasPrefix(value) => Field { + name: "total_bytes_used".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalBytesUsedHasSuffix(value) => Field { + name: "total_bytes_used".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalBytesUsedEquals(value) => Field { + name: "total_bytes_used".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalByteCapacityContains(value) => Field { + name: "total_byte_capacity".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalByteCapacityHasPrefix(value) => Field { + name: "total_byte_capacity".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalByteCapacityHasSuffix(value) => Field { + name: "total_byte_capacity".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalByteCapacityEquals(value) => Field { + name: "total_byte_capacity".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalUniqueBytesContains(value) => Field { + name: "total_unique_bytes".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalUniqueBytesHasPrefix(value) => Field { + name: "total_unique_bytes".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalUniqueBytesHasSuffix(value) => Field { + name: "total_unique_bytes".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalUniqueBytesEquals(value) => Field { + name: "total_unique_bytes".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBefore(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfter(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBeforeEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfterEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TimezoneContains(value) => Field { + name: "timezone".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TimezoneHasPrefix(value) => Field { + name: "timezone".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TimezoneHasSuffix(value) => Field { + name: "timezone".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TimezoneEquals(value) => Field { + name: "timezone".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::SpacesSome(value) => Field { + name: "spaces".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::SpacesEvery(value) => Field { + name: "spaces".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct LibraryWith { + pub param: LibraryWithParam, +} +pub enum LibraryWithParam { + Spaces(Vec), +} +impl From for LibraryWith { + fn from(param: LibraryWithParam) -> Self { + Self { param } + } +} +impl LibraryWithParam { + pub fn output(self) -> Output { + match self { + Self::Spaces(where_params) => Output { + name: "spaces".into(), + outputs: space_outputs(), + inputs: if where_params.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_params.into_iter().map(|f| f.field()).collect(), + ..Default::default() + }] + } else { + vec![] + }, + ..Default::default() + }, + } + } +} +pub enum LibrarySetParam { + Id(i64), + Uuid(String), + Name(String), + RemoteId(String), + IsPrimary(bool), + Encryption(i64), + TotalFileCount(i64), + TotalBytesUsed(String), + TotalByteCapacity(String), + TotalUniqueBytes(String), + DateCreated(chrono::DateTime), + Timezone(String), + LinkSpaces(Vec), + UnlinkSpaces(Vec), +} +impl LibrarySetParam { + pub fn field(self) -> Field { + match self { + Self::Id(value) => Field { + name: "id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Uuid(value) => Field { + name: "uuid".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Name(value) => Field { + name: "name".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::RemoteId(value) => Field { + name: "remote_id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::IsPrimary(value) => Field { + name: "is_primary".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Encryption(value) => Field { + name: "encryption".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::TotalFileCount(value) => Field { + name: "total_file_count".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::TotalBytesUsed(value) => Field { + name: "total_bytes_used".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::TotalByteCapacity(value) => Field { + name: "total_byte_capacity".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::TotalUniqueBytes(value) => Field { + name: "total_unique_bytes".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateCreated(value) => Field { + name: "date_created".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Timezone(value) => Field { + name: "timezone".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkSpaces(where_params) => Field { + name: "spaces".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + list: true, + wrap_list: true, + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkSpaces(where_params) => Field { + name: "spaces".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + list: true, + wrap_list: true, + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + ..Default::default() + }]), + ..Default::default() + }, + } + } +} +pub struct LibraryFindMany<'a> { + query: Query<'a>, +} +impl<'a> LibraryFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> LibraryDelete<'a> { + LibraryDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "Library".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> LibraryUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + LibraryUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LibraryFindFirst<'a> { + query: Query<'a>, +} +impl<'a> LibraryFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LibraryFindUnique<'a> { + query: Query<'a>, +} +impl<'a> LibraryFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> LibraryDelete<'a> { + LibraryDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "Library".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> LibraryUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + LibraryUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LibraryCreateOne<'a> { + query: Query<'a>, +} +impl<'a> LibraryCreateOne<'a> { + pub async fn exec(self) -> LibraryData { + self.query.perform::().await.unwrap() + } +} +pub struct LibraryUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> LibraryUpdateUnique<'a> { + pub async fn exec(self) -> LibraryData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LibraryUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> LibraryUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LibraryDelete<'a> { + query: Query<'a>, +} +impl<'a> LibraryDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct LibraryActions<'a> { + client: &'a PrismaClient, +} +impl<'a> LibraryActions<'a> { + pub fn find_unique(&self, param: LibraryWhereParam) -> LibraryFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "Library".into(), + outputs: library_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + LibraryFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> LibraryFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "Library".into(), + outputs: library_outputs(), + inputs, + }; + LibraryFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> LibraryFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "Library".into(), + outputs: library_outputs(), + inputs, + }; + LibraryFindMany { query } + } + pub fn create_one( + &self, + uuid: LibrarySetUuid, + name: LibrarySetName, + params: Vec, + ) -> LibraryCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + input_fields.push(LibrarySetParam::from(uuid).field()); + input_fields.push(LibrarySetParam::from(name).field()); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "Library".into(), + outputs: library_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + LibraryCreateOne { query } + } +} +fn client_outputs() -> Vec { + vec![ + Output::new("id"), + Output::new("uuid"), + Output::new("name"), + Output::new("platform"), + Output::new("version"), + Output::new("online"), + Output::new("last_seen"), + Output::new("timezone"), + Output::new("date_created"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ClientData { + #[serde(rename = "id")] + pub id: i64, + #[serde(rename = "uuid")] + pub uuid: String, + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "platform")] + pub platform: i64, + #[serde(rename = "version")] + pub version: Option, + #[serde(rename = "online")] + pub online: Option, + #[serde(rename = "last_seen")] + pub last_seen: chrono::DateTime, + #[serde(rename = "timezone")] + pub timezone: Option, + #[serde(rename = "date_created")] + pub date_created: chrono::DateTime, + #[serde(rename = "jobs")] + jobs: Option>, +} +impl ClientData { + pub fn jobs(&self) -> Result<&Vec, String> { + match self.jobs.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access jobs but did not fetch it using the .with() syntax" + .to_string(), + ), + } + } +} +pub struct Client; +impl Client { + pub fn id() -> ClientIdField { + ClientIdField {} + } + pub fn uuid() -> ClientUuidField { + ClientUuidField {} + } + pub fn name() -> ClientNameField { + ClientNameField {} + } + pub fn platform() -> ClientPlatformField { + ClientPlatformField {} + } + pub fn version() -> ClientVersionField { + ClientVersionField {} + } + pub fn online() -> ClientOnlineField { + ClientOnlineField {} + } + pub fn last_seen() -> ClientLastSeenField { + ClientLastSeenField {} + } + pub fn timezone() -> ClientTimezoneField { + ClientTimezoneField {} + } + pub fn date_created() -> ClientDateCreatedField { + ClientDateCreatedField {} + } + pub fn jobs() -> ClientJobsField { + ClientJobsField {} + } + pub fn not(params: Vec) -> ClientWhereParam { + ClientWhereParam::Not(params) + } + pub fn or(params: Vec) -> ClientWhereParam { + ClientWhereParam::Or(params) + } + pub fn and(params: Vec) -> ClientWhereParam { + ClientWhereParam::And(params) + } +} +pub struct ClientIdField {} +pub struct ClientSetId(i64); +impl From for ClientSetParam { + fn from(value: ClientSetId) -> Self { + Self::Id(value.0) + } +} +impl ClientIdField { + pub fn lt(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::IdLT(value) + } + pub fn gt(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::IdGT(value) + } + pub fn lte(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::IdLTE(value) + } + pub fn gte(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::IdGTE(value) + } + pub fn equals(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::IdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + ClientSetId(value).into() + } +} +pub struct ClientUuidField {} +pub struct ClientSetUuid(String); +impl From for ClientSetParam { + fn from(value: ClientSetUuid) -> Self { + Self::Uuid(value.0) + } +} +impl ClientUuidField { + pub fn contains(&self, value: String) -> ClientWhereParam { + ClientWhereParam::UuidContains(value) + } + pub fn has_prefix(&self, value: String) -> ClientWhereParam { + ClientWhereParam::UuidHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> ClientWhereParam { + ClientWhereParam::UuidHasSuffix(value) + } + pub fn equals(&self, value: String) -> ClientWhereParam { + ClientWhereParam::UuidEquals(value) + } + pub fn set>(&self, value: String) -> T { + ClientSetUuid(value).into() + } +} +pub struct ClientNameField {} +pub struct ClientSetName(String); +impl From for ClientSetParam { + fn from(value: ClientSetName) -> Self { + Self::Name(value.0) + } +} +impl ClientNameField { + pub fn contains(&self, value: String) -> ClientWhereParam { + ClientWhereParam::NameContains(value) + } + pub fn has_prefix(&self, value: String) -> ClientWhereParam { + ClientWhereParam::NameHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> ClientWhereParam { + ClientWhereParam::NameHasSuffix(value) + } + pub fn equals(&self, value: String) -> ClientWhereParam { + ClientWhereParam::NameEquals(value) + } + pub fn set>(&self, value: String) -> T { + ClientSetName(value).into() + } +} +pub struct ClientPlatformField {} +pub struct ClientSetPlatform(i64); +impl From for ClientSetParam { + fn from(value: ClientSetPlatform) -> Self { + Self::Platform(value.0) + } +} +impl ClientPlatformField { + pub fn lt(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::PlatformLT(value) + } + pub fn gt(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::PlatformGT(value) + } + pub fn lte(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::PlatformLTE(value) + } + pub fn gte(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::PlatformGTE(value) + } + pub fn equals(&self, value: i64) -> ClientWhereParam { + ClientWhereParam::PlatformEquals(value) + } + pub fn set>(&self, value: i64) -> T { + ClientSetPlatform(value).into() + } +} +pub struct ClientVersionField {} +pub struct ClientSetVersion(String); +impl From for ClientSetParam { + fn from(value: ClientSetVersion) -> Self { + Self::Version(value.0) + } +} +impl ClientVersionField { + pub fn contains(&self, value: String) -> ClientWhereParam { + ClientWhereParam::VersionContains(value) + } + pub fn has_prefix(&self, value: String) -> ClientWhereParam { + ClientWhereParam::VersionHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> ClientWhereParam { + ClientWhereParam::VersionHasSuffix(value) + } + pub fn equals(&self, value: String) -> ClientWhereParam { + ClientWhereParam::VersionEquals(value) + } + pub fn set>(&self, value: String) -> T { + ClientSetVersion(value).into() + } +} +pub struct ClientOnlineField {} +pub struct ClientSetOnline(bool); +impl From for ClientSetParam { + fn from(value: ClientSetOnline) -> Self { + Self::Online(value.0) + } +} +impl ClientOnlineField { + pub fn equals(&self, value: bool) -> ClientWhereParam { + ClientWhereParam::OnlineEquals(value) + } + pub fn set>(&self, value: bool) -> T { + ClientSetOnline(value).into() + } +} +pub struct ClientLastSeenField {} +pub struct ClientSetLastSeen(chrono::DateTime); +impl From for ClientSetParam { + fn from(value: ClientSetLastSeen) -> Self { + Self::LastSeen(value.0) + } +} +impl ClientLastSeenField { + pub fn before(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::LastSeenBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::LastSeenAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::LastSeenBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::LastSeenAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::LastSeenEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + ClientSetLastSeen(value).into() + } +} +pub struct ClientTimezoneField {} +pub struct ClientSetTimezone(String); +impl From for ClientSetParam { + fn from(value: ClientSetTimezone) -> Self { + Self::Timezone(value.0) + } +} +impl ClientTimezoneField { + pub fn contains(&self, value: String) -> ClientWhereParam { + ClientWhereParam::TimezoneContains(value) + } + pub fn has_prefix(&self, value: String) -> ClientWhereParam { + ClientWhereParam::TimezoneHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> ClientWhereParam { + ClientWhereParam::TimezoneHasSuffix(value) + } + pub fn equals(&self, value: String) -> ClientWhereParam { + ClientWhereParam::TimezoneEquals(value) + } + pub fn set>(&self, value: String) -> T { + ClientSetTimezone(value).into() + } +} +pub struct ClientDateCreatedField {} +pub struct ClientSetDateCreated(chrono::DateTime); +impl From for ClientSetParam { + fn from(value: ClientSetDateCreated) -> Self { + Self::DateCreated(value.0) + } +} +impl ClientDateCreatedField { + pub fn before(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::DateCreatedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::DateCreatedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::DateCreatedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::DateCreatedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> ClientWhereParam { + ClientWhereParam::DateCreatedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + ClientSetDateCreated(value).into() + } +} +pub struct ClientJobsField {} +pub struct ClientLinkJobs(Vec); +impl From for ClientSetParam { + fn from(value: ClientLinkJobs) -> Self { + Self::LinkJobs(value.0.into_iter().map(|v| v.into()).collect()) + } +} +impl ClientJobsField { + pub fn some(&self, value: Vec) -> ClientWhereParam { + ClientWhereParam::JobsSome(value) + } + pub fn every(&self, value: Vec) -> ClientWhereParam { + ClientWhereParam::JobsEvery(value) + } + pub fn link>(&self, value: Vec) -> T { + ClientLinkJobs(value).into() + } + pub fn unlink(&self, params: Vec) -> ClientSetParam { + ClientSetParam::UnlinkJobs(params) + } + pub fn fetch(&self, params: Vec) -> ClientWith { + ClientWithParam::Jobs(params).into() + } +} +pub enum ClientWhereParam { + IdLT(i64), + IdGT(i64), + IdLTE(i64), + IdGTE(i64), + IdEquals(i64), + UuidContains(String), + UuidHasPrefix(String), + UuidHasSuffix(String), + UuidEquals(String), + NameContains(String), + NameHasPrefix(String), + NameHasSuffix(String), + NameEquals(String), + PlatformLT(i64), + PlatformGT(i64), + PlatformLTE(i64), + PlatformGTE(i64), + PlatformEquals(i64), + VersionContains(String), + VersionHasPrefix(String), + VersionHasSuffix(String), + VersionEquals(String), + OnlineEquals(bool), + LastSeenBefore(chrono::DateTime), + LastSeenAfter(chrono::DateTime), + LastSeenBeforeEquals(chrono::DateTime), + LastSeenAfterEquals(chrono::DateTime), + LastSeenEquals(chrono::DateTime), + TimezoneContains(String), + TimezoneHasPrefix(String), + TimezoneHasSuffix(String), + TimezoneEquals(String), + DateCreatedBefore(chrono::DateTime), + DateCreatedAfter(chrono::DateTime), + DateCreatedBeforeEquals(chrono::DateTime), + DateCreatedAfterEquals(chrono::DateTime), + DateCreatedEquals(chrono::DateTime), + JobsSome(Vec), + JobsEvery(Vec), + Not(Vec), + Or(Vec), + And(Vec), +} +impl ClientWhereParam { + pub fn field(self) -> Field { + match self { + Self::IdLT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdLTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdEquals(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::UuidContains(value) => Field { + name: "uuid".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::UuidHasPrefix(value) => Field { + name: "uuid".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::UuidHasSuffix(value) => Field { + name: "uuid".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::UuidEquals(value) => Field { + name: "uuid".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameContains(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasPrefix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasSuffix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameEquals(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PlatformLT(value) => Field { + name: "platform".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PlatformGT(value) => Field { + name: "platform".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PlatformLTE(value) => Field { + name: "platform".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PlatformGTE(value) => Field { + name: "platform".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PlatformEquals(value) => Field { + name: "platform".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::VersionContains(value) => Field { + name: "version".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::VersionHasPrefix(value) => Field { + name: "version".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::VersionHasSuffix(value) => Field { + name: "version".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::VersionEquals(value) => Field { + name: "version".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::OnlineEquals(value) => Field { + name: "online".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LastSeenBefore(value) => Field { + name: "last_seen".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LastSeenAfter(value) => Field { + name: "last_seen".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LastSeenBeforeEquals(value) => Field { + name: "last_seen".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LastSeenAfterEquals(value) => Field { + name: "last_seen".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LastSeenEquals(value) => Field { + name: "last_seen".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TimezoneContains(value) => Field { + name: "timezone".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TimezoneHasPrefix(value) => Field { + name: "timezone".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TimezoneHasSuffix(value) => Field { + name: "timezone".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TimezoneEquals(value) => Field { + name: "timezone".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBefore(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfter(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBeforeEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfterEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::JobsSome(value) => Field { + name: "jobs".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::JobsEvery(value) => Field { + name: "jobs".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct ClientWith { + pub param: ClientWithParam, +} +pub enum ClientWithParam { + Jobs(Vec), +} +impl From for ClientWith { + fn from(param: ClientWithParam) -> Self { + Self { param } + } +} +impl ClientWithParam { + pub fn output(self) -> Output { + match self { + Self::Jobs(where_params) => Output { + name: "jobs".into(), + outputs: job_outputs(), + inputs: if where_params.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_params.into_iter().map(|f| f.field()).collect(), + ..Default::default() + }] + } else { + vec![] + }, + ..Default::default() + }, + } + } +} +pub enum ClientSetParam { + Id(i64), + Uuid(String), + Name(String), + Platform(i64), + Version(String), + Online(bool), + LastSeen(chrono::DateTime), + Timezone(String), + DateCreated(chrono::DateTime), + LinkJobs(Vec), + UnlinkJobs(Vec), +} +impl ClientSetParam { + pub fn field(self) -> Field { + match self { + Self::Id(value) => Field { + name: "id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Uuid(value) => Field { + name: "uuid".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Name(value) => Field { + name: "name".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Platform(value) => Field { + name: "platform".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Version(value) => Field { + name: "version".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Online(value) => Field { + name: "online".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LastSeen(value) => Field { + name: "last_seen".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Timezone(value) => Field { + name: "timezone".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateCreated(value) => Field { + name: "date_created".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkJobs(where_params) => Field { + name: "jobs".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + list: true, + wrap_list: true, + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkJobs(where_params) => Field { + name: "jobs".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + list: true, + wrap_list: true, + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + ..Default::default() + }]), + ..Default::default() + }, + } + } +} +pub struct ClientFindMany<'a> { + query: Query<'a>, +} +impl<'a> ClientFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> ClientDelete<'a> { + ClientDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "Client".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> ClientUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + ClientUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct ClientFindFirst<'a> { + query: Query<'a>, +} +impl<'a> ClientFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct ClientFindUnique<'a> { + query: Query<'a>, +} +impl<'a> ClientFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> ClientDelete<'a> { + ClientDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "Client".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> ClientUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + ClientUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct ClientCreateOne<'a> { + query: Query<'a>, +} +impl<'a> ClientCreateOne<'a> { + pub async fn exec(self) -> ClientData { + self.query.perform::().await.unwrap() + } +} +pub struct ClientUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> ClientUpdateUnique<'a> { + pub async fn exec(self) -> ClientData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct ClientUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> ClientUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct ClientDelete<'a> { + query: Query<'a>, +} +impl<'a> ClientDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct ClientActions<'a> { + client: &'a PrismaClient, +} +impl<'a> ClientActions<'a> { + pub fn find_unique(&self, param: ClientWhereParam) -> ClientFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "Client".into(), + outputs: client_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + ClientFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> ClientFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "Client".into(), + outputs: client_outputs(), + inputs, + }; + ClientFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> ClientFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "Client".into(), + outputs: client_outputs(), + inputs, + }; + ClientFindMany { query } + } + pub fn create_one( + &self, + uuid: ClientSetUuid, + name: ClientSetName, + params: Vec, + ) -> ClientCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + input_fields.push(ClientSetParam::from(uuid).field()); + input_fields.push(ClientSetParam::from(name).field()); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "Client".into(), + outputs: client_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + ClientCreateOne { query } + } +} +fn location_outputs() -> Vec { + vec![ + Output::new("id"), + Output::new("name"), + Output::new("path"), + Output::new("total_capacity"), + Output::new("available_capacity"), + Output::new("is_removable"), + Output::new("is_ejectable"), + Output::new("is_root_filesystem"), + Output::new("is_online"), + Output::new("date_created"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct LocationData { + #[serde(rename = "id")] + pub id: i64, + #[serde(rename = "name")] + pub name: Option, + #[serde(rename = "path")] + pub path: Option, + #[serde(rename = "total_capacity")] + pub total_capacity: Option, + #[serde(rename = "available_capacity")] + pub available_capacity: Option, + #[serde(rename = "is_removable")] + pub is_removable: bool, + #[serde(rename = "is_ejectable")] + pub is_ejectable: bool, + #[serde(rename = "is_root_filesystem")] + pub is_root_filesystem: bool, + #[serde(rename = "is_online")] + pub is_online: bool, + #[serde(rename = "date_created")] + pub date_created: chrono::DateTime, + #[serde(rename = "files")] + files: Option>, +} +impl LocationData { + pub fn files(&self) -> Result<&Vec, String> { + match self.files.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access files but did not fetch it using the .with() syntax" + .to_string(), + ), + } + } +} +pub struct Location; +impl Location { + pub fn id() -> LocationIdField { + LocationIdField {} + } + pub fn name() -> LocationNameField { + LocationNameField {} + } + pub fn path() -> LocationPathField { + LocationPathField {} + } + pub fn total_capacity() -> LocationTotalCapacityField { + LocationTotalCapacityField {} + } + pub fn available_capacity() -> LocationAvailableCapacityField { + LocationAvailableCapacityField {} + } + pub fn is_removable() -> LocationIsRemovableField { + LocationIsRemovableField {} + } + pub fn is_ejectable() -> LocationIsEjectableField { + LocationIsEjectableField {} + } + pub fn is_root_filesystem() -> LocationIsRootFilesystemField { + LocationIsRootFilesystemField {} + } + pub fn is_online() -> LocationIsOnlineField { + LocationIsOnlineField {} + } + pub fn date_created() -> LocationDateCreatedField { + LocationDateCreatedField {} + } + pub fn files() -> LocationFilesField { + LocationFilesField {} + } + pub fn not(params: Vec) -> LocationWhereParam { + LocationWhereParam::Not(params) + } + pub fn or(params: Vec) -> LocationWhereParam { + LocationWhereParam::Or(params) + } + pub fn and(params: Vec) -> LocationWhereParam { + LocationWhereParam::And(params) + } +} +pub struct LocationIdField {} +pub struct LocationSetId(i64); +impl From for LocationSetParam { + fn from(value: LocationSetId) -> Self { + Self::Id(value.0) + } +} +impl LocationIdField { + pub fn lt(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::IdLT(value) + } + pub fn gt(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::IdGT(value) + } + pub fn lte(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::IdLTE(value) + } + pub fn gte(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::IdGTE(value) + } + pub fn equals(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::IdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + LocationSetId(value).into() + } +} +pub struct LocationNameField {} +pub struct LocationSetName(String); +impl From for LocationSetParam { + fn from(value: LocationSetName) -> Self { + Self::Name(value.0) + } +} +impl LocationNameField { + pub fn contains(&self, value: String) -> LocationWhereParam { + LocationWhereParam::NameContains(value) + } + pub fn has_prefix(&self, value: String) -> LocationWhereParam { + LocationWhereParam::NameHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LocationWhereParam { + LocationWhereParam::NameHasSuffix(value) + } + pub fn equals(&self, value: String) -> LocationWhereParam { + LocationWhereParam::NameEquals(value) + } + pub fn set>(&self, value: String) -> T { + LocationSetName(value).into() + } +} +pub struct LocationPathField {} +pub struct LocationSetPath(String); +impl From for LocationSetParam { + fn from(value: LocationSetPath) -> Self { + Self::Path(value.0) + } +} +impl LocationPathField { + pub fn contains(&self, value: String) -> LocationWhereParam { + LocationWhereParam::PathContains(value) + } + pub fn has_prefix(&self, value: String) -> LocationWhereParam { + LocationWhereParam::PathHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> LocationWhereParam { + LocationWhereParam::PathHasSuffix(value) + } + pub fn equals(&self, value: String) -> LocationWhereParam { + LocationWhereParam::PathEquals(value) + } + pub fn set>(&self, value: String) -> T { + LocationSetPath(value).into() + } +} +pub struct LocationTotalCapacityField {} +pub struct LocationSetTotalCapacity(i64); +impl From for LocationSetParam { + fn from(value: LocationSetTotalCapacity) -> Self { + Self::TotalCapacity(value.0) + } +} +impl LocationTotalCapacityField { + pub fn lt(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::TotalCapacityLT(value) + } + pub fn gt(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::TotalCapacityGT(value) + } + pub fn lte(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::TotalCapacityLTE(value) + } + pub fn gte(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::TotalCapacityGTE(value) + } + pub fn equals(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::TotalCapacityEquals(value) + } + pub fn set>(&self, value: i64) -> T { + LocationSetTotalCapacity(value).into() + } +} +pub struct LocationAvailableCapacityField {} +pub struct LocationSetAvailableCapacity(i64); +impl From for LocationSetParam { + fn from(value: LocationSetAvailableCapacity) -> Self { + Self::AvailableCapacity(value.0) + } +} +impl LocationAvailableCapacityField { + pub fn lt(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::AvailableCapacityLT(value) + } + pub fn gt(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::AvailableCapacityGT(value) + } + pub fn lte(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::AvailableCapacityLTE(value) + } + pub fn gte(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::AvailableCapacityGTE(value) + } + pub fn equals(&self, value: i64) -> LocationWhereParam { + LocationWhereParam::AvailableCapacityEquals(value) + } + pub fn set>(&self, value: i64) -> T { + LocationSetAvailableCapacity(value).into() + } +} +pub struct LocationIsRemovableField {} +pub struct LocationSetIsRemovable(bool); +impl From for LocationSetParam { + fn from(value: LocationSetIsRemovable) -> Self { + Self::IsRemovable(value.0) + } +} +impl LocationIsRemovableField { + pub fn equals(&self, value: bool) -> LocationWhereParam { + LocationWhereParam::IsRemovableEquals(value) + } + pub fn set>(&self, value: bool) -> T { + LocationSetIsRemovable(value).into() + } +} +pub struct LocationIsEjectableField {} +pub struct LocationSetIsEjectable(bool); +impl From for LocationSetParam { + fn from(value: LocationSetIsEjectable) -> Self { + Self::IsEjectable(value.0) + } +} +impl LocationIsEjectableField { + pub fn equals(&self, value: bool) -> LocationWhereParam { + LocationWhereParam::IsEjectableEquals(value) + } + pub fn set>(&self, value: bool) -> T { + LocationSetIsEjectable(value).into() + } +} +pub struct LocationIsRootFilesystemField {} +pub struct LocationSetIsRootFilesystem(bool); +impl From for LocationSetParam { + fn from(value: LocationSetIsRootFilesystem) -> Self { + Self::IsRootFilesystem(value.0) + } +} +impl LocationIsRootFilesystemField { + pub fn equals(&self, value: bool) -> LocationWhereParam { + LocationWhereParam::IsRootFilesystemEquals(value) + } + pub fn set>(&self, value: bool) -> T { + LocationSetIsRootFilesystem(value).into() + } +} +pub struct LocationIsOnlineField {} +pub struct LocationSetIsOnline(bool); +impl From for LocationSetParam { + fn from(value: LocationSetIsOnline) -> Self { + Self::IsOnline(value.0) + } +} +impl LocationIsOnlineField { + pub fn equals(&self, value: bool) -> LocationWhereParam { + LocationWhereParam::IsOnlineEquals(value) + } + pub fn set>(&self, value: bool) -> T { + LocationSetIsOnline(value).into() + } +} +pub struct LocationDateCreatedField {} +pub struct LocationSetDateCreated(chrono::DateTime); +impl From for LocationSetParam { + fn from(value: LocationSetDateCreated) -> Self { + Self::DateCreated(value.0) + } +} +impl LocationDateCreatedField { + pub fn before(&self, value: chrono::DateTime) -> LocationWhereParam { + LocationWhereParam::DateCreatedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> LocationWhereParam { + LocationWhereParam::DateCreatedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> LocationWhereParam { + LocationWhereParam::DateCreatedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> LocationWhereParam { + LocationWhereParam::DateCreatedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> LocationWhereParam { + LocationWhereParam::DateCreatedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + LocationSetDateCreated(value).into() + } +} +pub struct LocationFilesField {} +pub struct LocationLinkFiles(Vec); +impl From for LocationSetParam { + fn from(value: LocationLinkFiles) -> Self { + Self::LinkFiles(value.0.into_iter().map(|v| v.into()).collect()) + } +} +impl LocationFilesField { + pub fn some(&self, value: Vec) -> LocationWhereParam { + LocationWhereParam::FilesSome(value) + } + pub fn every(&self, value: Vec) -> LocationWhereParam { + LocationWhereParam::FilesEvery(value) + } + pub fn link>(&self, value: Vec) -> T { + LocationLinkFiles(value).into() + } + pub fn unlink(&self, params: Vec) -> LocationSetParam { + LocationSetParam::UnlinkFiles(params) + } + pub fn fetch(&self, params: Vec) -> LocationWith { + LocationWithParam::Files(params).into() + } +} +pub enum LocationWhereParam { + IdLT(i64), + IdGT(i64), + IdLTE(i64), + IdGTE(i64), + IdEquals(i64), + NameContains(String), + NameHasPrefix(String), + NameHasSuffix(String), + NameEquals(String), + PathContains(String), + PathHasPrefix(String), + PathHasSuffix(String), + PathEquals(String), + TotalCapacityLT(i64), + TotalCapacityGT(i64), + TotalCapacityLTE(i64), + TotalCapacityGTE(i64), + TotalCapacityEquals(i64), + AvailableCapacityLT(i64), + AvailableCapacityGT(i64), + AvailableCapacityLTE(i64), + AvailableCapacityGTE(i64), + AvailableCapacityEquals(i64), + IsRemovableEquals(bool), + IsEjectableEquals(bool), + IsRootFilesystemEquals(bool), + IsOnlineEquals(bool), + DateCreatedBefore(chrono::DateTime), + DateCreatedAfter(chrono::DateTime), + DateCreatedBeforeEquals(chrono::DateTime), + DateCreatedAfterEquals(chrono::DateTime), + DateCreatedEquals(chrono::DateTime), + FilesSome(Vec), + FilesEvery(Vec), + Not(Vec), + Or(Vec), + And(Vec), +} +impl LocationWhereParam { + pub fn field(self) -> Field { + match self { + Self::IdLT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdLTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdEquals(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameContains(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasPrefix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasSuffix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameEquals(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PathContains(value) => Field { + name: "path".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PathHasPrefix(value) => Field { + name: "path".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PathHasSuffix(value) => Field { + name: "path".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PathEquals(value) => Field { + name: "path".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalCapacityLT(value) => Field { + name: "total_capacity".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalCapacityGT(value) => Field { + name: "total_capacity".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalCapacityLTE(value) => Field { + name: "total_capacity".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalCapacityGTE(value) => Field { + name: "total_capacity".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalCapacityEquals(value) => Field { + name: "total_capacity".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AvailableCapacityLT(value) => Field { + name: "available_capacity".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AvailableCapacityGT(value) => Field { + name: "available_capacity".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AvailableCapacityLTE(value) => Field { + name: "available_capacity".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AvailableCapacityGTE(value) => Field { + name: "available_capacity".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::AvailableCapacityEquals(value) => Field { + name: "available_capacity".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IsRemovableEquals(value) => Field { + name: "is_removable".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IsEjectableEquals(value) => Field { + name: "is_ejectable".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IsRootFilesystemEquals(value) => Field { + name: "is_root_filesystem".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IsOnlineEquals(value) => Field { + name: "is_online".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBefore(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfter(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBeforeEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfterEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FilesSome(value) => Field { + name: "files".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FilesEvery(value) => Field { + name: "files".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct LocationWith { + pub param: LocationWithParam, +} +pub enum LocationWithParam { + Files(Vec), +} +impl From for LocationWith { + fn from(param: LocationWithParam) -> Self { + Self { param } + } +} +impl LocationWithParam { + pub fn output(self) -> Output { + match self { + Self::Files(where_params) => Output { + name: "files".into(), + outputs: file_outputs(), + inputs: if where_params.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_params.into_iter().map(|f| f.field()).collect(), + ..Default::default() + }] + } else { + vec![] + }, + ..Default::default() + }, + } + } +} +pub enum LocationSetParam { + Id(i64), + Name(String), + Path(String), + TotalCapacity(i64), + AvailableCapacity(i64), + IsRemovable(bool), + IsEjectable(bool), + IsRootFilesystem(bool), + IsOnline(bool), + DateCreated(chrono::DateTime), + LinkFiles(Vec), + UnlinkFiles(Vec), +} +impl LocationSetParam { + pub fn field(self) -> Field { + match self { + Self::Id(value) => Field { + name: "id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Name(value) => Field { + name: "name".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Path(value) => Field { + name: "path".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::TotalCapacity(value) => Field { + name: "total_capacity".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::AvailableCapacity(value) => Field { + name: "available_capacity".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::IsRemovable(value) => Field { + name: "is_removable".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::IsEjectable(value) => Field { + name: "is_ejectable".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::IsRootFilesystem(value) => Field { + name: "is_root_filesystem".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::IsOnline(value) => Field { + name: "is_online".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateCreated(value) => Field { + name: "date_created".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkFiles(where_params) => Field { + name: "files".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + list: true, + wrap_list: true, + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkFiles(where_params) => Field { + name: "files".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + list: true, + wrap_list: true, + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + ..Default::default() + }]), + ..Default::default() + }, + } + } +} +pub struct LocationFindMany<'a> { + query: Query<'a>, +} +impl<'a> LocationFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> LocationDelete<'a> { + LocationDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "Location".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> LocationUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + LocationUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LocationFindFirst<'a> { + query: Query<'a>, +} +impl<'a> LocationFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LocationFindUnique<'a> { + query: Query<'a>, +} +impl<'a> LocationFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> LocationDelete<'a> { + LocationDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "Location".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> LocationUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + LocationUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LocationCreateOne<'a> { + query: Query<'a>, +} +impl<'a> LocationCreateOne<'a> { + pub async fn exec(self) -> LocationData { + self.query.perform::().await.unwrap() + } +} +pub struct LocationUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> LocationUpdateUnique<'a> { + pub async fn exec(self) -> LocationData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LocationUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> LocationUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct LocationDelete<'a> { + query: Query<'a>, +} +impl<'a> LocationDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct LocationActions<'a> { + client: &'a PrismaClient, +} +impl<'a> LocationActions<'a> { + pub fn find_unique(&self, param: LocationWhereParam) -> LocationFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "Location".into(), + outputs: location_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + LocationFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> LocationFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "Location".into(), + outputs: location_outputs(), + inputs, + }; + LocationFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> LocationFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "Location".into(), + outputs: location_outputs(), + inputs, + }; + LocationFindMany { query } + } + pub fn create_one(&self, params: Vec) -> LocationCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "Location".into(), + outputs: location_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + LocationCreateOne { query } + } +} +fn file_outputs() -> Vec { + vec![ + Output::new("id"), + Output::new("is_dir"), + Output::new("location_id"), + Output::new("materialized_path"), + Output::new("name"), + Output::new("extension"), + Output::new("path_integrity_hash"), + Output::new("quick_integrity_hash"), + Output::new("full_integrity_hash"), + Output::new("size_in_bytes"), + Output::new("encryption"), + Output::new("date_created"), + Output::new("date_modified"), + Output::new("date_indexed"), + Output::new("ipfs_id"), + Output::new("parent_id"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FileData { + #[serde(rename = "id")] + pub id: i64, + #[serde(rename = "is_dir")] + pub is_dir: bool, + #[serde(rename = "location_id")] + pub location_id: i64, + #[serde(rename = "materialized_path")] + pub materialized_path: String, + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "extension")] + pub extension: Option, + #[serde(rename = "path_integrity_hash")] + pub path_integrity_hash: String, + #[serde(rename = "quick_integrity_hash")] + pub quick_integrity_hash: Option, + #[serde(rename = "full_integrity_hash")] + pub full_integrity_hash: Option, + #[serde(rename = "size_in_bytes")] + pub size_in_bytes: String, + #[serde(rename = "encryption")] + pub encryption: i64, + #[serde(rename = "date_created")] + pub date_created: chrono::DateTime, + #[serde(rename = "date_modified")] + pub date_modified: chrono::DateTime, + #[serde(rename = "date_indexed")] + pub date_indexed: chrono::DateTime, + #[serde(rename = "ipfs_id")] + pub ipfs_id: Option, + #[serde(rename = "location")] + pub location: Box>, + #[serde(rename = "parent")] + pub parent: Box>, + #[serde(rename = "parent_id")] + pub parent_id: Option, + #[serde(rename = "children")] + children: Option>, + #[serde(rename = "file_tags")] + file_tags: Option>, +} +impl FileData { + pub fn location(&self) -> Option<&LocationData> { + self.location.as_ref().as_ref() + } + pub fn parent(&self) -> Option<&FileData> { + self.parent.as_ref().as_ref() + } + pub fn children(&self) -> Result<&Vec, String> { + match self.children.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access children but did not fetch it using the .with() syntax" + .to_string(), + ), + } + } + pub fn file_tags(&self) -> Result<&Vec, String> { + match self.file_tags.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access file_tags but did not fetch it using the .with() syntax" + .to_string(), + ), + } + } +} +pub struct File; +impl File { + pub fn id() -> FileIdField { + FileIdField {} + } + pub fn is_dir() -> FileIsDirField { + FileIsDirField {} + } + pub fn location_id() -> FileLocationIdField { + FileLocationIdField {} + } + pub fn materialized_path() -> FileMaterializedPathField { + FileMaterializedPathField {} + } + pub fn name() -> FileNameField { + FileNameField {} + } + pub fn extension() -> FileExtensionField { + FileExtensionField {} + } + pub fn path_integrity_hash() -> FilePathIntegrityHashField { + FilePathIntegrityHashField {} + } + pub fn quick_integrity_hash() -> FileQuickIntegrityHashField { + FileQuickIntegrityHashField {} + } + pub fn full_integrity_hash() -> FileFullIntegrityHashField { + FileFullIntegrityHashField {} + } + pub fn size_in_bytes() -> FileSizeInBytesField { + FileSizeInBytesField {} + } + pub fn encryption() -> FileEncryptionField { + FileEncryptionField {} + } + pub fn date_created() -> FileDateCreatedField { + FileDateCreatedField {} + } + pub fn date_modified() -> FileDateModifiedField { + FileDateModifiedField {} + } + pub fn date_indexed() -> FileDateIndexedField { + FileDateIndexedField {} + } + pub fn ipfs_id() -> FileIpfsIdField { + FileIpfsIdField {} + } + pub fn location() -> FileLocationField { + FileLocationField {} + } + pub fn parent() -> FileParentField { + FileParentField {} + } + pub fn parent_id() -> FileParentIdField { + FileParentIdField {} + } + pub fn children() -> FileChildrenField { + FileChildrenField {} + } + pub fn file_tags() -> FileFileTagsField { + FileFileTagsField {} + } + pub fn not(params: Vec) -> FileWhereParam { + FileWhereParam::Not(params) + } + pub fn or(params: Vec) -> FileWhereParam { + FileWhereParam::Or(params) + } + pub fn and(params: Vec) -> FileWhereParam { + FileWhereParam::And(params) + } +} +pub struct FileIdField {} +pub struct FileSetId(i64); +impl From for FileSetParam { + fn from(value: FileSetId) -> Self { + Self::Id(value.0) + } +} +impl FileIdField { + pub fn lt(&self, value: i64) -> FileWhereParam { + FileWhereParam::IdLT(value) + } + pub fn gt(&self, value: i64) -> FileWhereParam { + FileWhereParam::IdGT(value) + } + pub fn lte(&self, value: i64) -> FileWhereParam { + FileWhereParam::IdLTE(value) + } + pub fn gte(&self, value: i64) -> FileWhereParam { + FileWhereParam::IdGTE(value) + } + pub fn equals(&self, value: i64) -> FileWhereParam { + FileWhereParam::IdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + FileSetId(value).into() + } +} +pub struct FileIsDirField {} +pub struct FileSetIsDir(bool); +impl From for FileSetParam { + fn from(value: FileSetIsDir) -> Self { + Self::IsDir(value.0) + } +} +impl FileIsDirField { + pub fn equals(&self, value: bool) -> FileWhereParam { + FileWhereParam::IsDirEquals(value) + } + pub fn set>(&self, value: bool) -> T { + FileSetIsDir(value).into() + } +} +pub struct FileLocationIdField {} +pub struct FileSetLocationId(i64); +impl From for FileSetParam { + fn from(value: FileSetLocationId) -> Self { + Self::LocationId(value.0) + } +} +impl FileLocationIdField { + pub fn lt(&self, value: i64) -> FileWhereParam { + FileWhereParam::LocationIdLT(value) + } + pub fn gt(&self, value: i64) -> FileWhereParam { + FileWhereParam::LocationIdGT(value) + } + pub fn lte(&self, value: i64) -> FileWhereParam { + FileWhereParam::LocationIdLTE(value) + } + pub fn gte(&self, value: i64) -> FileWhereParam { + FileWhereParam::LocationIdGTE(value) + } + pub fn equals(&self, value: i64) -> FileWhereParam { + FileWhereParam::LocationIdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + FileSetLocationId(value).into() + } +} +pub struct FileMaterializedPathField {} +pub struct FileSetMaterializedPath(String); +impl From for FileSetParam { + fn from(value: FileSetMaterializedPath) -> Self { + Self::MaterializedPath(value.0) + } +} +impl FileMaterializedPathField { + pub fn contains(&self, value: String) -> FileWhereParam { + FileWhereParam::MaterializedPathContains(value) + } + pub fn has_prefix(&self, value: String) -> FileWhereParam { + FileWhereParam::MaterializedPathHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> FileWhereParam { + FileWhereParam::MaterializedPathHasSuffix(value) + } + pub fn equals(&self, value: String) -> FileWhereParam { + FileWhereParam::MaterializedPathEquals(value) + } + pub fn set>(&self, value: String) -> T { + FileSetMaterializedPath(value).into() + } +} +pub struct FileNameField {} +pub struct FileSetName(String); +impl From for FileSetParam { + fn from(value: FileSetName) -> Self { + Self::Name(value.0) + } +} +impl FileNameField { + pub fn contains(&self, value: String) -> FileWhereParam { + FileWhereParam::NameContains(value) + } + pub fn has_prefix(&self, value: String) -> FileWhereParam { + FileWhereParam::NameHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> FileWhereParam { + FileWhereParam::NameHasSuffix(value) + } + pub fn equals(&self, value: String) -> FileWhereParam { + FileWhereParam::NameEquals(value) + } + pub fn set>(&self, value: String) -> T { + FileSetName(value).into() + } +} +pub struct FileExtensionField {} +pub struct FileSetExtension(String); +impl From for FileSetParam { + fn from(value: FileSetExtension) -> Self { + Self::Extension(value.0) + } +} +impl FileExtensionField { + pub fn contains(&self, value: String) -> FileWhereParam { + FileWhereParam::ExtensionContains(value) + } + pub fn has_prefix(&self, value: String) -> FileWhereParam { + FileWhereParam::ExtensionHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> FileWhereParam { + FileWhereParam::ExtensionHasSuffix(value) + } + pub fn equals(&self, value: String) -> FileWhereParam { + FileWhereParam::ExtensionEquals(value) + } + pub fn set>(&self, value: String) -> T { + FileSetExtension(value).into() + } +} +pub struct FilePathIntegrityHashField {} +pub struct FileSetPathIntegrityHash(String); +impl From for FileSetParam { + fn from(value: FileSetPathIntegrityHash) -> Self { + Self::PathIntegrityHash(value.0) + } +} +impl FilePathIntegrityHashField { + pub fn contains(&self, value: String) -> FileWhereParam { + FileWhereParam::PathIntegrityHashContains(value) + } + pub fn has_prefix(&self, value: String) -> FileWhereParam { + FileWhereParam::PathIntegrityHashHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> FileWhereParam { + FileWhereParam::PathIntegrityHashHasSuffix(value) + } + pub fn equals(&self, value: String) -> FileWhereParam { + FileWhereParam::PathIntegrityHashEquals(value) + } + pub fn set>(&self, value: String) -> T { + FileSetPathIntegrityHash(value).into() + } +} +pub struct FileQuickIntegrityHashField {} +pub struct FileSetQuickIntegrityHash(String); +impl From for FileSetParam { + fn from(value: FileSetQuickIntegrityHash) -> Self { + Self::QuickIntegrityHash(value.0) + } +} +impl FileQuickIntegrityHashField { + pub fn contains(&self, value: String) -> FileWhereParam { + FileWhereParam::QuickIntegrityHashContains(value) + } + pub fn has_prefix(&self, value: String) -> FileWhereParam { + FileWhereParam::QuickIntegrityHashHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> FileWhereParam { + FileWhereParam::QuickIntegrityHashHasSuffix(value) + } + pub fn equals(&self, value: String) -> FileWhereParam { + FileWhereParam::QuickIntegrityHashEquals(value) + } + pub fn set>(&self, value: String) -> T { + FileSetQuickIntegrityHash(value).into() + } +} +pub struct FileFullIntegrityHashField {} +pub struct FileSetFullIntegrityHash(String); +impl From for FileSetParam { + fn from(value: FileSetFullIntegrityHash) -> Self { + Self::FullIntegrityHash(value.0) + } +} +impl FileFullIntegrityHashField { + pub fn contains(&self, value: String) -> FileWhereParam { + FileWhereParam::FullIntegrityHashContains(value) + } + pub fn has_prefix(&self, value: String) -> FileWhereParam { + FileWhereParam::FullIntegrityHashHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> FileWhereParam { + FileWhereParam::FullIntegrityHashHasSuffix(value) + } + pub fn equals(&self, value: String) -> FileWhereParam { + FileWhereParam::FullIntegrityHashEquals(value) + } + pub fn set>(&self, value: String) -> T { + FileSetFullIntegrityHash(value).into() + } +} +pub struct FileSizeInBytesField {} +pub struct FileSetSizeInBytes(String); +impl From for FileSetParam { + fn from(value: FileSetSizeInBytes) -> Self { + Self::SizeInBytes(value.0) + } +} +impl FileSizeInBytesField { + pub fn contains(&self, value: String) -> FileWhereParam { + FileWhereParam::SizeInBytesContains(value) + } + pub fn has_prefix(&self, value: String) -> FileWhereParam { + FileWhereParam::SizeInBytesHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> FileWhereParam { + FileWhereParam::SizeInBytesHasSuffix(value) + } + pub fn equals(&self, value: String) -> FileWhereParam { + FileWhereParam::SizeInBytesEquals(value) + } + pub fn set>(&self, value: String) -> T { + FileSetSizeInBytes(value).into() + } +} +pub struct FileEncryptionField {} +pub struct FileSetEncryption(i64); +impl From for FileSetParam { + fn from(value: FileSetEncryption) -> Self { + Self::Encryption(value.0) + } +} +impl FileEncryptionField { + pub fn lt(&self, value: i64) -> FileWhereParam { + FileWhereParam::EncryptionLT(value) + } + pub fn gt(&self, value: i64) -> FileWhereParam { + FileWhereParam::EncryptionGT(value) + } + pub fn lte(&self, value: i64) -> FileWhereParam { + FileWhereParam::EncryptionLTE(value) + } + pub fn gte(&self, value: i64) -> FileWhereParam { + FileWhereParam::EncryptionGTE(value) + } + pub fn equals(&self, value: i64) -> FileWhereParam { + FileWhereParam::EncryptionEquals(value) + } + pub fn set>(&self, value: i64) -> T { + FileSetEncryption(value).into() + } +} +pub struct FileDateCreatedField {} +pub struct FileSetDateCreated(chrono::DateTime); +impl From for FileSetParam { + fn from(value: FileSetDateCreated) -> Self { + Self::DateCreated(value.0) + } +} +impl FileDateCreatedField { + pub fn before(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateCreatedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateCreatedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateCreatedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateCreatedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateCreatedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + FileSetDateCreated(value).into() + } +} +pub struct FileDateModifiedField {} +pub struct FileSetDateModified(chrono::DateTime); +impl From for FileSetParam { + fn from(value: FileSetDateModified) -> Self { + Self::DateModified(value.0) + } +} +impl FileDateModifiedField { + pub fn before(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateModifiedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateModifiedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateModifiedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateModifiedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateModifiedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + FileSetDateModified(value).into() + } +} +pub struct FileDateIndexedField {} +pub struct FileSetDateIndexed(chrono::DateTime); +impl From for FileSetParam { + fn from(value: FileSetDateIndexed) -> Self { + Self::DateIndexed(value.0) + } +} +impl FileDateIndexedField { + pub fn before(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateIndexedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateIndexedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateIndexedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateIndexedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> FileWhereParam { + FileWhereParam::DateIndexedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + FileSetDateIndexed(value).into() + } +} +pub struct FileIpfsIdField {} +pub struct FileSetIpfsId(String); +impl From for FileSetParam { + fn from(value: FileSetIpfsId) -> Self { + Self::IpfsId(value.0) + } +} +impl FileIpfsIdField { + pub fn contains(&self, value: String) -> FileWhereParam { + FileWhereParam::IpfsIdContains(value) + } + pub fn has_prefix(&self, value: String) -> FileWhereParam { + FileWhereParam::IpfsIdHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> FileWhereParam { + FileWhereParam::IpfsIdHasSuffix(value) + } + pub fn equals(&self, value: String) -> FileWhereParam { + FileWhereParam::IpfsIdEquals(value) + } + pub fn set>(&self, value: String) -> T { + FileSetIpfsId(value).into() + } +} +pub struct FileLocationField {} +pub struct FileLinkLocation(LocationWhereParam); +impl From for FileSetParam { + fn from(value: FileLinkLocation) -> Self { + Self::LinkLocation(value.0) + } +} +impl FileLocationField { + pub fn is(&self, value: Vec) -> FileWhereParam { + FileWhereParam::LocationIs(value) + } + pub fn link>(&self, value: LocationWhereParam) -> T { + FileLinkLocation(value).into() + } + pub fn fetch(&self) -> FileWith { + FileWithParam::Location.into() + } + pub fn unlink(&self) -> FileSetParam { + FileSetParam::UnlinkLocation + } +} +pub struct FileParentField {} +pub struct FileLinkParent(FileWhereParam); +impl From for FileSetParam { + fn from(value: FileLinkParent) -> Self { + Self::LinkParent(value.0) + } +} +impl FileParentField { + pub fn is(&self, value: Vec) -> FileWhereParam { + FileWhereParam::ParentIs(value) + } + pub fn link>(&self, value: FileWhereParam) -> T { + FileLinkParent(value).into() + } + pub fn fetch(&self) -> FileWith { + FileWithParam::Parent.into() + } + pub fn unlink(&self) -> FileSetParam { + FileSetParam::UnlinkParent + } +} +pub struct FileParentIdField {} +pub struct FileSetParentId(i64); +impl From for FileSetParam { + fn from(value: FileSetParentId) -> Self { + Self::ParentId(value.0) + } +} +impl FileParentIdField { + pub fn lt(&self, value: i64) -> FileWhereParam { + FileWhereParam::ParentIdLT(value) + } + pub fn gt(&self, value: i64) -> FileWhereParam { + FileWhereParam::ParentIdGT(value) + } + pub fn lte(&self, value: i64) -> FileWhereParam { + FileWhereParam::ParentIdLTE(value) + } + pub fn gte(&self, value: i64) -> FileWhereParam { + FileWhereParam::ParentIdGTE(value) + } + pub fn equals(&self, value: i64) -> FileWhereParam { + FileWhereParam::ParentIdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + FileSetParentId(value).into() + } +} +pub struct FileChildrenField {} +pub struct FileLinkChildren(Vec); +impl From for FileSetParam { + fn from(value: FileLinkChildren) -> Self { + Self::LinkChildren(value.0.into_iter().map(|v| v.into()).collect()) + } +} +impl FileChildrenField { + pub fn some(&self, value: Vec) -> FileWhereParam { + FileWhereParam::ChildrenSome(value) + } + pub fn every(&self, value: Vec) -> FileWhereParam { + FileWhereParam::ChildrenEvery(value) + } + pub fn link>(&self, value: Vec) -> T { + FileLinkChildren(value).into() + } + pub fn unlink(&self, params: Vec) -> FileSetParam { + FileSetParam::UnlinkChildren(params) + } + pub fn fetch(&self, params: Vec) -> FileWith { + FileWithParam::Children(params).into() + } +} +pub struct FileFileTagsField {} +pub struct FileLinkFileTags(Vec); +impl From for FileSetParam { + fn from(value: FileLinkFileTags) -> Self { + Self::LinkFileTags(value.0.into_iter().map(|v| v.into()).collect()) + } +} +impl FileFileTagsField { + pub fn some(&self, value: Vec) -> FileWhereParam { + FileWhereParam::FileTagsSome(value) + } + pub fn every(&self, value: Vec) -> FileWhereParam { + FileWhereParam::FileTagsEvery(value) + } + pub fn link>(&self, value: Vec) -> T { + FileLinkFileTags(value).into() + } + pub fn unlink(&self, params: Vec) -> FileSetParam { + FileSetParam::UnlinkFileTags(params) + } + pub fn fetch(&self, params: Vec) -> FileWith { + FileWithParam::FileTags(params).into() + } +} +pub enum FileWhereParam { + IdLT(i64), + IdGT(i64), + IdLTE(i64), + IdGTE(i64), + IdEquals(i64), + IsDirEquals(bool), + LocationIdLT(i64), + LocationIdGT(i64), + LocationIdLTE(i64), + LocationIdGTE(i64), + LocationIdEquals(i64), + MaterializedPathContains(String), + MaterializedPathHasPrefix(String), + MaterializedPathHasSuffix(String), + MaterializedPathEquals(String), + NameContains(String), + NameHasPrefix(String), + NameHasSuffix(String), + NameEquals(String), + ExtensionContains(String), + ExtensionHasPrefix(String), + ExtensionHasSuffix(String), + ExtensionEquals(String), + PathIntegrityHashContains(String), + PathIntegrityHashHasPrefix(String), + PathIntegrityHashHasSuffix(String), + PathIntegrityHashEquals(String), + QuickIntegrityHashContains(String), + QuickIntegrityHashHasPrefix(String), + QuickIntegrityHashHasSuffix(String), + QuickIntegrityHashEquals(String), + FullIntegrityHashContains(String), + FullIntegrityHashHasPrefix(String), + FullIntegrityHashHasSuffix(String), + FullIntegrityHashEquals(String), + SizeInBytesContains(String), + SizeInBytesHasPrefix(String), + SizeInBytesHasSuffix(String), + SizeInBytesEquals(String), + EncryptionLT(i64), + EncryptionGT(i64), + EncryptionLTE(i64), + EncryptionGTE(i64), + EncryptionEquals(i64), + DateCreatedBefore(chrono::DateTime), + DateCreatedAfter(chrono::DateTime), + DateCreatedBeforeEquals(chrono::DateTime), + DateCreatedAfterEquals(chrono::DateTime), + DateCreatedEquals(chrono::DateTime), + DateModifiedBefore(chrono::DateTime), + DateModifiedAfter(chrono::DateTime), + DateModifiedBeforeEquals(chrono::DateTime), + DateModifiedAfterEquals(chrono::DateTime), + DateModifiedEquals(chrono::DateTime), + DateIndexedBefore(chrono::DateTime), + DateIndexedAfter(chrono::DateTime), + DateIndexedBeforeEquals(chrono::DateTime), + DateIndexedAfterEquals(chrono::DateTime), + DateIndexedEquals(chrono::DateTime), + IpfsIdContains(String), + IpfsIdHasPrefix(String), + IpfsIdHasSuffix(String), + IpfsIdEquals(String), + LocationIs(Vec), + ParentIs(Vec), + ParentIdLT(i64), + ParentIdGT(i64), + ParentIdLTE(i64), + ParentIdGTE(i64), + ParentIdEquals(i64), + ChildrenSome(Vec), + ChildrenEvery(Vec), + FileTagsSome(Vec), + FileTagsEvery(Vec), + Not(Vec), + Or(Vec), + And(Vec), +} +impl FileWhereParam { + pub fn field(self) -> Field { + match self { + Self::IdLT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdLTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdEquals(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IsDirEquals(value) => Field { + name: "is_dir".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LocationIdLT(value) => Field { + name: "location_id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LocationIdGT(value) => Field { + name: "location_id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LocationIdLTE(value) => Field { + name: "location_id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LocationIdGTE(value) => Field { + name: "location_id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LocationIdEquals(value) => Field { + name: "location_id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::MaterializedPathContains(value) => Field { + name: "materialized_path".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::MaterializedPathHasPrefix(value) => Field { + name: "materialized_path".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::MaterializedPathHasSuffix(value) => Field { + name: "materialized_path".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::MaterializedPathEquals(value) => Field { + name: "materialized_path".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameContains(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasPrefix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasSuffix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameEquals(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ExtensionContains(value) => Field { + name: "extension".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ExtensionHasPrefix(value) => Field { + name: "extension".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ExtensionHasSuffix(value) => Field { + name: "extension".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ExtensionEquals(value) => Field { + name: "extension".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PathIntegrityHashContains(value) => Field { + name: "path_integrity_hash".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PathIntegrityHashHasPrefix(value) => Field { + name: "path_integrity_hash".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PathIntegrityHashHasSuffix(value) => Field { + name: "path_integrity_hash".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PathIntegrityHashEquals(value) => Field { + name: "path_integrity_hash".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::QuickIntegrityHashContains(value) => Field { + name: "quick_integrity_hash".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::QuickIntegrityHashHasPrefix(value) => Field { + name: "quick_integrity_hash".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::QuickIntegrityHashHasSuffix(value) => Field { + name: "quick_integrity_hash".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::QuickIntegrityHashEquals(value) => Field { + name: "quick_integrity_hash".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FullIntegrityHashContains(value) => Field { + name: "full_integrity_hash".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FullIntegrityHashHasPrefix(value) => Field { + name: "full_integrity_hash".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FullIntegrityHashHasSuffix(value) => Field { + name: "full_integrity_hash".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FullIntegrityHashEquals(value) => Field { + name: "full_integrity_hash".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::SizeInBytesContains(value) => Field { + name: "size_in_bytes".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::SizeInBytesHasPrefix(value) => Field { + name: "size_in_bytes".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::SizeInBytesHasSuffix(value) => Field { + name: "size_in_bytes".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::SizeInBytesEquals(value) => Field { + name: "size_in_bytes".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionLT(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionGT(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionLTE(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionGTE(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionEquals(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBefore(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfter(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBeforeEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfterEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedBefore(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedAfter(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedBeforeEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedAfterEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateIndexedBefore(value) => Field { + name: "date_indexed".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateIndexedAfter(value) => Field { + name: "date_indexed".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateIndexedBeforeEquals(value) => Field { + name: "date_indexed".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateIndexedAfterEquals(value) => Field { + name: "date_indexed".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateIndexedEquals(value) => Field { + name: "date_indexed".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IpfsIdContains(value) => Field { + name: "ipfs_id".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IpfsIdHasPrefix(value) => Field { + name: "ipfs_id".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IpfsIdHasSuffix(value) => Field { + name: "ipfs_id".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IpfsIdEquals(value) => Field { + name: "ipfs_id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LocationIs(value) => Field { + name: "location".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ParentIs(value) => Field { + name: "parent".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ParentIdLT(value) => Field { + name: "parent_id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ParentIdGT(value) => Field { + name: "parent_id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ParentIdLTE(value) => Field { + name: "parent_id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ParentIdGTE(value) => Field { + name: "parent_id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ParentIdEquals(value) => Field { + name: "parent_id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ChildrenSome(value) => Field { + name: "children".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ChildrenEvery(value) => Field { + name: "children".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileTagsSome(value) => Field { + name: "file_tags".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileTagsEvery(value) => Field { + name: "file_tags".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct FileWith { + pub param: FileWithParam, +} +pub enum FileWithParam { + Location, + Parent, + Children(Vec), + FileTags(Vec), +} +impl From for FileWith { + fn from(param: FileWithParam) -> Self { + Self { param } + } +} +impl FileWithParam { + pub fn output(self) -> Output { + match self { + Self::Location => Output { + name: "location".into(), + outputs: location_outputs(), + ..Default::default() + }, + Self::Parent => Output { + name: "parent".into(), + outputs: file_outputs(), + ..Default::default() + }, + Self::Children(where_params) => Output { + name: "children".into(), + outputs: file_outputs(), + inputs: if where_params.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_params.into_iter().map(|f| f.field()).collect(), + ..Default::default() + }] + } else { + vec![] + }, + ..Default::default() + }, + Self::FileTags(where_params) => Output { + name: "file_tags".into(), + outputs: tag_on_file_outputs(), + inputs: if where_params.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_params.into_iter().map(|f| f.field()).collect(), + ..Default::default() + }] + } else { + vec![] + }, + ..Default::default() + }, + } + } +} +pub enum FileSetParam { + Id(i64), + IsDir(bool), + LocationId(i64), + MaterializedPath(String), + Name(String), + Extension(String), + PathIntegrityHash(String), + QuickIntegrityHash(String), + FullIntegrityHash(String), + SizeInBytes(String), + Encryption(i64), + DateCreated(chrono::DateTime), + DateModified(chrono::DateTime), + DateIndexed(chrono::DateTime), + IpfsId(String), + LinkLocation(LocationWhereParam), + UnlinkLocation, + LinkParent(FileWhereParam), + UnlinkParent, + ParentId(i64), + LinkChildren(Vec), + UnlinkChildren(Vec), + LinkFileTags(Vec), + UnlinkFileTags(Vec), +} +impl FileSetParam { + pub fn field(self) -> Field { + match self { + Self::Id(value) => Field { + name: "id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::IsDir(value) => Field { + name: "is_dir".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LocationId(value) => Field { + name: "location_id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::MaterializedPath(value) => Field { + name: "materialized_path".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Name(value) => Field { + name: "name".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Extension(value) => Field { + name: "extension".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::PathIntegrityHash(value) => Field { + name: "path_integrity_hash".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::QuickIntegrityHash(value) => Field { + name: "quick_integrity_hash".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::FullIntegrityHash(value) => Field { + name: "full_integrity_hash".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::SizeInBytes(value) => Field { + name: "size_in_bytes".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Encryption(value) => Field { + name: "encryption".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateCreated(value) => Field { + name: "date_created".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateModified(value) => Field { + name: "date_modified".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateIndexed(value) => Field { + name: "date_indexed".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::IpfsId(value) => Field { + name: "ipfs_id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkLocation(where_param) => Field { + name: "location".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals(vec![where_param.field()])), + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkLocation => Field { + name: "location".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + value: Some(true.into()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LinkParent(where_param) => Field { + name: "parent".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals(vec![where_param.field()])), + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkParent => Field { + name: "parent".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + value: Some(true.into()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ParentId(value) => Field { + name: "parent_id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkChildren(where_params) => Field { + name: "children".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + list: true, + wrap_list: true, + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkChildren(where_params) => Field { + name: "children".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + list: true, + wrap_list: true, + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + ..Default::default() + }]), + ..Default::default() + }, + Self::LinkFileTags(where_params) => Field { + name: "file_tags".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + list: true, + wrap_list: true, + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkFileTags(where_params) => Field { + name: "file_tags".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + list: true, + wrap_list: true, + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + ..Default::default() + }]), + ..Default::default() + }, + } + } +} +pub struct FileFindMany<'a> { + query: Query<'a>, +} +impl<'a> FileFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> FileDelete<'a> { + FileDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "File".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> FileUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + FileUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct FileFindFirst<'a> { + query: Query<'a>, +} +impl<'a> FileFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct FileFindUnique<'a> { + query: Query<'a>, +} +impl<'a> FileFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> FileDelete<'a> { + FileDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "File".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> FileUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + FileUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct FileCreateOne<'a> { + query: Query<'a>, +} +impl<'a> FileCreateOne<'a> { + pub async fn exec(self) -> FileData { + self.query.perform::().await.unwrap() + } +} +pub struct FileUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> FileUpdateUnique<'a> { + pub async fn exec(self) -> FileData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct FileUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> FileUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct FileDelete<'a> { + query: Query<'a>, +} +impl<'a> FileDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct FileActions<'a> { + client: &'a PrismaClient, +} +impl<'a> FileActions<'a> { + pub fn find_unique(&self, param: FileWhereParam) -> FileFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "File".into(), + outputs: file_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + FileFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> FileFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "File".into(), + outputs: file_outputs(), + inputs, + }; + FileFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> FileFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "File".into(), + outputs: file_outputs(), + inputs, + }; + FileFindMany { query } + } + pub fn create_one( + &self, + materialized_path: FileSetMaterializedPath, + name: FileSetName, + path_integrity_hash: FileSetPathIntegrityHash, + size_in_bytes: FileSetSizeInBytes, + params: Vec, + ) -> FileCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + input_fields.push(FileSetParam::from(materialized_path).field()); + input_fields.push(FileSetParam::from(name).field()); + input_fields.push(FileSetParam::from(path_integrity_hash).field()); + input_fields.push(FileSetParam::from(size_in_bytes).field()); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "File".into(), + outputs: file_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + FileCreateOne { query } + } +} +fn tag_outputs() -> Vec { + vec![ + Output::new("id"), + Output::new("name"), + Output::new("encryption"), + Output::new("total_files"), + Output::new("redundancy_goal"), + Output::new("date_created"), + Output::new("date_modified"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TagData { + #[serde(rename = "id")] + pub id: i64, + #[serde(rename = "name")] + pub name: Option, + #[serde(rename = "encryption")] + pub encryption: Option, + #[serde(rename = "total_files")] + pub total_files: Option, + #[serde(rename = "redundancy_goal")] + pub redundancy_goal: Option, + #[serde(rename = "date_created")] + pub date_created: chrono::DateTime, + #[serde(rename = "date_modified")] + pub date_modified: chrono::DateTime, + #[serde(rename = "tag_files")] + tag_files: Option>, +} +impl TagData { + pub fn tag_files(&self) -> Result<&Vec, String> { + match self.tag_files.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access tag_files but did not fetch it using the .with() syntax" + .to_string(), + ), + } + } +} +pub struct Tag; +impl Tag { + pub fn id() -> TagIdField { + TagIdField {} + } + pub fn name() -> TagNameField { + TagNameField {} + } + pub fn encryption() -> TagEncryptionField { + TagEncryptionField {} + } + pub fn total_files() -> TagTotalFilesField { + TagTotalFilesField {} + } + pub fn redundancy_goal() -> TagRedundancyGoalField { + TagRedundancyGoalField {} + } + pub fn date_created() -> TagDateCreatedField { + TagDateCreatedField {} + } + pub fn date_modified() -> TagDateModifiedField { + TagDateModifiedField {} + } + pub fn tag_files() -> TagTagFilesField { + TagTagFilesField {} + } + pub fn not(params: Vec) -> TagWhereParam { + TagWhereParam::Not(params) + } + pub fn or(params: Vec) -> TagWhereParam { + TagWhereParam::Or(params) + } + pub fn and(params: Vec) -> TagWhereParam { + TagWhereParam::And(params) + } +} +pub struct TagIdField {} +pub struct TagSetId(i64); +impl From for TagSetParam { + fn from(value: TagSetId) -> Self { + Self::Id(value.0) + } +} +impl TagIdField { + pub fn lt(&self, value: i64) -> TagWhereParam { + TagWhereParam::IdLT(value) + } + pub fn gt(&self, value: i64) -> TagWhereParam { + TagWhereParam::IdGT(value) + } + pub fn lte(&self, value: i64) -> TagWhereParam { + TagWhereParam::IdLTE(value) + } + pub fn gte(&self, value: i64) -> TagWhereParam { + TagWhereParam::IdGTE(value) + } + pub fn equals(&self, value: i64) -> TagWhereParam { + TagWhereParam::IdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + TagSetId(value).into() + } +} +pub struct TagNameField {} +pub struct TagSetName(String); +impl From for TagSetParam { + fn from(value: TagSetName) -> Self { + Self::Name(value.0) + } +} +impl TagNameField { + pub fn contains(&self, value: String) -> TagWhereParam { + TagWhereParam::NameContains(value) + } + pub fn has_prefix(&self, value: String) -> TagWhereParam { + TagWhereParam::NameHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> TagWhereParam { + TagWhereParam::NameHasSuffix(value) + } + pub fn equals(&self, value: String) -> TagWhereParam { + TagWhereParam::NameEquals(value) + } + pub fn set>(&self, value: String) -> T { + TagSetName(value).into() + } +} +pub struct TagEncryptionField {} +pub struct TagSetEncryption(i64); +impl From for TagSetParam { + fn from(value: TagSetEncryption) -> Self { + Self::Encryption(value.0) + } +} +impl TagEncryptionField { + pub fn lt(&self, value: i64) -> TagWhereParam { + TagWhereParam::EncryptionLT(value) + } + pub fn gt(&self, value: i64) -> TagWhereParam { + TagWhereParam::EncryptionGT(value) + } + pub fn lte(&self, value: i64) -> TagWhereParam { + TagWhereParam::EncryptionLTE(value) + } + pub fn gte(&self, value: i64) -> TagWhereParam { + TagWhereParam::EncryptionGTE(value) + } + pub fn equals(&self, value: i64) -> TagWhereParam { + TagWhereParam::EncryptionEquals(value) + } + pub fn set>(&self, value: i64) -> T { + TagSetEncryption(value).into() + } +} +pub struct TagTotalFilesField {} +pub struct TagSetTotalFiles(i64); +impl From for TagSetParam { + fn from(value: TagSetTotalFiles) -> Self { + Self::TotalFiles(value.0) + } +} +impl TagTotalFilesField { + pub fn lt(&self, value: i64) -> TagWhereParam { + TagWhereParam::TotalFilesLT(value) + } + pub fn gt(&self, value: i64) -> TagWhereParam { + TagWhereParam::TotalFilesGT(value) + } + pub fn lte(&self, value: i64) -> TagWhereParam { + TagWhereParam::TotalFilesLTE(value) + } + pub fn gte(&self, value: i64) -> TagWhereParam { + TagWhereParam::TotalFilesGTE(value) + } + pub fn equals(&self, value: i64) -> TagWhereParam { + TagWhereParam::TotalFilesEquals(value) + } + pub fn set>(&self, value: i64) -> T { + TagSetTotalFiles(value).into() + } +} +pub struct TagRedundancyGoalField {} +pub struct TagSetRedundancyGoal(i64); +impl From for TagSetParam { + fn from(value: TagSetRedundancyGoal) -> Self { + Self::RedundancyGoal(value.0) + } +} +impl TagRedundancyGoalField { + pub fn lt(&self, value: i64) -> TagWhereParam { + TagWhereParam::RedundancyGoalLT(value) + } + pub fn gt(&self, value: i64) -> TagWhereParam { + TagWhereParam::RedundancyGoalGT(value) + } + pub fn lte(&self, value: i64) -> TagWhereParam { + TagWhereParam::RedundancyGoalLTE(value) + } + pub fn gte(&self, value: i64) -> TagWhereParam { + TagWhereParam::RedundancyGoalGTE(value) + } + pub fn equals(&self, value: i64) -> TagWhereParam { + TagWhereParam::RedundancyGoalEquals(value) + } + pub fn set>(&self, value: i64) -> T { + TagSetRedundancyGoal(value).into() + } +} +pub struct TagDateCreatedField {} +pub struct TagSetDateCreated(chrono::DateTime); +impl From for TagSetParam { + fn from(value: TagSetDateCreated) -> Self { + Self::DateCreated(value.0) + } +} +impl TagDateCreatedField { + pub fn before(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateCreatedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateCreatedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateCreatedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateCreatedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateCreatedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + TagSetDateCreated(value).into() + } +} +pub struct TagDateModifiedField {} +pub struct TagSetDateModified(chrono::DateTime); +impl From for TagSetParam { + fn from(value: TagSetDateModified) -> Self { + Self::DateModified(value.0) + } +} +impl TagDateModifiedField { + pub fn before(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateModifiedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateModifiedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateModifiedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateModifiedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> TagWhereParam { + TagWhereParam::DateModifiedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + TagSetDateModified(value).into() + } +} +pub struct TagTagFilesField {} +pub struct TagLinkTagFiles(Vec); +impl From for TagSetParam { + fn from(value: TagLinkTagFiles) -> Self { + Self::LinkTagFiles(value.0.into_iter().map(|v| v.into()).collect()) + } +} +impl TagTagFilesField { + pub fn some(&self, value: Vec) -> TagWhereParam { + TagWhereParam::TagFilesSome(value) + } + pub fn every(&self, value: Vec) -> TagWhereParam { + TagWhereParam::TagFilesEvery(value) + } + pub fn link>(&self, value: Vec) -> T { + TagLinkTagFiles(value).into() + } + pub fn unlink(&self, params: Vec) -> TagSetParam { + TagSetParam::UnlinkTagFiles(params) + } + pub fn fetch(&self, params: Vec) -> TagWith { + TagWithParam::TagFiles(params).into() + } +} +pub enum TagWhereParam { + IdLT(i64), + IdGT(i64), + IdLTE(i64), + IdGTE(i64), + IdEquals(i64), + NameContains(String), + NameHasPrefix(String), + NameHasSuffix(String), + NameEquals(String), + EncryptionLT(i64), + EncryptionGT(i64), + EncryptionLTE(i64), + EncryptionGTE(i64), + EncryptionEquals(i64), + TotalFilesLT(i64), + TotalFilesGT(i64), + TotalFilesLTE(i64), + TotalFilesGTE(i64), + TotalFilesEquals(i64), + RedundancyGoalLT(i64), + RedundancyGoalGT(i64), + RedundancyGoalLTE(i64), + RedundancyGoalGTE(i64), + RedundancyGoalEquals(i64), + DateCreatedBefore(chrono::DateTime), + DateCreatedAfter(chrono::DateTime), + DateCreatedBeforeEquals(chrono::DateTime), + DateCreatedAfterEquals(chrono::DateTime), + DateCreatedEquals(chrono::DateTime), + DateModifiedBefore(chrono::DateTime), + DateModifiedAfter(chrono::DateTime), + DateModifiedBeforeEquals(chrono::DateTime), + DateModifiedAfterEquals(chrono::DateTime), + DateModifiedEquals(chrono::DateTime), + TagFilesSome(Vec), + TagFilesEvery(Vec), + Not(Vec), + Or(Vec), + And(Vec), +} +impl TagWhereParam { + pub fn field(self) -> Field { + match self { + Self::IdLT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdLTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdEquals(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameContains(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasPrefix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasSuffix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameEquals(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionLT(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionGT(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionLTE(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionGTE(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionEquals(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFilesLT(value) => Field { + name: "total_files".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFilesGT(value) => Field { + name: "total_files".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFilesLTE(value) => Field { + name: "total_files".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFilesGTE(value) => Field { + name: "total_files".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TotalFilesEquals(value) => Field { + name: "total_files".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RedundancyGoalLT(value) => Field { + name: "redundancy_goal".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RedundancyGoalGT(value) => Field { + name: "redundancy_goal".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RedundancyGoalLTE(value) => Field { + name: "redundancy_goal".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RedundancyGoalGTE(value) => Field { + name: "redundancy_goal".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::RedundancyGoalEquals(value) => Field { + name: "redundancy_goal".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBefore(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfter(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBeforeEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfterEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedBefore(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedAfter(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedBeforeEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedAfterEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TagFilesSome(value) => Field { + name: "tag_files".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TagFilesEvery(value) => Field { + name: "tag_files".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct TagWith { + pub param: TagWithParam, +} +pub enum TagWithParam { + TagFiles(Vec), +} +impl From for TagWith { + fn from(param: TagWithParam) -> Self { + Self { param } + } +} +impl TagWithParam { + pub fn output(self) -> Output { + match self { + Self::TagFiles(where_params) => Output { + name: "tag_files".into(), + outputs: tag_on_file_outputs(), + inputs: if where_params.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_params.into_iter().map(|f| f.field()).collect(), + ..Default::default() + }] + } else { + vec![] + }, + ..Default::default() + }, + } + } +} +pub enum TagSetParam { + Id(i64), + Name(String), + Encryption(i64), + TotalFiles(i64), + RedundancyGoal(i64), + DateCreated(chrono::DateTime), + DateModified(chrono::DateTime), + LinkTagFiles(Vec), + UnlinkTagFiles(Vec), +} +impl TagSetParam { + pub fn field(self) -> Field { + match self { + Self::Id(value) => Field { + name: "id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Name(value) => Field { + name: "name".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Encryption(value) => Field { + name: "encryption".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::TotalFiles(value) => Field { + name: "total_files".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::RedundancyGoal(value) => Field { + name: "redundancy_goal".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateCreated(value) => Field { + name: "date_created".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateModified(value) => Field { + name: "date_modified".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkTagFiles(where_params) => Field { + name: "tag_files".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + list: true, + wrap_list: true, + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkTagFiles(where_params) => Field { + name: "tag_files".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + list: true, + wrap_list: true, + fields: Some(transform_equals( + where_params.into_iter().map(|item| item.field()).collect(), + )), + ..Default::default() + }]), + ..Default::default() + }, + } + } +} +pub struct TagFindMany<'a> { + query: Query<'a>, +} +impl<'a> TagFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> TagDelete<'a> { + TagDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "Tag".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> TagUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + TagUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagFindFirst<'a> { + query: Query<'a>, +} +impl<'a> TagFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagFindUnique<'a> { + query: Query<'a>, +} +impl<'a> TagFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> TagDelete<'a> { + TagDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "Tag".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> TagUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + TagUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagCreateOne<'a> { + query: Query<'a>, +} +impl<'a> TagCreateOne<'a> { + pub async fn exec(self) -> TagData { + self.query.perform::().await.unwrap() + } +} +pub struct TagUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> TagUpdateUnique<'a> { + pub async fn exec(self) -> TagData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> TagUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagDelete<'a> { + query: Query<'a>, +} +impl<'a> TagDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct TagActions<'a> { + client: &'a PrismaClient, +} +impl<'a> TagActions<'a> { + pub fn find_unique(&self, param: TagWhereParam) -> TagFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "Tag".into(), + outputs: tag_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + TagFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> TagFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "Tag".into(), + outputs: tag_outputs(), + inputs, + }; + TagFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> TagFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "Tag".into(), + outputs: tag_outputs(), + inputs, + }; + TagFindMany { query } + } + pub fn create_one(&self, params: Vec) -> TagCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "Tag".into(), + outputs: tag_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + TagCreateOne { query } + } +} +fn tag_on_file_outputs() -> Vec { + vec![ + Output::new("date_created"), + Output::new("tag_id"), + Output::new("file_id"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TagOnFileData { + #[serde(rename = "date_created")] + pub date_created: chrono::DateTime, + #[serde(rename = "tag_id")] + pub tag_id: i64, + #[serde(rename = "tag")] + tag: Box>, + #[serde(rename = "file_id")] + pub file_id: i64, + #[serde(rename = "file")] + file: Box>, +} +impl TagOnFileData { + pub fn tag(&self) -> Result<&TagData, String> { + match self.tag.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access tag but did not fetch it using the .with() syntax".to_string(), + ), + } + } + pub fn file(&self) -> Result<&FileData, String> { + match self.file.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access file but did not fetch it using the .with() syntax" + .to_string(), + ), + } + } +} +pub struct TagOnFile; +impl TagOnFile { + pub fn date_created() -> TagOnFileDateCreatedField { + TagOnFileDateCreatedField {} + } + pub fn tag_id() -> TagOnFileTagIdField { + TagOnFileTagIdField {} + } + pub fn tag() -> TagOnFileTagField { + TagOnFileTagField {} + } + pub fn file_id() -> TagOnFileFileIdField { + TagOnFileFileIdField {} + } + pub fn file() -> TagOnFileFileField { + TagOnFileFileField {} + } + pub fn not(params: Vec) -> TagOnFileWhereParam { + TagOnFileWhereParam::Not(params) + } + pub fn or(params: Vec) -> TagOnFileWhereParam { + TagOnFileWhereParam::Or(params) + } + pub fn and(params: Vec) -> TagOnFileWhereParam { + TagOnFileWhereParam::And(params) + } +} +pub struct TagOnFileDateCreatedField {} +pub struct TagOnFileSetDateCreated(chrono::DateTime); +impl From for TagOnFileSetParam { + fn from(value: TagOnFileSetDateCreated) -> Self { + Self::DateCreated(value.0) + } +} +impl TagOnFileDateCreatedField { + pub fn before(&self, value: chrono::DateTime) -> TagOnFileWhereParam { + TagOnFileWhereParam::DateCreatedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> TagOnFileWhereParam { + TagOnFileWhereParam::DateCreatedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> TagOnFileWhereParam { + TagOnFileWhereParam::DateCreatedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> TagOnFileWhereParam { + TagOnFileWhereParam::DateCreatedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> TagOnFileWhereParam { + TagOnFileWhereParam::DateCreatedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + TagOnFileSetDateCreated(value).into() + } +} +pub struct TagOnFileTagIdField {} +pub struct TagOnFileSetTagId(i64); +impl From for TagOnFileSetParam { + fn from(value: TagOnFileSetTagId) -> Self { + Self::TagId(value.0) + } +} +impl TagOnFileTagIdField { + pub fn lt(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::TagIdLT(value) + } + pub fn gt(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::TagIdGT(value) + } + pub fn lte(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::TagIdLTE(value) + } + pub fn gte(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::TagIdGTE(value) + } + pub fn equals(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::TagIdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + TagOnFileSetTagId(value).into() + } +} +pub struct TagOnFileTagField {} +pub struct TagOnFileLinkTag(TagWhereParam); +impl From for TagOnFileSetParam { + fn from(value: TagOnFileLinkTag) -> Self { + Self::LinkTag(value.0) + } +} +impl TagOnFileTagField { + pub fn is(&self, value: Vec) -> TagOnFileWhereParam { + TagOnFileWhereParam::TagIs(value) + } + pub fn link>(&self, value: TagWhereParam) -> T { + TagOnFileLinkTag(value).into() + } + pub fn fetch(&self) -> TagOnFileWith { + TagOnFileWithParam::Tag.into() + } +} +pub struct TagOnFileFileIdField {} +pub struct TagOnFileSetFileId(i64); +impl From for TagOnFileSetParam { + fn from(value: TagOnFileSetFileId) -> Self { + Self::FileId(value.0) + } +} +impl TagOnFileFileIdField { + pub fn lt(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::FileIdLT(value) + } + pub fn gt(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::FileIdGT(value) + } + pub fn lte(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::FileIdLTE(value) + } + pub fn gte(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::FileIdGTE(value) + } + pub fn equals(&self, value: i64) -> TagOnFileWhereParam { + TagOnFileWhereParam::FileIdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + TagOnFileSetFileId(value).into() + } +} +pub struct TagOnFileFileField {} +pub struct TagOnFileLinkFile(FileWhereParam); +impl From for TagOnFileSetParam { + fn from(value: TagOnFileLinkFile) -> Self { + Self::LinkFile(value.0) + } +} +impl TagOnFileFileField { + pub fn is(&self, value: Vec) -> TagOnFileWhereParam { + TagOnFileWhereParam::FileIs(value) + } + pub fn link>(&self, value: FileWhereParam) -> T { + TagOnFileLinkFile(value).into() + } + pub fn fetch(&self) -> TagOnFileWith { + TagOnFileWithParam::File.into() + } +} +pub enum TagOnFileWhereParam { + DateCreatedBefore(chrono::DateTime), + DateCreatedAfter(chrono::DateTime), + DateCreatedBeforeEquals(chrono::DateTime), + DateCreatedAfterEquals(chrono::DateTime), + DateCreatedEquals(chrono::DateTime), + TagIdLT(i64), + TagIdGT(i64), + TagIdLTE(i64), + TagIdGTE(i64), + TagIdEquals(i64), + TagIs(Vec), + FileIdLT(i64), + FileIdGT(i64), + FileIdLTE(i64), + FileIdGTE(i64), + FileIdEquals(i64), + FileIs(Vec), + Not(Vec), + Or(Vec), + And(Vec), +} +impl TagOnFileWhereParam { + pub fn field(self) -> Field { + match self { + Self::DateCreatedBefore(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfter(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBeforeEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfterEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TagIdLT(value) => Field { + name: "tag_id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TagIdGT(value) => Field { + name: "tag_id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TagIdLTE(value) => Field { + name: "tag_id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TagIdGTE(value) => Field { + name: "tag_id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TagIdEquals(value) => Field { + name: "tag_id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TagIs(value) => Field { + name: "tag".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileIdLT(value) => Field { + name: "file_id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileIdGT(value) => Field { + name: "file_id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileIdLTE(value) => Field { + name: "file_id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileIdGTE(value) => Field { + name: "file_id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileIdEquals(value) => Field { + name: "file_id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileIs(value) => Field { + name: "file".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct TagOnFileWith { + pub param: TagOnFileWithParam, +} +pub enum TagOnFileWithParam { + Tag, + File, +} +impl From for TagOnFileWith { + fn from(param: TagOnFileWithParam) -> Self { + Self { param } + } +} +impl TagOnFileWithParam { + pub fn output(self) -> Output { + match self { + Self::Tag => Output { + name: "tag".into(), + outputs: tag_outputs(), + ..Default::default() + }, + Self::File => Output { + name: "file".into(), + outputs: file_outputs(), + ..Default::default() + }, + } + } +} +pub enum TagOnFileSetParam { + DateCreated(chrono::DateTime), + TagId(i64), + LinkTag(TagWhereParam), + FileId(i64), + LinkFile(FileWhereParam), +} +impl TagOnFileSetParam { + pub fn field(self) -> Field { + match self { + Self::DateCreated(value) => Field { + name: "date_created".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::TagId(value) => Field { + name: "tag_id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkTag(where_param) => Field { + name: "tag".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals(vec![where_param.field()])), + ..Default::default() + }]), + ..Default::default() + }, + Self::FileId(value) => Field { + name: "file_id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkFile(where_param) => Field { + name: "file".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals(vec![where_param.field()])), + ..Default::default() + }]), + ..Default::default() + }, + } + } +} +pub struct TagOnFileFindMany<'a> { + query: Query<'a>, +} +impl<'a> TagOnFileFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> TagOnFileDelete<'a> { + TagOnFileDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "TagOnFile".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> TagOnFileUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + TagOnFileUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagOnFileFindFirst<'a> { + query: Query<'a>, +} +impl<'a> TagOnFileFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagOnFileFindUnique<'a> { + query: Query<'a>, +} +impl<'a> TagOnFileFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> TagOnFileDelete<'a> { + TagOnFileDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "TagOnFile".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> TagOnFileUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + TagOnFileUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagOnFileCreateOne<'a> { + query: Query<'a>, +} +impl<'a> TagOnFileCreateOne<'a> { + pub async fn exec(self) -> TagOnFileData { + self.query.perform::().await.unwrap() + } +} +pub struct TagOnFileUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> TagOnFileUpdateUnique<'a> { + pub async fn exec(self) -> TagOnFileData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagOnFileUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> TagOnFileUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct TagOnFileDelete<'a> { + query: Query<'a>, +} +impl<'a> TagOnFileDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct TagOnFileActions<'a> { + client: &'a PrismaClient, +} +impl<'a> TagOnFileActions<'a> { + pub fn find_unique(&self, param: TagOnFileWhereParam) -> TagOnFileFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "TagOnFile".into(), + outputs: tag_on_file_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + TagOnFileFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> TagOnFileFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "TagOnFile".into(), + outputs: tag_on_file_outputs(), + inputs, + }; + TagOnFileFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> TagOnFileFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "TagOnFile".into(), + outputs: tag_on_file_outputs(), + inputs, + }; + TagOnFileFindMany { query } + } + pub fn create_one( + &self, + tag: TagOnFileLinkTag, + file: TagOnFileLinkFile, + params: Vec, + ) -> TagOnFileCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + input_fields.push(TagOnFileSetParam::from(tag).field()); + input_fields.push(TagOnFileSetParam::from(file).field()); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "TagOnFile".into(), + outputs: tag_on_file_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + TagOnFileCreateOne { query } + } +} +fn job_outputs() -> Vec { + vec![ + Output::new("id"), + Output::new("client_id"), + Output::new("action"), + Output::new("status"), + Output::new("percentage_complete"), + Output::new("task_count"), + Output::new("completed_task_count"), + Output::new("date_created"), + Output::new("date_modified"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct JobData { + #[serde(rename = "id")] + pub id: i64, + #[serde(rename = "client_id")] + pub client_id: i64, + #[serde(rename = "action")] + pub action: i64, + #[serde(rename = "status")] + pub status: i64, + #[serde(rename = "percentage_complete")] + pub percentage_complete: i64, + #[serde(rename = "task_count")] + pub task_count: i64, + #[serde(rename = "completed_task_count")] + pub completed_task_count: i64, + #[serde(rename = "date_created")] + pub date_created: chrono::DateTime, + #[serde(rename = "date_modified")] + pub date_modified: chrono::DateTime, + #[serde(rename = "clients")] + clients: Box>, +} +impl JobData { + pub fn clients(&self) -> Result<&ClientData, String> { + match self.clients.as_ref() { + Some(v) => Ok(v), + None => Err( + "attempted to access clients but did not fetch it using the .with() syntax" + .to_string(), + ), + } + } +} +pub struct Job; +impl Job { + pub fn id() -> JobIdField { + JobIdField {} + } + pub fn client_id() -> JobClientIdField { + JobClientIdField {} + } + pub fn action() -> JobActionField { + JobActionField {} + } + pub fn status() -> JobStatusField { + JobStatusField {} + } + pub fn percentage_complete() -> JobPercentageCompleteField { + JobPercentageCompleteField {} + } + pub fn task_count() -> JobTaskCountField { + JobTaskCountField {} + } + pub fn completed_task_count() -> JobCompletedTaskCountField { + JobCompletedTaskCountField {} + } + pub fn date_created() -> JobDateCreatedField { + JobDateCreatedField {} + } + pub fn date_modified() -> JobDateModifiedField { + JobDateModifiedField {} + } + pub fn clients() -> JobClientsField { + JobClientsField {} + } + pub fn not(params: Vec) -> JobWhereParam { + JobWhereParam::Not(params) + } + pub fn or(params: Vec) -> JobWhereParam { + JobWhereParam::Or(params) + } + pub fn and(params: Vec) -> JobWhereParam { + JobWhereParam::And(params) + } +} +pub struct JobIdField {} +pub struct JobSetId(i64); +impl From for JobSetParam { + fn from(value: JobSetId) -> Self { + Self::Id(value.0) + } +} +impl JobIdField { + pub fn lt(&self, value: i64) -> JobWhereParam { + JobWhereParam::IdLT(value) + } + pub fn gt(&self, value: i64) -> JobWhereParam { + JobWhereParam::IdGT(value) + } + pub fn lte(&self, value: i64) -> JobWhereParam { + JobWhereParam::IdLTE(value) + } + pub fn gte(&self, value: i64) -> JobWhereParam { + JobWhereParam::IdGTE(value) + } + pub fn equals(&self, value: i64) -> JobWhereParam { + JobWhereParam::IdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + JobSetId(value).into() + } +} +pub struct JobClientIdField {} +pub struct JobSetClientId(i64); +impl From for JobSetParam { + fn from(value: JobSetClientId) -> Self { + Self::ClientId(value.0) + } +} +impl JobClientIdField { + pub fn lt(&self, value: i64) -> JobWhereParam { + JobWhereParam::ClientIdLT(value) + } + pub fn gt(&self, value: i64) -> JobWhereParam { + JobWhereParam::ClientIdGT(value) + } + pub fn lte(&self, value: i64) -> JobWhereParam { + JobWhereParam::ClientIdLTE(value) + } + pub fn gte(&self, value: i64) -> JobWhereParam { + JobWhereParam::ClientIdGTE(value) + } + pub fn equals(&self, value: i64) -> JobWhereParam { + JobWhereParam::ClientIdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + JobSetClientId(value).into() + } +} +pub struct JobActionField {} +pub struct JobSetAction(i64); +impl From for JobSetParam { + fn from(value: JobSetAction) -> Self { + Self::Action(value.0) + } +} +impl JobActionField { + pub fn lt(&self, value: i64) -> JobWhereParam { + JobWhereParam::ActionLT(value) + } + pub fn gt(&self, value: i64) -> JobWhereParam { + JobWhereParam::ActionGT(value) + } + pub fn lte(&self, value: i64) -> JobWhereParam { + JobWhereParam::ActionLTE(value) + } + pub fn gte(&self, value: i64) -> JobWhereParam { + JobWhereParam::ActionGTE(value) + } + pub fn equals(&self, value: i64) -> JobWhereParam { + JobWhereParam::ActionEquals(value) + } + pub fn set>(&self, value: i64) -> T { + JobSetAction(value).into() + } +} +pub struct JobStatusField {} +pub struct JobSetStatus(i64); +impl From for JobSetParam { + fn from(value: JobSetStatus) -> Self { + Self::Status(value.0) + } +} +impl JobStatusField { + pub fn lt(&self, value: i64) -> JobWhereParam { + JobWhereParam::StatusLT(value) + } + pub fn gt(&self, value: i64) -> JobWhereParam { + JobWhereParam::StatusGT(value) + } + pub fn lte(&self, value: i64) -> JobWhereParam { + JobWhereParam::StatusLTE(value) + } + pub fn gte(&self, value: i64) -> JobWhereParam { + JobWhereParam::StatusGTE(value) + } + pub fn equals(&self, value: i64) -> JobWhereParam { + JobWhereParam::StatusEquals(value) + } + pub fn set>(&self, value: i64) -> T { + JobSetStatus(value).into() + } +} +pub struct JobPercentageCompleteField {} +pub struct JobSetPercentageComplete(i64); +impl From for JobSetParam { + fn from(value: JobSetPercentageComplete) -> Self { + Self::PercentageComplete(value.0) + } +} +impl JobPercentageCompleteField { + pub fn lt(&self, value: i64) -> JobWhereParam { + JobWhereParam::PercentageCompleteLT(value) + } + pub fn gt(&self, value: i64) -> JobWhereParam { + JobWhereParam::PercentageCompleteGT(value) + } + pub fn lte(&self, value: i64) -> JobWhereParam { + JobWhereParam::PercentageCompleteLTE(value) + } + pub fn gte(&self, value: i64) -> JobWhereParam { + JobWhereParam::PercentageCompleteGTE(value) + } + pub fn equals(&self, value: i64) -> JobWhereParam { + JobWhereParam::PercentageCompleteEquals(value) + } + pub fn set>(&self, value: i64) -> T { + JobSetPercentageComplete(value).into() + } +} +pub struct JobTaskCountField {} +pub struct JobSetTaskCount(i64); +impl From for JobSetParam { + fn from(value: JobSetTaskCount) -> Self { + Self::TaskCount(value.0) + } +} +impl JobTaskCountField { + pub fn lt(&self, value: i64) -> JobWhereParam { + JobWhereParam::TaskCountLT(value) + } + pub fn gt(&self, value: i64) -> JobWhereParam { + JobWhereParam::TaskCountGT(value) + } + pub fn lte(&self, value: i64) -> JobWhereParam { + JobWhereParam::TaskCountLTE(value) + } + pub fn gte(&self, value: i64) -> JobWhereParam { + JobWhereParam::TaskCountGTE(value) + } + pub fn equals(&self, value: i64) -> JobWhereParam { + JobWhereParam::TaskCountEquals(value) + } + pub fn set>(&self, value: i64) -> T { + JobSetTaskCount(value).into() + } +} +pub struct JobCompletedTaskCountField {} +pub struct JobSetCompletedTaskCount(i64); +impl From for JobSetParam { + fn from(value: JobSetCompletedTaskCount) -> Self { + Self::CompletedTaskCount(value.0) + } +} +impl JobCompletedTaskCountField { + pub fn lt(&self, value: i64) -> JobWhereParam { + JobWhereParam::CompletedTaskCountLT(value) + } + pub fn gt(&self, value: i64) -> JobWhereParam { + JobWhereParam::CompletedTaskCountGT(value) + } + pub fn lte(&self, value: i64) -> JobWhereParam { + JobWhereParam::CompletedTaskCountLTE(value) + } + pub fn gte(&self, value: i64) -> JobWhereParam { + JobWhereParam::CompletedTaskCountGTE(value) + } + pub fn equals(&self, value: i64) -> JobWhereParam { + JobWhereParam::CompletedTaskCountEquals(value) + } + pub fn set>(&self, value: i64) -> T { + JobSetCompletedTaskCount(value).into() + } +} +pub struct JobDateCreatedField {} +pub struct JobSetDateCreated(chrono::DateTime); +impl From for JobSetParam { + fn from(value: JobSetDateCreated) -> Self { + Self::DateCreated(value.0) + } +} +impl JobDateCreatedField { + pub fn before(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateCreatedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateCreatedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateCreatedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateCreatedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateCreatedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + JobSetDateCreated(value).into() + } +} +pub struct JobDateModifiedField {} +pub struct JobSetDateModified(chrono::DateTime); +impl From for JobSetParam { + fn from(value: JobSetDateModified) -> Self { + Self::DateModified(value.0) + } +} +impl JobDateModifiedField { + pub fn before(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateModifiedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateModifiedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateModifiedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateModifiedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> JobWhereParam { + JobWhereParam::DateModifiedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + JobSetDateModified(value).into() + } +} +pub struct JobClientsField {} +pub struct JobLinkClients(ClientWhereParam); +impl From for JobSetParam { + fn from(value: JobLinkClients) -> Self { + Self::LinkClients(value.0) + } +} +impl JobClientsField { + pub fn is(&self, value: Vec) -> JobWhereParam { + JobWhereParam::ClientsIs(value) + } + pub fn link>(&self, value: ClientWhereParam) -> T { + JobLinkClients(value).into() + } + pub fn fetch(&self) -> JobWith { + JobWithParam::Clients.into() + } +} +pub enum JobWhereParam { + IdLT(i64), + IdGT(i64), + IdLTE(i64), + IdGTE(i64), + IdEquals(i64), + ClientIdLT(i64), + ClientIdGT(i64), + ClientIdLTE(i64), + ClientIdGTE(i64), + ClientIdEquals(i64), + ActionLT(i64), + ActionGT(i64), + ActionLTE(i64), + ActionGTE(i64), + ActionEquals(i64), + StatusLT(i64), + StatusGT(i64), + StatusLTE(i64), + StatusGTE(i64), + StatusEquals(i64), + PercentageCompleteLT(i64), + PercentageCompleteGT(i64), + PercentageCompleteLTE(i64), + PercentageCompleteGTE(i64), + PercentageCompleteEquals(i64), + TaskCountLT(i64), + TaskCountGT(i64), + TaskCountLTE(i64), + TaskCountGTE(i64), + TaskCountEquals(i64), + CompletedTaskCountLT(i64), + CompletedTaskCountGT(i64), + CompletedTaskCountLTE(i64), + CompletedTaskCountGTE(i64), + CompletedTaskCountEquals(i64), + DateCreatedBefore(chrono::DateTime), + DateCreatedAfter(chrono::DateTime), + DateCreatedBeforeEquals(chrono::DateTime), + DateCreatedAfterEquals(chrono::DateTime), + DateCreatedEquals(chrono::DateTime), + DateModifiedBefore(chrono::DateTime), + DateModifiedAfter(chrono::DateTime), + DateModifiedBeforeEquals(chrono::DateTime), + DateModifiedAfterEquals(chrono::DateTime), + DateModifiedEquals(chrono::DateTime), + ClientsIs(Vec), + Not(Vec), + Or(Vec), + And(Vec), +} +impl JobWhereParam { + pub fn field(self) -> Field { + match self { + Self::IdLT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdLTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdEquals(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ClientIdLT(value) => Field { + name: "client_id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ClientIdGT(value) => Field { + name: "client_id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ClientIdLTE(value) => Field { + name: "client_id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ClientIdGTE(value) => Field { + name: "client_id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ClientIdEquals(value) => Field { + name: "client_id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ActionLT(value) => Field { + name: "action".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ActionGT(value) => Field { + name: "action".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ActionLTE(value) => Field { + name: "action".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ActionGTE(value) => Field { + name: "action".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ActionEquals(value) => Field { + name: "action".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StatusLT(value) => Field { + name: "status".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StatusGT(value) => Field { + name: "status".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StatusLTE(value) => Field { + name: "status".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StatusGTE(value) => Field { + name: "status".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::StatusEquals(value) => Field { + name: "status".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PercentageCompleteLT(value) => Field { + name: "percentage_complete".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PercentageCompleteGT(value) => Field { + name: "percentage_complete".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PercentageCompleteLTE(value) => Field { + name: "percentage_complete".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PercentageCompleteGTE(value) => Field { + name: "percentage_complete".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::PercentageCompleteEquals(value) => Field { + name: "percentage_complete".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TaskCountLT(value) => Field { + name: "task_count".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TaskCountGT(value) => Field { + name: "task_count".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TaskCountLTE(value) => Field { + name: "task_count".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TaskCountGTE(value) => Field { + name: "task_count".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::TaskCountEquals(value) => Field { + name: "task_count".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::CompletedTaskCountLT(value) => Field { + name: "completed_task_count".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::CompletedTaskCountGT(value) => Field { + name: "completed_task_count".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::CompletedTaskCountLTE(value) => Field { + name: "completed_task_count".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::CompletedTaskCountGTE(value) => Field { + name: "completed_task_count".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::CompletedTaskCountEquals(value) => Field { + name: "completed_task_count".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBefore(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfter(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBeforeEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfterEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedBefore(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedAfter(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedBeforeEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedAfterEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::ClientsIs(value) => Field { + name: "clients".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct JobWith { + pub param: JobWithParam, +} +pub enum JobWithParam { + Clients, +} +impl From for JobWith { + fn from(param: JobWithParam) -> Self { + Self { param } + } +} +impl JobWithParam { + pub fn output(self) -> Output { + match self { + Self::Clients => Output { + name: "clients".into(), + outputs: client_outputs(), + ..Default::default() + }, + } + } +} +pub enum JobSetParam { + Id(i64), + ClientId(i64), + Action(i64), + Status(i64), + PercentageComplete(i64), + TaskCount(i64), + CompletedTaskCount(i64), + DateCreated(chrono::DateTime), + DateModified(chrono::DateTime), + LinkClients(ClientWhereParam), +} +impl JobSetParam { + pub fn field(self) -> Field { + match self { + Self::Id(value) => Field { + name: "id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::ClientId(value) => Field { + name: "client_id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Action(value) => Field { + name: "action".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Status(value) => Field { + name: "status".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::PercentageComplete(value) => Field { + name: "percentage_complete".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::TaskCount(value) => Field { + name: "task_count".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::CompletedTaskCount(value) => Field { + name: "completed_task_count".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateCreated(value) => Field { + name: "date_created".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateModified(value) => Field { + name: "date_modified".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkClients(where_param) => Field { + name: "clients".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals(vec![where_param.field()])), + ..Default::default() + }]), + ..Default::default() + }, + } + } +} +pub struct JobFindMany<'a> { + query: Query<'a>, +} +impl<'a> JobFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> JobDelete<'a> { + JobDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "Job".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> JobUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + JobUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct JobFindFirst<'a> { + query: Query<'a>, +} +impl<'a> JobFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct JobFindUnique<'a> { + query: Query<'a>, +} +impl<'a> JobFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> JobDelete<'a> { + JobDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "Job".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> JobUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + JobUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct JobCreateOne<'a> { + query: Query<'a>, +} +impl<'a> JobCreateOne<'a> { + pub async fn exec(self) -> JobData { + self.query.perform::().await.unwrap() + } +} +pub struct JobUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> JobUpdateUnique<'a> { + pub async fn exec(self) -> JobData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct JobUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> JobUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct JobDelete<'a> { + query: Query<'a>, +} +impl<'a> JobDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct JobActions<'a> { + client: &'a PrismaClient, +} +impl<'a> JobActions<'a> { + pub fn find_unique(&self, param: JobWhereParam) -> JobFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "Job".into(), + outputs: job_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + JobFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> JobFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "Job".into(), + outputs: job_outputs(), + inputs, + }; + JobFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> JobFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "Job".into(), + outputs: job_outputs(), + inputs, + }; + JobFindMany { query } + } + pub fn create_one( + &self, + action: JobSetAction, + clients: JobLinkClients, + params: Vec, + ) -> JobCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + input_fields.push(JobSetParam::from(action).field()); + input_fields.push(JobSetParam::from(clients).field()); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "Job".into(), + outputs: job_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + JobCreateOne { query } + } +} +fn space_outputs() -> Vec { + vec![ + Output::new("id"), + Output::new("name"), + Output::new("encryption"), + Output::new("date_created"), + Output::new("date_modified"), + Output::new("libraryId"), + ] +} +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SpaceData { + #[serde(rename = "id")] + pub id: i64, + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "encryption")] + pub encryption: Option, + #[serde(rename = "date_created")] + pub date_created: chrono::DateTime, + #[serde(rename = "date_modified")] + pub date_modified: chrono::DateTime, + #[serde(rename = "Library")] + pub library: Box>, + #[serde(rename = "libraryId")] + pub library_id: Option, +} +impl SpaceData { + pub fn library(&self) -> Option<&LibraryData> { + self.library.as_ref().as_ref() + } +} +pub struct Space; +impl Space { + pub fn id() -> SpaceIdField { + SpaceIdField {} + } + pub fn name() -> SpaceNameField { + SpaceNameField {} + } + pub fn encryption() -> SpaceEncryptionField { + SpaceEncryptionField {} + } + pub fn date_created() -> SpaceDateCreatedField { + SpaceDateCreatedField {} + } + pub fn date_modified() -> SpaceDateModifiedField { + SpaceDateModifiedField {} + } + pub fn library() -> SpaceLibraryField { + SpaceLibraryField {} + } + pub fn library_id() -> SpaceLibraryIdField { + SpaceLibraryIdField {} + } + pub fn not(params: Vec) -> SpaceWhereParam { + SpaceWhereParam::Not(params) + } + pub fn or(params: Vec) -> SpaceWhereParam { + SpaceWhereParam::Or(params) + } + pub fn and(params: Vec) -> SpaceWhereParam { + SpaceWhereParam::And(params) + } +} +pub struct SpaceIdField {} +pub struct SpaceSetId(i64); +impl From for SpaceSetParam { + fn from(value: SpaceSetId) -> Self { + Self::Id(value.0) + } +} +impl SpaceIdField { + pub fn lt(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::IdLT(value) + } + pub fn gt(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::IdGT(value) + } + pub fn lte(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::IdLTE(value) + } + pub fn gte(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::IdGTE(value) + } + pub fn equals(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::IdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + SpaceSetId(value).into() + } +} +pub struct SpaceNameField {} +pub struct SpaceSetName(String); +impl From for SpaceSetParam { + fn from(value: SpaceSetName) -> Self { + Self::Name(value.0) + } +} +impl SpaceNameField { + pub fn contains(&self, value: String) -> SpaceWhereParam { + SpaceWhereParam::NameContains(value) + } + pub fn has_prefix(&self, value: String) -> SpaceWhereParam { + SpaceWhereParam::NameHasPrefix(value) + } + pub fn has_suffix(&self, value: String) -> SpaceWhereParam { + SpaceWhereParam::NameHasSuffix(value) + } + pub fn equals(&self, value: String) -> SpaceWhereParam { + SpaceWhereParam::NameEquals(value) + } + pub fn set>(&self, value: String) -> T { + SpaceSetName(value).into() + } +} +pub struct SpaceEncryptionField {} +pub struct SpaceSetEncryption(i64); +impl From for SpaceSetParam { + fn from(value: SpaceSetEncryption) -> Self { + Self::Encryption(value.0) + } +} +impl SpaceEncryptionField { + pub fn lt(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::EncryptionLT(value) + } + pub fn gt(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::EncryptionGT(value) + } + pub fn lte(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::EncryptionLTE(value) + } + pub fn gte(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::EncryptionGTE(value) + } + pub fn equals(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::EncryptionEquals(value) + } + pub fn set>(&self, value: i64) -> T { + SpaceSetEncryption(value).into() + } +} +pub struct SpaceDateCreatedField {} +pub struct SpaceSetDateCreated(chrono::DateTime); +impl From for SpaceSetParam { + fn from(value: SpaceSetDateCreated) -> Self { + Self::DateCreated(value.0) + } +} +impl SpaceDateCreatedField { + pub fn before(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateCreatedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateCreatedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateCreatedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateCreatedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateCreatedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + SpaceSetDateCreated(value).into() + } +} +pub struct SpaceDateModifiedField {} +pub struct SpaceSetDateModified(chrono::DateTime); +impl From for SpaceSetParam { + fn from(value: SpaceSetDateModified) -> Self { + Self::DateModified(value.0) + } +} +impl SpaceDateModifiedField { + pub fn before(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateModifiedBefore(value) + } + pub fn after(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateModifiedAfter(value) + } + pub fn before_equals(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateModifiedBeforeEquals(value) + } + pub fn after_equals(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateModifiedAfterEquals(value) + } + pub fn equals(&self, value: chrono::DateTime) -> SpaceWhereParam { + SpaceWhereParam::DateModifiedEquals(value) + } + pub fn set>(&self, value: chrono::DateTime) -> T { + SpaceSetDateModified(value).into() + } +} +pub struct SpaceLibraryField {} +pub struct SpaceLinkLibrary(LibraryWhereParam); +impl From for SpaceSetParam { + fn from(value: SpaceLinkLibrary) -> Self { + Self::LinkLibrary(value.0) + } +} +impl SpaceLibraryField { + pub fn is(&self, value: Vec) -> SpaceWhereParam { + SpaceWhereParam::LibraryIs(value) + } + pub fn link>(&self, value: LibraryWhereParam) -> T { + SpaceLinkLibrary(value).into() + } + pub fn fetch(&self) -> SpaceWith { + SpaceWithParam::Library.into() + } + pub fn unlink(&self) -> SpaceSetParam { + SpaceSetParam::UnlinkLibrary + } +} +pub struct SpaceLibraryIdField {} +pub struct SpaceSetLibraryId(i64); +impl From for SpaceSetParam { + fn from(value: SpaceSetLibraryId) -> Self { + Self::LibraryId(value.0) + } +} +impl SpaceLibraryIdField { + pub fn lt(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::LibraryIdLT(value) + } + pub fn gt(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::LibraryIdGT(value) + } + pub fn lte(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::LibraryIdLTE(value) + } + pub fn gte(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::LibraryIdGTE(value) + } + pub fn equals(&self, value: i64) -> SpaceWhereParam { + SpaceWhereParam::LibraryIdEquals(value) + } + pub fn set>(&self, value: i64) -> T { + SpaceSetLibraryId(value).into() + } +} +pub enum SpaceWhereParam { + IdLT(i64), + IdGT(i64), + IdLTE(i64), + IdGTE(i64), + IdEquals(i64), + NameContains(String), + NameHasPrefix(String), + NameHasSuffix(String), + NameEquals(String), + EncryptionLT(i64), + EncryptionGT(i64), + EncryptionLTE(i64), + EncryptionGTE(i64), + EncryptionEquals(i64), + DateCreatedBefore(chrono::DateTime), + DateCreatedAfter(chrono::DateTime), + DateCreatedBeforeEquals(chrono::DateTime), + DateCreatedAfterEquals(chrono::DateTime), + DateCreatedEquals(chrono::DateTime), + DateModifiedBefore(chrono::DateTime), + DateModifiedAfter(chrono::DateTime), + DateModifiedBeforeEquals(chrono::DateTime), + DateModifiedAfterEquals(chrono::DateTime), + DateModifiedEquals(chrono::DateTime), + LibraryIs(Vec), + LibraryIdLT(i64), + LibraryIdGT(i64), + LibraryIdLTE(i64), + LibraryIdGTE(i64), + LibraryIdEquals(i64), + Not(Vec), + Or(Vec), + And(Vec), +} +impl SpaceWhereParam { + pub fn field(self) -> Field { + match self { + Self::IdLT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGT(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdLTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdGTE(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::IdEquals(value) => Field { + name: "id".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameContains(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "contains".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasPrefix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "starts_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameHasSuffix(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "ends_with".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::NameEquals(value) => Field { + name: "name".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionLT(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionGT(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionLTE(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionGTE(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::EncryptionEquals(value) => Field { + name: "encryption".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBefore(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfter(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedBeforeEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedAfterEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateCreatedEquals(value) => Field { + name: "date_created".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedBefore(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedAfter(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedBeforeEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedAfterEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::DateModifiedEquals(value) => Field { + name: "date_modified".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LibraryIs(value) => Field { + name: "Library".into(), + fields: Some(vec![Field { + name: "AND".into(), + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LibraryIdLT(value) => Field { + name: "libraryId".into(), + fields: Some(vec![Field { + name: "lt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LibraryIdGT(value) => Field { + name: "libraryId".into(), + fields: Some(vec![Field { + name: "gt".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LibraryIdLTE(value) => Field { + name: "libraryId".into(), + fields: Some(vec![Field { + name: "lte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LibraryIdGTE(value) => Field { + name: "libraryId".into(), + fields: Some(vec![Field { + name: "gte".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LibraryIdEquals(value) => Field { + name: "libraryId".into(), + fields: Some(vec![Field { + name: "equals".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }]), + ..Default::default() + }, + Self::Not(value) => Field { + name: "NOT".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::Or(value) => Field { + name: "OR".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + Self::And(value) => Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(value.into_iter().map(|f| f.field()).collect()), + ..Default::default() + }, + } + } +} +pub struct SpaceWith { + pub param: SpaceWithParam, +} +pub enum SpaceWithParam { + Library, +} +impl From for SpaceWith { + fn from(param: SpaceWithParam) -> Self { + Self { param } + } +} +impl SpaceWithParam { + pub fn output(self) -> Output { + match self { + Self::Library => Output { + name: "Library".into(), + outputs: library_outputs(), + ..Default::default() + }, + } + } +} +pub enum SpaceSetParam { + Id(i64), + Name(String), + Encryption(i64), + DateCreated(chrono::DateTime), + DateModified(chrono::DateTime), + LinkLibrary(LibraryWhereParam), + UnlinkLibrary, + LibraryId(i64), +} +impl SpaceSetParam { + pub fn field(self) -> Field { + match self { + Self::Id(value) => Field { + name: "id".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Name(value) => Field { + name: "name".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::Encryption(value) => Field { + name: "encryption".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateCreated(value) => Field { + name: "date_created".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::DateModified(value) => Field { + name: "date_modified".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + Self::LinkLibrary(where_param) => Field { + name: "Library".into(), + fields: Some(vec![Field { + name: "connect".into(), + fields: Some(transform_equals(vec![where_param.field()])), + ..Default::default() + }]), + ..Default::default() + }, + Self::UnlinkLibrary => Field { + name: "Library".into(), + fields: Some(vec![Field { + name: "disconnect".into(), + value: Some(true.into()), + ..Default::default() + }]), + ..Default::default() + }, + Self::LibraryId(value) => Field { + name: "libraryId".into(), + value: Some(serde_json::to_value(value).unwrap()), + ..Default::default() + }, + } + } +} +pub struct SpaceFindMany<'a> { + query: Query<'a>, +} +impl<'a> SpaceFindMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> SpaceDelete<'a> { + SpaceDelete { + query: Query { + operation: "mutation".into(), + method: "deleteMany".into(), + model: "Space".into(), + outputs: vec![Output::new("count")], + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> SpaceUpdateMany<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + SpaceUpdateMany { + query: Query { + operation: "mutation".into(), + method: "updateMany".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct SpaceFindFirst<'a> { + query: Query<'a>, +} +impl<'a> SpaceFindFirst<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct SpaceFindUnique<'a> { + query: Query<'a>, +} +impl<'a> SpaceFindUnique<'a> { + pub async fn exec(self) -> Option { + self.query.perform::>().await.unwrap() + } + pub fn delete(self) -> SpaceDelete<'a> { + SpaceDelete { + query: Query { + operation: "mutation".into(), + method: "deleteOne".into(), + model: "Space".into(), + ..self.query + }, + } + } + pub fn update(mut self, params: Vec) -> SpaceUpdateUnique<'a> { + self.query.inputs.push(Input { + name: "data".into(), + fields: params + .into_iter() + .map(|param| { + let mut field = param.field(); + if let Some(value) = field.value { + field.fields = Some(vec![Field { + name: "set".into(), + value: Some(value), + ..Default::default() + }]); + field.value = None; + } + field + }) + .collect(), + ..Default::default() + }); + SpaceUpdateUnique { + query: Query { + operation: "mutation".into(), + method: "updateOne".into(), + ..self.query + }, + } + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct SpaceCreateOne<'a> { + query: Query<'a>, +} +impl<'a> SpaceCreateOne<'a> { + pub async fn exec(self) -> SpaceData { + self.query.perform::().await.unwrap() + } +} +pub struct SpaceUpdateUnique<'a> { + query: Query<'a>, +} +impl<'a> SpaceUpdateUnique<'a> { + pub async fn exec(self) -> SpaceData { + self.query.perform::().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct SpaceUpdateMany<'a> { + query: Query<'a>, +} +impl<'a> SpaceUpdateMany<'a> { + pub async fn exec(self) -> Vec { + self.query.perform::>().await.unwrap() + } + pub fn with(mut self, fetches: Vec) -> Self { + let outputs = fetches + .into_iter() + .map(|f| f.param.output()) + .collect::>(); + self.query.outputs.extend(outputs); + self + } +} +pub struct SpaceDelete<'a> { + query: Query<'a>, +} +impl<'a> SpaceDelete<'a> { + pub async fn exec(self) -> isize { + self.query.perform::().await.unwrap().count + } +} +pub struct SpaceActions<'a> { + client: &'a PrismaClient, +} +impl<'a> SpaceActions<'a> { + pub fn find_unique(&self, param: SpaceWhereParam) -> SpaceFindUnique { + let fields = transform_equals(vec![param.field()]); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findUnique".into(), + model: "Space".into(), + outputs: space_outputs(), + inputs: vec![Input { + name: "where".into(), + fields, + ..Default::default() + }], + }; + SpaceFindUnique { query } + } + pub fn find_first(&self, params: Vec) -> SpaceFindFirst { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: vec![Field { + name: "AND".into(), + list: true, + wrap_list: true, + fields: Some(where_fields), + ..Default::default() + }], + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findFirst".into(), + model: "Space".into(), + outputs: space_outputs(), + inputs, + }; + SpaceFindFirst { query } + } + pub fn find_many(&self, params: Vec) -> SpaceFindMany { + let where_fields: Vec = params.into_iter().map(|param| param.field()).collect(); + let inputs = if where_fields.len() > 0 { + vec![Input { + name: "where".into(), + fields: where_fields, + ..Default::default() + }] + } else { + Vec::new() + }; + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "query".into(), + method: "findMany".into(), + model: "Space".into(), + outputs: space_outputs(), + inputs, + }; + SpaceFindMany { query } + } + pub fn create_one(&self, name: SpaceSetName, params: Vec) -> SpaceCreateOne { + let mut input_fields = params.into_iter().map(|p| p.field()).collect::>(); + input_fields.push(SpaceSetParam::from(name).field()); + let query = Query { + ctx: QueryContext::new(&self.client.executor, self.client.query_schema.clone()), + name: String::new(), + operation: "mutation".into(), + method: "createOne".into(), + model: "Space".into(), + outputs: space_outputs(), + inputs: vec![Input { + name: "data".into(), + fields: input_fields, + ..Default::default() + }], + }; + SpaceCreateOne { query } + } +} diff --git a/packages/core/src/tx/commit.rs b/packages/core/src/tx/commit.rs index 41e67084c..a4d306edc 100644 --- a/packages/core/src/tx/commit.rs +++ b/packages/core/src/tx/commit.rs @@ -1,52 +1,35 @@ +use chrono::{DateTime, Utc}; +use prisma_client_rust::SerializeQuery; use serde::{Deserialize, Serialize}; +use uuid::Uuid; +use crate::state; + +// an SQL commit to be sent to connected clients #[derive(Serialize, Deserialize)] pub struct Commit { - pub commit_type: CommitType, - pub client_id: u32, - pub library_id: u32, + pub id: String, pub timestamp: DateTime, - pub sql: Option, -} - -enum CommitType { - Create, - Mutate, - Delete, + pub client_uuid: String, + pub library_uuid: String, + pub sql: String, } impl Commit { - pub fn new(commit_type: CommitType, sql: Option) -> Self { - Self { commit_type, sql } + pub fn new(sql: String) -> Self { + let client = state::client::get(); + let id = Uuid::new_v4().to_string(); + let timestamp = Utc::now(); + Self { + id, + sql, + client_uuid: client.client_id, + library_uuid: client.current_library_id, + timestamp, + } } pub fn from_query(query: T) -> Self { - Self::new(CommitType::Mutate, query.serialize_query()) + Self::new(query.serialize_query()) } } - -struct RawQuery(String); - -trait SerializeQuery { - fn serialize_query(self) -> String; -} - -struct PostFindMany { - query: String, -} - -impl SerializeQuery for PostFindUnique { - fn serialize_query(self) -> String { - RawQuery(self.query) - } -} - -fn main() { - // example - Commit::from_query( - client - .post() - .find_unique(Post::id().equals("post0".to_string())) - .with(vec![Post::user().fetch()]), - ); -} diff --git a/packages/core/src/tx/mod.rs b/packages/core/src/tx/mod.rs index e69de29bb..6cfaa824a 100644 --- a/packages/core/src/tx/mod.rs +++ b/packages/core/src/tx/mod.rs @@ -0,0 +1 @@ +// pub mod commit;