hkalbasiمن نیتیوی در این نمی بینم هنوز
خیلی بهتره
مثلا file system روی مموری داره
میتونی از fs استفاده کنی
بعد تایمر و این چیزا هم کار میکنه روش
با تغییراتی که سمت توکیو دادن رانتایم تک ترد توکیو هم روش کار میکنه
خیلی مفیده...
H S
Omidچجپت گفت توی PostgreSQL این شکلی میشه:
CREATE TYPE owner AS ENUM (
'human',
'animal'
);
CREATE TABLE objects (
id UUID PRIMARY KEY,
owner owner NOT NULL,
owner_id UUID NOT NULL
);
اینو الان تست کردم
شبیه چیزیه که حدس زده :))
این کدمه
#[derive(Debug, toasty::Model)]
struct Human {
#[key]
#[auto]
id: uuid::Uuid,
name: String,
}
#[derive(Debug, toasty::Model)]
struct Animal {
#[key]
#[auto]
id: uuid::Uuid,
name: String,
color: String,
}
#[derive(Debug, toasty::Embed)]
enum Owner {
Human {
#[shared(id)]
id: uuid::Uuid,
#[belongs_to(key = id)]
human: toasty::Deferred<Human>,
},
Animal {
#[shared(id)]
id: uuid::Uuid,
#[belongs_to(key = id)]
animal: toasty::Deferred<Animal>,
},
}
#[derive(Debug, toasty::Model)]
struct House {
#[key]
#[auto]
id: uuid::Uuid,
address: String,
owner: Owner,
}
#[tokio::main]
async fn main() -> toasty::Result<()> {
let mut db = toasty::Db::builder()
.models(toasty::models!(crate::*))
.connect("turso://db.sqlite")
.await?;
db.push_schema().await?;
let human = toasty::create!(Human { name: "saeid" })
.exec(&mut db)
.await?;
toasty::create!(House {
address: "far far away",
owner: Owner::Human { human },
})
.exec(&mut db)
.await?;
Ok(())
}
S این تیبلهایه که ساخته CREATE TABLE "animals" ("id" BLOB NOT NULL, "name" TEXT NOT NULL, "color" TEXT NOT NULL, PRIMARY KEY ("id")); CREATE TABLE "houses" ("id" BLOB NOT NULL, "address" TEXT NOT NULL, "owner" TEXT NOT NULL CHECK ("owner" IN ('human', 'animal')), "owner_id" BLOB, PRIMARY KEY ("id")); CREATE TABLE "humans" ("id" BLOB NOT NULL, "name" TEXT NOT NULL, PRIMARY KEY ("id"));O O S O O S آره دقت نکردم... این دقیقا همون #[derive(Debug, toasty::Model)] struct Human { #[key] #[auto] id: uuid::Uuid, name: String, } #[derive(Debug, toasty::Model)] struct Animal { #[key] #[auto] id: uuid::Uuid, name: String, color: String, } #[derive(Debug, toasty::Embed)] enum Owner { Human { #[shared(id)] id: uuid::Uuid, #[belongs_to(key = id)] human: toasty::Deferred<Human>, }, Animal { #[shared(id)] id: uuid::Uuid, #[belongs_to(key = id)] animal: toasty::Deferred<Animal>, }, } #[derive(Debug, toasty::Model)] struct Object { #[key] #[auto] id: uuid::Uuid, owner: Owner, } #[tokio::main] async fn main() -> toasty::Result<()> { let mut db = toasty::Db::builder() .models(toasty::models!(crate::*)) .connect("turso://db.sqlite") .await?; db.push_schema().await?; let saeid = toasty::create!(Human { name: "saeid" }) .exec(&mut db) .await?; toasty::create!(Object { owner: Owner::Human { human: &saeid }, }) .exec(&mut db) .await?; Ok(()) } تیبلایی که ساخت CREATE TABLE "animals" ("id" BLOB NOT NULL, "name" TEXT NOT NULL, "color" TEXT NOT NULL, PRIMARY KEY ("id")); CREATE TABLE "objects" ("id" BLOB NOT NULL, "owner" TEXT NOT NULL CHECK ("owner" IN ('human', 'animal')), "owner_id" BLOB, PRIMARY KEY ("id")); CREATE TABLE "humans" ("id" BLOB NOT NULL, "name" TEXT NOT NULL, PRIMARY KEY ("id"));
O