Creates a new DbHelper instance
Configuration object
The B2B database instance to use for queries
Usage:
db.select().from(myTable).where(
eq(
myTable.customerId,
dbHelper.customerInternalId({ customerId })
)
)
Query parameters
Customer external ID
Optionaltx?: B2bPgTransactionOptional database transaction to use
Query that returns internal ID for customer
Helper for "with ... insert" where we need to provide identity or organization id
This is suitable for tables that store entity references as mutually-exclusive populated identity ID and organization ID.
Usage:
const { entityWith, entityInsertFields } = dbHelper.entityInsertWith({
entityId,
customerId,
});
const results = await this.db
.with(entityWith)
.insert(myTable)
.values({
...input,
...entityInsertFields,
});
You may need to rename entityInsertFields if you are not using the
standard identity_id and organization_id columns in your table,
or omit customer_id if this is not used in your table.
Query parameters
Customer external ID that owns the entity
Either identity or organization external ID
Optionalname?: stringName for the WITH clause (defaults to "entity")
Optionaltx?: B2bPgTransactionOptional database transaction to use
Object containing entityWith that can be plugged into WITH clause and
entityInsertFields fields that can be used in the VALUES of INSERT
Usage:
db.select().from(myTable).where(
eq(
myTable.identityId,
dbHelper.identityInternalId({ identityId, customerId })
)
)
Query parameters
Customer external ID that owns the identity
Identity external ID
OptionalincludeCustomerInternalId?: booleanWhether to include customer internal ID in result
Optionaltx?: B2bPgTransactionOptional database transaction to use
Query that returns internal ID for identity, belonging to given customer
Usage:
db.select().from(myTable).where(
eq(
myTable.organizationId,
dbHelper.organizationInternalId({ organizationId, customerId })
)
)
Query parameters
Customer external ID that owns the organization
OptionalincludeCustomerInternalId?: booleanWhether to include customer internal ID in result
Organization external ID
Optionaltx?: B2bPgTransactionOptional database transaction to use
Query that returns internal ID for organization
A collection of helpers for aggressively common patterns used in our services
Instantiate this in your service class, do not expose to outside