Skip to main content
Use 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

Or with Yarn:
Effect is optional for the ordinary Promise API. Only applications importing esix/effect need it.

Create your first program

Save this complete example as quickstart.ts:
Run it:
Expected output:
Each run inserts a new record into the 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 with Option, typed errors, updates, relationships, configuration, Streams, and testing. The existing model guide applies to both APIs.