@@ -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 if it doesn't exist, the initial connection is made using the default database
643+ /// `postgres`.
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,47 @@ 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+ /// Connects to the PostgreSQL database at the given `connection_string`, e.g.,
1132+ /// `"postgres://user:password@localhost/ldk_db"`.
1133+ ///
1134+ /// The given `db_name` will be used or default to
1135+ /// [`DEFAULT_DB_NAME`](io::postgres_store::DEFAULT_DB_NAME). The database will be created
1136+ /// automatically if it doesn't already exist. The `connection_string` must not include a
1137+ /// `dbname` when `db_name` is set, providing both is an error. When auto-creating the
1138+ /// database if is doesn't exist, the initial connection is made using the default database
1139+ /// `postgres`.
1140+ ///
1141+ /// The given `kv_table_name` will be used or default to
1142+ /// [`DEFAULT_KV_TABLE_NAME`](io::postgres_store::DEFAULT_KV_TABLE_NAME).
1143+ ///
1144+ /// If `tls_config` is `Some`, TLS will be used for database connections. A custom CA
1145+ /// certificate can be provided via
1146+ /// [`PostgresTlsConfig::certificate_pem`](io::postgres_store::PostgresTlsConfig::certificate_pem),
1147+ /// which will be added to the system's default root certificates (not replace them).
1148+ /// If `tls_config` is `None`, connections will be unencrypted.
1149+ ///
1150+ /// [PostgreSQL]: https://www.postgresql.org
1151+ #[ cfg( feature = "postgres" ) ]
1152+ pub fn build_with_postgres_store (
1153+ & self , node_entropy : Arc < NodeEntropy > , connection_string : String , db_name : Option < String > ,
1154+ kv_table_name : Option < String > , tls_config : Option < io:: postgres_store:: PostgresTlsConfig > ,
1155+ ) -> Result < Arc < Node > , BuildError > {
1156+ self . inner
1157+ . read ( )
1158+ . unwrap ( )
1159+ . build_with_postgres_store (
1160+ * node_entropy,
1161+ connection_string,
1162+ db_name,
1163+ kv_table_name,
1164+ tls_config,
1165+ )
1166+ . map ( Arc :: new)
1167+ }
1168+
10901169 /// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
10911170 /// previously configured.
10921171 pub fn build_with_fs_store (
0 commit comments