esix/effect to run Esix queries inside an Effect program. Your models
still extend BaseModel; database operations return lazy Effects.
Prerequisites
- Node.js 20 or newer.
- MongoDB running locally on port 27017, or a MongoDB connection URL.
- Effect 3.21.3 or newer within major version 3. Effect 4 is not supported by this entry point.
Install
esix/effect need it.
Create your first program
Save this complete example asquickstart.ts:
users collection. create() supplies
the model defaults, id, and timestamps. Constructing the program does no
database work; Effect.runPromise executes it.
Esix.model(User) can be defined at module scope. Its operations carry the
Esix requirement in their types; providing live supplies the connection when
they execute.
For environment-based configuration, use Esix.Default instead of live: it
reads the required DB_URL and optional DB_DATABASE through Effect Config.
Use Esix.layerConfig(...) to customize configuration keys or defaults.
The Layer opens its own MongoDB client and closes it when the program finishes,
including on failure. In a server, provide the Layer for the application’s
lifetime so requests share its connection pool.
Next steps
The Effect integration guide covers missing records withOption, typed errors, updates, relationships, configuration, Streams, and
testing. The existing model guide applies to both APIs.