// db.ts
class DBService { }
export const DBServiceLive = Layer.effect(
DBService,
CreateDBServiceEffect, // creates a database connection and initial value
);
// lib/actions
const defaultLayer = Layer.provideMerge(DBServiceLive, ...)
// lib/feature1
"use server";
export const feature1 = () => {
// creates a new database connection on every invocation
const program = getFeature1().pipe(Effect.provide(defaultLayer))
return Effect.runPromise(program)
}
// db.ts
class DBService { }
export const DBServiceLive = Layer.effect(
DBService,
CreateDBServiceEffect, // creates a database connection and initial value
);
// lib/actions
const defaultLayer = Layer.provideMerge(DBServiceLive, ...)
// lib/feature1
"use server";
export const feature1 = () => {
// creates a new database connection on every invocation
const program = getFeature1().pipe(Effect.provide(defaultLayer))
return Effect.runPromise(program)
}