-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
42 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
use std::env; | ||
|
||
use ensemble::{ | ||
relationships::{BelongsTo, HasMany, Relationship}, | ||
types::{DateTime, Hashed}, | ||
Model, | ||
relationships::{BelongsTo, HasMany, Relationship}, | ||
types::{DateTime, Hashed}, | ||
Model, | ||
}; | ||
|
||
#[derive(Debug, Model)] | ||
pub struct User { | ||
pub id: u64, | ||
pub name: String, | ||
pub email: String, | ||
pub password: Hashed<String>, | ||
pub created_at: DateTime, | ||
pub updated_at: DateTime, | ||
#[model(foreign_key = "author_id")] | ||
pub posts: HasMany<User, Post>, | ||
pub id: u64, | ||
pub name: String, | ||
pub email: String, | ||
pub password: Hashed<String>, | ||
pub created_at: DateTime, | ||
pub updated_at: DateTime, | ||
// #[model(foreign_key = "author_id")] | ||
pub posts: HasMany<User, Post>, | ||
} | ||
|
||
#[derive(Debug, Model)] | ||
pub struct Post { | ||
#[model(incrementing)] | ||
pub id: u64, | ||
pub title: String, | ||
pub content: String, | ||
pub created_at: DateTime, | ||
pub updated_at: DateTime, | ||
#[model(incrementing)] | ||
pub id: u64, | ||
pub title: String, | ||
pub content: String, | ||
pub created_at: DateTime, | ||
pub updated_at: DateTime, | ||
|
||
#[model(foreign_key = "author_id")] | ||
pub user: BelongsTo<Post, User>, | ||
// #[model(foreign_key = "author_id")] | ||
pub user: BelongsTo<Post, User>, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
ensemble::setup(&env::var("DATABASE_URL").expect("DATABASE_URL must be set")) | ||
.expect("Failed to set up database pool."); | ||
ensemble::setup(&env::var("DATABASE_URL").expect("DATABASE_URL must be set")) | ||
.expect("Failed to set up database pool."); | ||
|
||
let mut user = User::find(1).await.expect("Failed to find user."); | ||
let posts = user.posts.get().await.expect("Failed to get posts."); | ||
dbg!(posts); | ||
let mut user = User::find(1).await.expect("Failed to find user."); | ||
let posts = user.posts.get().await.expect("Failed to get posts."); | ||
dbg!(posts); | ||
|
||
let mut post = Post::find(1).await.expect("Failed to find post."); | ||
let user = post.user.get().await.expect("Failed to get user."); | ||
dbg!(user); | ||
let mut post = Post::find(1).await.expect("Failed to find post."); | ||
let user = post.user.get().await.expect("Failed to get user."); | ||
dbg!(user); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.