-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: share a postgres instance across rust project
- Loading branch information
1 parent
0045134
commit d5bcc97
Showing
11 changed files
with
129 additions
and
68 deletions.
There are no files selected for viewing
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,23 @@ | ||
use crate::types::code::Code; | ||
|
||
pub fn generate_database_code() -> Code { | ||
Code::new( | ||
r#" | ||
use std::sync::Arc; | ||
use rindexer::PostgresClient; | ||
use tokio::sync::OnceCell; | ||
static POSTGRES_CLIENT: OnceCell<Arc<PostgresClient>> = OnceCell::const_new(); | ||
pub async fn get_or_init_postgres_client() -> Arc<PostgresClient> { | ||
POSTGRES_CLIENT | ||
.get_or_init(|| async { | ||
Arc::new(PostgresClient::new().await.expect("Failed to connect to Postgres")) | ||
}) | ||
.await | ||
.clone() | ||
} | ||
"# | ||
.to_string(), | ||
) | ||
} |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub mod build; | ||
|
||
mod context_bindings; | ||
mod database_bindings; | ||
mod docker; | ||
mod events_bindings; | ||
mod networks_bindings; | ||
|
||
pub use docker::generate_docker_file; |
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
15 changes: 15 additions & 0 deletions
15
rindexer_rust_playground/src/rindexer_lib/typings/database.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use std::sync::Arc; | ||
|
||
use rindexer::PostgresClient; | ||
use tokio::sync::OnceCell; | ||
|
||
static POSTGRES_CLIENT: OnceCell<Arc<PostgresClient>> = OnceCell::const_new(); | ||
|
||
pub async fn get_or_init_postgres_client() -> Arc<PostgresClient> { | ||
POSTGRES_CLIENT | ||
.get_or_init(|| async { | ||
Arc::new(PostgresClient::new().await.expect("Failed to connect to Postgres")) | ||
}) | ||
.await | ||
.clone() | ||
} |
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,4 +1,5 @@ | ||
#![allow(dead_code, unused)] | ||
pub mod database; | ||
pub mod global_contracts; | ||
pub mod networks; | ||
pub mod rindexer_playground; |
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