add sample data to basic example

This commit is contained in:
manuel 2023-01-07 18:21:19 +01:00
parent 77ec92f7eb
commit ba83f29ab5
3 changed files with 31 additions and 5 deletions

View File

@ -1,10 +1,12 @@
// setup
use sea_orm::sea_query::{ForeignKeyCreateStatement, ColumnDef, TableCreateStatement};
use sea_orm::{error::*, sea_query, ConnectionTrait, DbConn, ExecResult};
use sea_orm::{Set, EntityTrait, error::*, sea_query, ConnectionTrait, DbConn, ExecResult};
pub mod comment;
pub mod post;
pub use comment::Entity as Comment;
pub use post::Entity as Post;
use sea_orm::prelude::DateTime;
use sea_orm::prelude::Decimal;
// setup
async fn create_table(db: &DbConn, stmt: &TableCreateStatement) -> Result<ExecResult, DbErr> {
@ -59,5 +61,30 @@ pub async fn create_post_table(db: &DbConn) -> Result<ExecResult, DbErr> {
)
.to_owned();
create_table(db, &stmt).await
let res = create_table(db, &stmt).await;
for i in 1..101 {
let row = post::ActiveModel {
title: Set(format!("Test {}", i)),
text: Set("some content".to_string()),
tea_mandatory: Set(post::Tea::EverydayTea),
tea_optional: Set(None),
..Default::default()
};
let _res = Post::insert(row).exec(db).await;
}
for i in 1..101 {
let row = comment::ActiveModel {
comment: Set(format!("Test {}", i)),
user: Set("me@home.com".to_string()),
my_decimal: Set(Decimal::new(105, 0)),
insert_date: Set(DateTime::default()),
is_visible: Set(i%2 == 0),
..Default::default()
};
let _res = Comment::insert(row).exec(db).await;
}
res
}

View File

@ -4,7 +4,6 @@ use actix_admin::prelude::*;
use actix_web::{web, App, HttpServer, middleware};
use sea_orm::{ConnectOptions, DatabaseConnection};
use std::time::Duration;
mod entity;
use entity::{Post, Comment};
@ -61,7 +60,7 @@ async fn main() {
let conn = sea_orm::Database::connect(opt).await.unwrap();
let _ = entity::create_post_table(&conn).await;
println!("The admin interface will be available at http://localhost:5000/admin/");
println!("The admin interface is available at http://localhost:5000/admin/");
HttpServer::new(move || {

View File

@ -133,7 +133,7 @@
</tfoot>
</table>
</form>
<nav class="pagination" aria-label="pagination">
<nav hx-boost="true" hx-indicator="#loading" class="pagination" aria-label="pagination">
<a href="?page={{ page - 1 }}&entities_per_page={{ entities_per_page }}&search={{ search }}"
class="pagination-previous">Previous Page</a>
<a href="?page={{ page + 1 }}&entities_per_page={{ entities_per_page }}&search={{ search }}"