feat: sqlx sqlite create db file if not present
This commit is contained in:
parent
450557e3f8
commit
10f33d8ea6
2 changed files with 10 additions and 1 deletions
|
@ -63,10 +63,18 @@ pub mod prelude {
|
||||||
impl Connect for ConnectionOptions {
|
impl Connect for ConnectionOptions {
|
||||||
type Pool = Database;
|
type Pool = Database;
|
||||||
async fn connect(self) -> DBResult<Self::Pool> {
|
async fn connect(self) -> DBResult<Self::Pool> {
|
||||||
|
use sqlx::sqlite::SqliteConnectOptions;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
let pool = match self {
|
let pool = match self {
|
||||||
Self::Fresh(fresh) => fresh
|
Self::Fresh(fresh) => fresh
|
||||||
.pool_options
|
.pool_options
|
||||||
.connect(&fresh.url)
|
.connect_with(
|
||||||
|
SqliteConnectOptions::from_str(&fresh.url)
|
||||||
|
.unwrap()
|
||||||
|
.create_if_missing(true)
|
||||||
|
.read_only(false),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| DBError::DBError(Box::new(e)))?,
|
.map_err(|e| DBError::DBError(Box::new(e)))?,
|
||||||
Self::Existing(conn) => conn.0,
|
Self::Existing(conn) => conn.0,
|
||||||
|
|
|
@ -61,6 +61,7 @@ async fn everything_works() {
|
||||||
let pool_options = SqlitePoolOptions::new().max_connections(2);
|
let pool_options = SqlitePoolOptions::new().max_connections(2);
|
||||||
let connection_options = ConnectionOptions::Fresh(Fresh { pool_options, url });
|
let connection_options = ConnectionOptions::Fresh(Fresh { pool_options, url });
|
||||||
let db = connection_options.connect().await.unwrap();
|
let db = connection_options.connect().await.unwrap();
|
||||||
|
db.migrate().await.unwrap();
|
||||||
|
|
||||||
let add_repo_msg = AddRepository {
|
let add_repo_msg = AddRepository {
|
||||||
html_link: HTML_REPO_URL,
|
html_link: HTML_REPO_URL,
|
||||||
|
|
Loading…
Reference in a new issue