Creates a new DbHelper instance
Configuration object
The B2B database instance to use for queries
Returns a scalar subquery resolving an ACTIVE, non-deleted product
route's internal id from its external id. Used by rule-admin services
to attach rules to routes inline in INSERT — if no row matches, the
subquery yields NULL and the FK on route_id rejects the insert.
Returns a scalar subquery resolving a bank's internal id from its
external id (the literal BankId). Used inline in INSERT/UPDATE
to populate bank_id int FK columns without a separate round trip.
Returns a scalar subquery (SELECT id FROM customer WHERE external_id = ?)
wrapped in parens, usable anywhere an SQL<number> is accepted — including
insert values, eq(col, ...) conditions, and inArray(col, ...).
Resolve the external id of the owning entity (identity or organization)
for a row that left-joins both identity and organization. Returns
NULL when neither side is joined.
Caller is responsible for the joins — see LedgerAccountService.search
for the canonical pattern.
Resolve the display name of the owning entity (identity or organization)
for a row that left-joins both identity and organization. Identity
names are formatted via identityFullName; organization names use
organization.name directly. Returns NULL when neither side is joined.
Resolve the customer-supplied reference id of the owning entity (identity
or organization) for a row that left-joins both identity and
organization. Returns NULL when neither side has a reference id set.
Resolve the type tag ('IDENTITY' | 'ORGANIZATION') of the owning
entity for a row that left-joins both identity and organization.
Returns NULL when neither side is joined.
Format the jsonb identity.name column ({firstName, middleName?, lastName})
as a single text value: "First [Middle] Last". Returns NULL when the
column is NULL or the resulting trimmed string is empty.
Pair with coalesce() to derive an "owning entity name" projection that
falls back to organization / customer names — see
LedgerAccountService.search for the canonical pattern.
Returns a scalar subquery resolving an identity's internal id from its external id, scoped to the owning customer.
Returns a scalar subquery resolving a ledger account's internal id from its external id, optionally scoped to the owning customer.
Ledger accounts are owned by exactly one customer — pass customerId
whenever the caller knows the owning customer, for defense-in-depth
against cross-tenant IDOR. Omit customerId only for system-managed
accounts (e.g. master fee accounts owned by the platform) where the
caller doesn't naturally know the owning customer.
Returns a scalar subquery resolving an organization's internal id from its external id, scoped to the owning customer.
Returns a scalar subquery resolving a product's internal id from its
external id. Accepts any ProductName, including the routing
wildcards (deposit.* / withdraw.*), all of which exist as rows in
b2b.product.
Returns a scalar subquery resolving a product_quote's internal id from
its external id (the public-facing quoteId nanoid). Used by rail-quote
services (deposit/withdrawal) to populate product_quote_id int FK
columns from the string quoteId returned by ProductQuoteService.quote(),
without an extra round trip. Optional customerId adds defense-in-depth
cross-tenant scoping when the caller knows the owning customer.
A collection of helpers for aggressively common patterns used in our services. Instantiated automatically by createDrizzle and attached as
db.helpers.