use pool options (#86)

pull/90/head
Takayuki Maeda 3 years ago committed by GitHub
parent f42ebafe68
commit 7fb3565992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,17 +3,21 @@ use async_trait::async_trait;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use database_tree::{Child, Database, Table}; use database_tree::{Child, Database, Table};
use futures::TryStreamExt; use futures::TryStreamExt;
use sqlx::mysql::{MySqlColumn, MySqlPool as MPool, MySqlRow}; use sqlx::mysql::{MySqlColumn, MySqlPoolOptions, MySqlRow};
use sqlx::{Column as _, Row as _, TypeInfo as _}; use sqlx::{Column as _, Row as _, TypeInfo as _};
use std::time::Duration;
pub struct MySqlPool { pub struct MySqlPool {
pool: MPool, pool: sqlx::mysql::MySqlPool,
} }
impl MySqlPool { impl MySqlPool {
pub async fn new(database_url: &str) -> anyhow::Result<Self> { pub async fn new(database_url: &str) -> anyhow::Result<Self> {
Ok(Self { Ok(Self {
pool: MPool::connect(database_url).await?, pool: MySqlPoolOptions::new()
.connect_timeout(Duration::from_millis(500))
.connect(database_url)
.await?,
}) })
} }
} }

@ -4,8 +4,9 @@ use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use database_tree::{Child, Database, Schema, Table}; use database_tree::{Child, Database, Schema, Table};
use futures::TryStreamExt; use futures::TryStreamExt;
use itertools::Itertools; use itertools::Itertools;
use sqlx::postgres::{PgColumn, PgPool, PgRow}; use sqlx::postgres::{PgColumn, PgPool, PgPoolOptions, PgRow};
use sqlx::{Column as _, Row as _, TypeInfo as _}; use sqlx::{Column as _, Row as _, TypeInfo as _};
use std::time::Duration;
pub struct PostgresPool { pub struct PostgresPool {
pool: PgPool, pool: PgPool,
@ -14,7 +15,10 @@ pub struct PostgresPool {
impl PostgresPool { impl PostgresPool {
pub async fn new(database_url: &str) -> anyhow::Result<Self> { pub async fn new(database_url: &str) -> anyhow::Result<Self> {
Ok(Self { Ok(Self {
pool: PgPool::connect(database_url).await?, pool: PgPoolOptions::new()
.connect_timeout(Duration::from_millis(500))
.connect(database_url)
.await?,
}) })
} }
} }

@ -3,17 +3,21 @@ use async_trait::async_trait;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use database_tree::{Child, Database, Table}; use database_tree::{Child, Database, Table};
use futures::TryStreamExt; use futures::TryStreamExt;
use sqlx::sqlite::{SqliteColumn, SqlitePool as SPool, SqliteRow}; use sqlx::sqlite::{SqliteColumn, SqlitePoolOptions, SqliteRow};
use sqlx::{Column as _, Row as _, TypeInfo as _}; use sqlx::{Column as _, Row as _, TypeInfo as _};
use std::time::Duration;
pub struct SqlitePool { pub struct SqlitePool {
pool: SPool, pool: sqlx::sqlite::SqlitePool,
} }
impl SqlitePool { impl SqlitePool {
pub async fn new(database_url: &str) -> anyhow::Result<Self> { pub async fn new(database_url: &str) -> anyhow::Result<Self> {
Ok(Self { Ok(Self {
pool: SPool::connect(database_url).await?, pool: SqlitePoolOptions::new()
.connect_timeout(Duration::from_millis(500))
.connect(database_url)
.await?,
}) })
} }
} }

Loading…
Cancel
Save