Custom database clients
Included clients
We have support for two clients:
The pg client can be used as follows:
import { ,  } from "sidetrack";
import {  } from "pg";
 
// You can also use a pg.Client instead of a pg.Pool
const  = new ();
 
const  = new <{
  : { : string };
}>({
  : {
    : .["DATABASE_URL"]!,
  },
  : {
    : {
      : async (, ) => {
        .(`Welcome ${.}`);
      },
    },
  },
  // This will apply to all methods available on sidetrack
  : (),
});
 
// You can also override the connection per method
.(
  "userOnboarding",
  { : "hello@example.com" },
  {
    : (),
  },
);Similarly, the @sidetrack/client-prisma package exposes a usePrisma function that can be used to create a client that works with prisma. You can find the documentation for it here .
With this custom client, you can now run most of the functions that are
available within the Sidetrack class in a transaction. Pass in a client
that’s running within a transaction, and it “just works”!
Creating your own client
Sidetrack is designed to support working with your database client library of choice, as long as it works with the databases that are supported by sidetrack. To do this, you need to implement the SidetrackDatabaseClient interface, which you can find here . It currently has one method called execute.
For example, you can find the implementation of the usePg function here