@@ -640,6 +640,44 @@ impl NodeBuilder {
640640 self . build_with_store ( node_entropy, kv_store)
641641 }
642642
643+ /// Builds a [`Node`] instance with a [PostgreSQL] backend and according to the options
644+ /// previously configured.
645+ ///
646+ /// Connects to the PostgreSQL database at the given `connection_string`, e.g.,
647+ /// `"postgres://user:password@localhost/ldk_db"`.
648+ ///
649+ /// The given `db_name` will be used or default to
650+ /// [`DEFAULT_DB_NAME`](io::postgres_store::DEFAULT_DB_NAME). The `connection_string` must
651+ /// not include a `dbname` when `db_name` is set, providing both is an error. The database
652+ /// will be created automatically if it doesn't already exist. The initial connection is
653+ /// made to the target database, and if it fails we fall back to the default `postgres`
654+ /// database to create it.
655+ ///
656+ /// The given `kv_table_name` will be used or default to
657+ /// [`DEFAULT_KV_TABLE_NAME`](io::postgres_store::DEFAULT_KV_TABLE_NAME).
658+ ///
659+ /// If `tls_config` is `Some`, TLS will be used for database connections. A custom CA
660+ /// certificate can be provided via
661+ /// [`PostgresTlsConfig::certificate_pem`](io::postgres_store::PostgresTlsConfig::certificate_pem),
662+ /// which will be added to the system's default root certificates (not replace them).
663+ /// If `tls_config` is `None`, connections will be unencrypted.
664+ ///
665+ /// [PostgreSQL]: https://www.postgresql.org
666+ #[ cfg( feature = "postgres" ) ]
667+ pub fn build_with_postgres_store (
668+ & self , node_entropy : NodeEntropy , connection_string : String , db_name : Option < String > ,
669+ kv_table_name : Option < String > , tls_config : Option < io:: postgres_store:: PostgresTlsConfig > ,
670+ ) -> Result < Node , BuildError > {
671+ let kv_store = io:: postgres_store:: PostgresStore :: new (
672+ connection_string,
673+ db_name,
674+ kv_table_name,
675+ tls_config,
676+ )
677+ . map_err ( |_| BuildError :: KVStoreSetupFailed ) ?;
678+ self . build_with_store ( node_entropy, kv_store)
679+ }
680+
643681 /// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
644682 /// previously configured.
645683 pub fn build_with_fs_store ( & self , node_entropy : NodeEntropy ) -> Result < Node , BuildError > {
@@ -1102,6 +1140,60 @@ impl ArcedNodeBuilder {
11021140 self . inner . read ( ) . expect ( "lock" ) . build ( * node_entropy) . map ( Arc :: new)
11031141 }
11041142
1143+ /// Builds a [`Node`] instance with a [PostgreSQL] backend and according to the options
1144+ /// previously configured.
1145+ ///
1146+ /// Connects to the PostgreSQL database at the given `connection_string`, e.g.,
1147+ /// `"postgres://user:password@localhost/ldk_db"`.
1148+ ///
1149+ /// The given `db_name` will be used or default to
1150+ /// [`DEFAULT_DB_NAME`](io::postgres_store::DEFAULT_DB_NAME). The `connection_string` must
1151+ /// not include a `dbname` when `db_name` is set, providing both is an error. The database
1152+ /// will be created automatically if it doesn't already exist. The initial connection is
1153+ /// made to the target database, and if it fails we fall back to the default `postgres`
1154+ /// database to create it.
1155+ ///
1156+ /// The given `kv_table_name` will be used or default to
1157+ /// [`DEFAULT_KV_TABLE_NAME`](io::postgres_store::DEFAULT_KV_TABLE_NAME).
1158+ ///
1159+ /// If `tls_config` is `Some`, TLS will be used for database connections. A custom CA
1160+ /// certificate can be provided via
1161+ /// [`PostgresTlsConfig::certificate_pem`](io::postgres_store::PostgresTlsConfig::certificate_pem),
1162+ /// which will be added to the system's default root certificates (not replace them).
1163+ /// If `tls_config` is `None`, connections will be unencrypted.
1164+ ///
1165+ /// [PostgreSQL]: https://www.postgresql.org
1166+ #[ cfg( feature = "postgres" ) ]
1167+ pub fn build_with_postgres_store (
1168+ & self , node_entropy : Arc < NodeEntropy > , connection_string : String , db_name : Option < String > ,
1169+ kv_table_name : Option < String > , tls_config : Option < io:: postgres_store:: PostgresTlsConfig > ,
1170+ ) -> Result < Arc < Node > , BuildError > {
1171+ self . inner
1172+ . read ( )
1173+ . unwrap ( )
1174+ . build_with_postgres_store (
1175+ * node_entropy,
1176+ connection_string,
1177+ db_name,
1178+ kv_table_name,
1179+ tls_config,
1180+ )
1181+ . map ( Arc :: new)
1182+ }
1183+
1184+ /// Builds a [`Node`] instance with a [PostgreSQL] backend and according to the options
1185+ /// previously configured.
1186+ ///
1187+ /// This requires the `postgres` crate feature.
1188+ #[ cfg( not( feature = "postgres" ) ) ]
1189+ pub fn build_with_postgres_store (
1190+ & self , _node_entropy : Arc < NodeEntropy > , _connection_string : String ,
1191+ _db_name : Option < String > , _kv_table_name : Option < String > ,
1192+ _tls_config : Option < io:: PostgresTlsConfig > ,
1193+ ) -> Result < Arc < Node > , BuildError > {
1194+ Err ( BuildError :: KVStoreSetupFailed )
1195+ }
1196+
11051197 /// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
11061198 /// previously configured.
11071199 pub fn build_with_fs_store (
0 commit comments