@@ -629,6 +629,44 @@ impl NodeBuilder {
629629 self . build_with_store ( node_entropy, kv_store)
630630 }
631631
632+ /// Builds a [`Node`] instance with a [PostgreSQL] backend and according to the options
633+ /// previously configured.
634+ ///
635+ /// Connects to the PostgreSQL database at the given `connection_string`, e.g.,
636+ /// `"postgres://user:password@localhost/ldk_db"`.
637+ ///
638+ /// The given `db_name` will be used or default to
639+ /// [`DEFAULT_DB_NAME`](io::postgres_store::DEFAULT_DB_NAME). The database will be created
640+ /// automatically if it doesn't already exist. The `connection_string` must not include a
641+ /// `dbname` when `db_name` is set, providing both is an error. When auto-creating the
642+ /// database, the initial connection is made using the database from the connection string,
643+ /// or the server's default if none is specified.
644+ ///
645+ /// The given `kv_table_name` will be used or default to
646+ /// [`DEFAULT_KV_TABLE_NAME`](io::postgres_store::DEFAULT_KV_TABLE_NAME).
647+ ///
648+ /// If `tls_config` is `Some`, TLS will be used for database connections. A custom CA
649+ /// certificate can be provided via
650+ /// [`PostgresTlsConfig::certificate_pem`](io::postgres_store::PostgresTlsConfig::certificate_pem),
651+ /// which will be added to the system's default root certificates (not replace them).
652+ /// If `tls_config` is `None`, connections will be unencrypted.
653+ ///
654+ /// [PostgreSQL]: https://www.postgresql.org
655+ #[ cfg( feature = "postgres" ) ]
656+ pub fn build_with_postgres_store (
657+ & self , node_entropy : NodeEntropy , connection_string : String , db_name : Option < String > ,
658+ kv_table_name : Option < String > , tls_config : Option < io:: postgres_store:: PostgresTlsConfig > ,
659+ ) -> Result < Node , BuildError > {
660+ let kv_store = io:: postgres_store:: PostgresStore :: new (
661+ connection_string,
662+ db_name,
663+ kv_table_name,
664+ tls_config,
665+ )
666+ . map_err ( |_| BuildError :: KVStoreSetupFailed ) ?;
667+ self . build_with_store ( node_entropy, kv_store)
668+ }
669+
632670 /// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
633671 /// previously configured.
634672 pub fn build_with_fs_store ( & self , node_entropy : NodeEntropy ) -> Result < Node , BuildError > {
@@ -1087,6 +1125,28 @@ impl ArcedNodeBuilder {
10871125 self . inner . read ( ) . unwrap ( ) . build ( * node_entropy) . map ( Arc :: new)
10881126 }
10891127
1128+ /// Builds a [`Node`] instance with a [PostgreSQL] backend and according to the options
1129+ /// previously configured.
1130+ ///
1131+ /// [PostgreSQL]: https://www.postgresql.org
1132+ #[ cfg( feature = "postgres" ) ]
1133+ pub fn build_with_postgres_store (
1134+ & self , node_entropy : Arc < NodeEntropy > , connection_string : String , db_name : Option < String > ,
1135+ kv_table_name : Option < String > , tls_config : Option < io:: postgres_store:: PostgresTlsConfig > ,
1136+ ) -> Result < Arc < Node > , BuildError > {
1137+ self . inner
1138+ . read ( )
1139+ . unwrap ( )
1140+ . build_with_postgres_store (
1141+ * node_entropy,
1142+ connection_string,
1143+ db_name,
1144+ kv_table_name,
1145+ tls_config,
1146+ )
1147+ . map ( Arc :: new)
1148+ }
1149+
10901150 /// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
10911151 /// previously configured.
10921152 pub fn build_with_fs_store (
0 commit comments