-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from friendbear/develop
PostgreSQL
- Loading branch information
Showing
24 changed files
with
340 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
product: | ||
select_all: SELECT id, name, price, category_id FROM product | ||
select_by_id: SELECT id, name, price, category_id FROM product WHERE id = $1 | ||
insert: INSERT INTO product VALUES(nextval('product_seq'), $1, $2, $3) | ||
update_by_id: UPDATE product SET name=$1, price=#2, category_id=$3 WHERE id = $4 | ||
delete_by_id: DELETE FROM product WHERE id = $1 | ||
product_category: | ||
select_all: SELECT id, name FROM product_category | ||
select_by_id: SELECT id, name FROM FROM product_category | ||
insert: INSERT INTO product_category VALUES(nextval('product_category_seq')), $1) | ||
delete_by_id: DELETE FROM product_category WHERE id = $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ pub struct Product { | |
price: i32, | ||
category_id: i32, | ||
product_category: Option<Vec<ProductCategory>>, | ||
} | ||
} |
17 changes: 11 additions & 6 deletions
17
practice_collection/postgres/src/lib.rs → practice_collection/postgresql/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
mod params; | ||
mod connect; | ||
mod transaction; | ||
mod entities; | ||
mod repository; | ||
mod product_repository; | ||
mod product_category_repository; | ||
mod manager; | ||
mod params; | ||
mod pool_1; | ||
mod pool_2; | ||
mod manager; | ||
mod product_category_repository; | ||
mod product_repository; | ||
mod repository; | ||
mod tokio_connect; | ||
mod tokio_product_repository; | ||
mod tokio_repository; | ||
mod tokio_transaction; | ||
mod transaction; | ||
pub mod sql; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
practice_collection/postgres/src/pool_1.rs → practice_collection/postgresql/src/pool_1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
use std::sync::Mutex; | ||
use r2d2_postgres::{postgres::NoTls, PostgresConnectionManager}; | ||
use r2d2_postgres::r2d2::Pool; | ||
use once_cell::sync::Lazy; | ||
use r2d2_postgres::r2d2::Pool; | ||
use r2d2_postgres::{postgres::NoTls, PostgresConnectionManager}; | ||
use std::sync::Mutex; | ||
|
||
#[allow(dead_code)] | ||
// Connecttion String | ||
static CONNECTION_STR: &str = "host=localhost port=5432 dbname=rust_sample user=postgres password=admin"; | ||
static CONNECTION_STR: &str = | ||
"host=localhost port=5432 dbname=rust_sample user=postgres password=admin"; | ||
#[allow(dead_code)] | ||
// Create Connection Pool | ||
pub static SAMPLE_POOL_1: Lazy<Mutex<Pool<PostgresConnectionManager<NoTls>>>> = | ||
Lazy::new(|| { | ||
pub static SAMPLE_POOL_1: Lazy<Mutex<Pool<PostgresConnectionManager<NoTls>>>> = Lazy::new(|| { | ||
let config = CONNECTION_STR.parse().unwrap(); | ||
// create connection manager | ||
let manager = PostgresConnectionManager::new(config, NoTls); | ||
// create pool | ||
let pool = r2d2::Pool::new(manager).unwrap(); | ||
Mutex::new(pool) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use once_cell::sync::Lazy; | ||
use r2d2_postgres::r2d2::Pool; | ||
use r2d2_postgres::{postgres::NoTls, PostgresConnectionManager}; | ||
use std::sync::Mutex; | ||
use std::time::Duration; | ||
|
||
#[allow(dead_code)] | ||
// connection str | ||
static CONNECTION_STR: &str = | ||
"host=localhost port=5432 dbname=rust_sample user=postgres password=admin"; | ||
|
||
#[allow(dead_code)] | ||
// create connection pool | ||
pub static SAMPLE_POOL_2: Lazy<Mutex<Pool<PostgresConnectionManager<NoTls>>>> = Lazy::new(|| { | ||
let config = CONNECTION_STR.parse().unwrap(); | ||
let manager = PostgresConnectionManager::new(config, NoTls); | ||
let pool = r2d2::Pool::builder() | ||
.max_size(30) | ||
.min_idle(Some(1)) | ||
.connection_timeout(Duration::from_secs_f32(60.0)) | ||
.build(manager) | ||
.unwrap(); | ||
Mutex::new(pool) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.