Effect CommunityEC
Effect Community2y ago
1 reply
Tim Smart

Breaking Change Notice: `@effect/sql` Client Context Tag Moved

Hello @1110198784417345608 !

If you are using @effect/sql, a breaking change will be released soon that moves the main sql client Context.Tag to the core package.

Here is the PR: https://github.com/Effect-TS/effect/pull/2693

From the changeset:

---

All of the client implementations now share the same Context.Tag. This means you can create
services that support multiple SQL flavors.

You can now use the @effect/sql package to access the client apis:

import * as Sql from "@effect/sql"
import { Effect } from "effect"

Effect.gen(function* () {
  const sql = yield* Sql.client.Client
  yield* sql`SELECT * FROM users`
})


If you need a functionality that is specific to a implementation, you can use the tag from the
implementation package:

import * as Sqlite from "@effect/sql-sqlite-node"
import { Effect } from "effect"

Effect.gen(function* () {
  const sql = yield* Sqlite.client.SqliteClient
  const dump = yield* sql.export
})


If you need to run a different query depending on the dialect, you can use the sql.onDialect api:

import * as Sql from "@effect/sql"
import { Effect } from "effect"

Effect.gen(function* () {
  const sql = yield* Sql.client.Client
  yield* sql.onDialect({
    sqlite: () => sql`SELECT * FROM sqlite_master`,
    mysql: () => sql`SHOW TABLES`,
    mssql: () => sql`SELECT * FROM sys.tables`,
    pg: () => sql`SELECT * FROM pg_catalog.pg_tables`
  })
})
Was this page helpful?