nesting db calls in transactions without using the callback argument

What is the point of the trx argument when calling db.transaction()?
when using raw sql, a transaction looks something like

BEGIN TRANSACTION
INSERT into whatever values something returning id;
INSERT into otherWhatever values somertinhElse;
COMMIT;

so the queries don't really have to "know" that they are inside a transaction, so my question is, is this possible?
  const insertedPropId = await db.transaction(async (trx) => {
    // insertPlaceDetails calls the db DIRECTLY, instead of something like
    // trx.insert()
    const insertedPlaceData = await insertPlaceDetails([
      location.latitude,
      location.longitude,
    ]);
    const [insertedProperty] = await db
      .insert(propertiesTable)
      .values(propertyData)
      .returning({ id: propertiesTable.id });
    return insertedProperty.id;
  });
  return insertedPropId;
};


if this is not possible: is there any way of nesting inserts without passing the trx argument around? I'd rather keep those things outside functions like insertPlaceDetails, which would now need to "know" about its context. Thanks!
Was this page helpful?