use log::info; use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseConnection}; use std::error::Error; use sea_orm::Schema; pub struct Starter { pub conn: DatabaseConnection, } impl Starter { pub async fn connect(db_url:&str) -> Result> { let opt: ConnectOptions = ConnectOptions::new(db_url); let conn_new: DatabaseConnection = Database::connect(opt).await?; Ok(Starter{conn:conn_new}) } pub async fn create_table(&self) -> Result<(), Box> { let backend = self.conn.get_database_backend(); let schema = Schema::new(backend); let table_create_statement = schema.create_table_from_entity(super::word_entity::Entity); let table_create_result = self.conn.execute(backend.build(&table_create_statement)).await?; info!("{:?}",table_create_result); Ok(()) } }