mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-30 13:54:01 +00:00
1.8 KiB
1.8 KiB
opencode database guide
Database
- Schema: Drizzle schema lives in
src/**/*.sql.ts. - Naming: tables and columns use snake*case; join columns are
<entity>_id; indexes are<table>*<column>\_idx. - Migrations: generated by Drizzle Kit using
drizzle.config.ts(schema:./src/**/*.sql.ts, output:./migration). - Command:
bun run db generate --name <slug>. - Output: creates
migration/<timestamp>_<slug>/migration.sqlandsnapshot.json. - Tests: migration tests should read the per-folder layout (no
_journal.json).
opencode Effect guide
Instructions to follow when writing Effect.
Schemas
- Use
Schema.Classfor data types with multiple fields. - Use branded schemas (
Schema.brand) for single-value types.
Services
- Services use
ServiceMap.Service<ServiceName, ServiceName.Service>()("@console/<Name>"). - In
Layer.effect, always return service implementations withServiceName.of({ ... }), never a plain object.
Errors
- Use
Schema.TaggedErrorClassfor typed errors. - For defect-like causes, use
Schema.Defectinstead ofunknown. - In
Effect.gen, preferyield* new MyError(...)overyield* Effect.fail(new MyError(...))for direct early-failure branches.
Effects
- Use
Effect.gen(function* () { ... })for composition. - Use
Effect.fn("ServiceName.method")for named/traced effects andEffect.fnUntracedfor internal helpers. Effect.fn/Effect.fnUntracedaccept pipeable operators as extra arguments, so avoid unnecessaryflowor outer.pipe()wrappers.
Time
- Prefer
DateTime.nowAsDateovernew Date(yield* Clock.currentTimeMillis)when you need aDate.
Errors
- In
Effect.gen/fn, preferyield* new MyError(...)overyield* Effect.fail(new MyError(...))for direct early-failure branches.