MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / run_cli_with_connection

Function run_cli_with_connection

sea-orm-migration/src/cli.rs:27–52  ·  view source on GitHub ↗

Same as [`run_cli`] where you provide the function to create the [`DbConn`]. This allows configuring the database connection as you see fit. E.g. you can change settings in [`ConnectOptions`] or you can load sqlite extensions.

(migrator: M, make_connection: F)

Source from the content-addressed store, hash-verified

25/// E.g. you can change settings in [`ConnectOptions`] or you can load sqlite
26/// extensions.
27pub async fn run_cli_with_connection<M, F, Fut>(migrator: M, make_connection: F)
28where
29 M: MigratorTrait,
30 F: FnOnce(ConnectOptions) -> Fut,
31 Fut: Future<Output = Result<DbConn, DbErr>>,
32{
33 dotenv().ok();
34 let cli = Cli::parse();
35
36 let url = cli
37 .database_url
38 .expect("Environment variable 'DATABASE_URL' not set");
39 let schema = cli.database_schema.unwrap_or_else(|| "public".to_owned());
40
41 let connect_options = ConnectOptions::new(url)
42 .set_schema_search_path(schema)
43 .to_owned();
44
45 let db = make_connection(connect_options)
46 .await
47 .expect("Fail to acquire database connection");
48
49 run_migrate(migrator, &db, cli.command, cli.verbose)
50 .await
51 .unwrap_or_else(handle_error);
52}
53
54pub async fn run_migrate<M>(
55 _: M,

Callers 1

run_cliFunction · 0.85

Calls 3

run_migrateFunction · 0.85
newFunction · 0.50

Tested by

no test coverage detected