/**
* Create database client.
*/
const SqlLive = PgClient.layerConfig({
url: Config.redacted('DB_CONNECTION_STRING'),
transformQueryNames: Config.succeed(STR.camelToSnake),
transformResultNames: Config.succeed(STR.snakeToCamel)
});
type AppLayer = IDGenerator | SqlClient.SqlClient;
const createAppRuntime = () => {
// eslint-disable-next-line no-console
console.trace(">>>> Creating App Runtime...");
const AppLive = pipe(
IDGeneratorLive,
Layer.provideMerge(SqlLive),
);
return ManagedRuntime.make(AppLive);
};
export type AppRuntime = ManagedRuntime.ManagedRuntime<
AppLayer,
ConfigError.ConfigError | SqlError.SqlError
>;
const globalForRuntime = global as unknown as { runtime: AppRuntime | undefined };
export const appRuntime =
globalForRuntime.runtime || createAppRuntime();
if (process.env.NODE_ENV !== "production") globalForRuntime.runtime = appRuntime;
/**
* Create database client.
*/
const SqlLive = PgClient.layerConfig({
url: Config.redacted('DB_CONNECTION_STRING'),
transformQueryNames: Config.succeed(STR.camelToSnake),
transformResultNames: Config.succeed(STR.snakeToCamel)
});
type AppLayer = IDGenerator | SqlClient.SqlClient;
const createAppRuntime = () => {
// eslint-disable-next-line no-console
console.trace(">>>> Creating App Runtime...");
const AppLive = pipe(
IDGeneratorLive,
Layer.provideMerge(SqlLive),
);
return ManagedRuntime.make(AppLive);
};
export type AppRuntime = ManagedRuntime.ManagedRuntime<
AppLayer,
ConfigError.ConfigError | SqlError.SqlError
>;
const globalForRuntime = global as unknown as { runtime: AppRuntime | undefined };
export const appRuntime =
globalForRuntime.runtime || createAppRuntime();
if (process.env.NODE_ENV !== "production") globalForRuntime.runtime = appRuntime;