Skip to content

Commit

Permalink
fix??
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Aug 16, 2022
1 parent f67962a commit 8a561a5
Show file tree
Hide file tree
Showing 5 changed files with 1,232 additions and 904 deletions.
59 changes: 59 additions & 0 deletions prisma/migrations/20220816125113_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- CreateTable
CREATE TABLE "Activity" (
"ID" TEXT NOT NULL,
"UpdatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"CreatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"Name" TEXT NOT NULL,
"UserId" TEXT NOT NULL,

CONSTRAINT "Activity_pkey" PRIMARY KEY ("ID")
);

-- CreateTable
CREATE TABLE "Device" (
"ID" TEXT NOT NULL,
"Name" TEXT NOT NULL,

CONSTRAINT "Device_pkey" PRIMARY KEY ("ID")
);

-- CreateTable
CREATE TABLE "DeviceActivity" (
"ID" TEXT NOT NULL,
"UpdatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"CreatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"ActivityId" TEXT,
"DeviceId" TEXT NOT NULL,

CONSTRAINT "DeviceActivity_pkey" PRIMARY KEY ("ID")
);

-- CreateTable
CREATE TABLE "User" (
"ID" TEXT NOT NULL,
"Name" TEXT NOT NULL,
"ApiKey" TEXT NOT NULL,

CONSTRAINT "User_pkey" PRIMARY KEY ("ID")
);

-- CreateIndex
CREATE UNIQUE INDEX "Activity_Name_key" ON "Activity"("Name");

-- CreateIndex
CREATE UNIQUE INDEX "Device_Name_key" ON "Device"("Name");

-- CreateIndex
CREATE UNIQUE INDEX "User_Name_key" ON "User"("Name");

-- CreateIndex
CREATE UNIQUE INDEX "User_ApiKey_key" ON "User"("ApiKey");

-- AddForeignKey
ALTER TABLE "Activity" ADD CONSTRAINT "Activity_UserId_fkey" FOREIGN KEY ("UserId") REFERENCES "User"("ID") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DeviceActivity" ADD CONSTRAINT "DeviceActivity_ActivityId_fkey" FOREIGN KEY ("ActivityId") REFERENCES "Activity"("ID") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DeviceActivity" ADD CONSTRAINT "DeviceActivity_DeviceId_fkey" FOREIGN KEY ("DeviceId") REFERENCES "Device"("ID") ON DELETE RESTRICT ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
8 changes: 4 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
generator client {
// Corresponds to the cargo alias created earlier
provider = "cargo prisma"
// The location to generate the schema. Is relative to the position of the schema
output = "../src/prisma.rs"
// Corresponds to the cargo alias created earlier
provider = "cargo prisma"
// The location to generate the schema. Is relative to the position of the schema
output = "../src/prisma.rs"
}

datasource db {
Expand Down
60 changes: 42 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
use prisma::PrismaClient;
use prisma_client_rust::NewClientError;

use crate::prisma::_prisma::QueryMode;
use _prisma::QueryMode;
use prisma::*;

pub mod prisma;

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let client: Result<PrismaClient, NewClientError> = prisma::new_client().await;
let client = prisma::new_client().await;

match &client {
Ok(client) => {
println!("all users: {:?}", client.user().find_many(vec![]).exec().await);
let d = client.user().find_first(vec![
prisma::user::name::mode(QueryMode::Insensitive),
prisma::user::name::equals("Luna".to_string())

]).exec().await.unwrap();
client
.user()
.upsert(
user::id::equals("0".to_string()),
user::create("0".to_string(), "Luna".to_string(), "".to_string(), vec![]),
vec![],
)
.exec()
.await
.unwrap();

println!(
"all users: {:?}",
client.user().find_many(vec![]).exec().await
);

use user::*;

let d = client
.user()
.find_first(vec![
name::mode(QueryMode::Insensitive),
name::equals("Luna".to_string()),
])
.exec()
.await
.unwrap();
println!("search for 'Luna' : {:?}", d);
let d = client.user().find_first(vec![
prisma::user::name::mode(QueryMode::Insensitive),
prisma::user::name::equals("luna".to_string())

]).exec().await.unwrap();

let d = client
.user()
.find_first(vec![
name::mode(QueryMode::Insensitive),
name::equals("luna".to_string()),
])
.exec()
.await
.unwrap();
println!("search for 'luna' : {:?}", d);
}
Err(e) => {

println!("error initalizing client: {:?}", e);
}
}
Expand Down
Loading

0 comments on commit 8a561a5

Please sign in to comment.