mirror of
https://github.com/catdevnull/preciazo.git
synced 2024-11-26 03:26:19 +00:00
db: arreglar init
This commit is contained in:
parent
33d416d921
commit
9dd3a8766f
1 changed files with 3 additions and 1 deletions
|
@ -5,6 +5,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
|
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
use crate::{best_selling::BestSellingRecord, PrecioPoint};
|
use crate::{best_selling::BestSellingRecord, PrecioPoint};
|
||||||
|
|
||||||
|
@ -16,10 +17,11 @@ pub struct Db {
|
||||||
impl Db {
|
impl Db {
|
||||||
pub async fn connect() -> anyhow::Result<Self> {
|
pub async fn connect() -> anyhow::Result<Self> {
|
||||||
let db_path = env::var("DB_PATH").unwrap_or("../sqlite.db".to_string());
|
let db_path = env::var("DB_PATH").unwrap_or("../sqlite.db".to_string());
|
||||||
|
info!("Opening DB at {}", db_path);
|
||||||
let pool = sqlx::pool::PoolOptions::new()
|
let pool = sqlx::pool::PoolOptions::new()
|
||||||
.max_connections(1)
|
.max_connections(1)
|
||||||
.connect_with(
|
.connect_with(
|
||||||
SqliteConnectOptions::from_str(&db_path)?
|
SqliteConnectOptions::from_str(&format!("sqlite://{}", db_path))?
|
||||||
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
|
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
|
||||||
.synchronous(sqlx::sqlite::SqliteSynchronous::Normal)
|
.synchronous(sqlx::sqlite::SqliteSynchronous::Normal)
|
||||||
.optimize_on_close(true, None),
|
.optimize_on_close(true, None),
|
||||||
|
|
Loading…
Reference in a new issue