Code Review: Side Effects Injection Approach
Hi, can any masters here check if this is good approach to inject side effects in the end ? or is there simpler way ?
import { Console, Context, Effect, Layer } from "effect";
import db from "./db/db";
import * as schema from "./db/schema";
class App extends Context.Tag("App")<
App,
{ readonly db: typeof db; readonly schema: typeof schema }
>() {}
const main = Effect.gen(function* () {
const { db, schema } = yield* App;
const { notice } = schema;
const res = yield* Effect.promise(() => db.select().from(notice).limit(1));
yield* Console.log(res);
});
const appLive = Layer.succeed(App, { db, schema });
const runnable = Effect.provide(main, appLive);
await Effect.runPromise(runnable);import { Console, Context, Effect, Layer } from "effect";
import db from "./db/db";
import * as schema from "./db/schema";
class App extends Context.Tag("App")<
App,
{ readonly db: typeof db; readonly schema: typeof schema }
>() {}
const main = Effect.gen(function* () {
const { db, schema } = yield* App;
const { notice } = schema;
const res = yield* Effect.promise(() => db.select().from(notice).limit(1));
yield* Console.log(res);
});
const appLive = Layer.succeed(App, { db, schema });
const runnable = Effect.provide(main, appLive);
await Effect.runPromise(runnable);