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

Method connect

src/driver/sqlx_sqlite.rs:63–115  ·  view source on GitHub ↗
(options: ConnectOptions)

Source from the content-addressed store, hash-verified

61 /// Add configuration options for the SQLite database
62 #[instrument(level = "trace")]
63 pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
64 let mut options = options;
65 let mut sqlx_opts = options
66 .url
67 .parse::<SqliteConnectOptions>()
68 .map_err(sqlx_error_to_conn_err)?;
69 if let Some(sqlcipher_key) = &options.sqlcipher_key {
70 sqlx_opts = sqlx_opts.pragma("key", sqlcipher_key.clone());
71 }
72 use sqlx::ConnectOptions;
73 if !options.sqlx_logging {
74 sqlx_opts = sqlx_opts.disable_statement_logging();
75 } else {
76 sqlx_opts = sqlx_opts.log_statements(options.sqlx_logging_level);
77 if options.sqlx_slow_statements_logging_level != LevelFilter::Off {
78 sqlx_opts = sqlx_opts.log_slow_statements(
79 options.sqlx_slow_statements_logging_level,
80 options.sqlx_slow_statements_logging_threshold,
81 );
82 }
83 }
84
85 if options.get_max_connections().is_none() {
86 options.max_connections(1);
87 }
88
89 if let Some(f) = &options.sqlite_opts_fn {
90 sqlx_opts = f(sqlx_opts);
91 }
92
93 let pool = if options.connect_lazy {
94 options.sqlx_pool_options().connect_lazy_with(sqlx_opts)
95 } else {
96 options
97 .sqlx_pool_options()
98 .connect_with(sqlx_opts)
99 .await
100 .map_err(sqlx_error_to_conn_err)?
101 };
102
103 let pool = SqlxSqlitePoolConnection {
104 pool,
105 metric_callback: None,
106 };
107
108 #[cfg(feature = "sqlite-use-returning-for-3_35")]
109 {
110 let version = get_version(&pool).await?;
111 ensure_returning_version(&version)?;
112 }
113
114 Ok(DatabaseConnection::SqlxSqlitePoolConnection(pool))
115 }
116}
117
118impl SqlxSqliteConnector {

Callers

nothing calls this directly

Calls 6

get_versionFunction · 0.85
ensure_returning_versionFunction · 0.85
get_max_connectionsMethod · 0.80
max_connectionsMethod · 0.80
sqlx_pool_optionsMethod · 0.80

Tested by

no test coverage detected