MCPcopy Create free account
hub / github.com/Effect-TS/effect / MysqlDatabase

Class MysqlDatabase

packages/sql/mysql2/test/utils.ts:7–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5
6// A fresh database on the server started by vitest.globalSetup.ts.
7export class MysqlDatabase extends Context.Service<MysqlDatabase, {
8 readonly url: Redacted.Redacted
9}>()("test/MysqlDatabase") {
10 static readonly layer = Layer.effect(this)(
11 Effect.gen(function*() {
12 const url = new URL(inject("mysqlUrl"))
13 const sql = yield* MysqlClient.make({ url: Redacted.make(url.toString()) })
14 const database = `test_${crypto.randomUUID().replaceAll("-", "")}`
15 yield* sql.unsafe(`CREATE DATABASE ${database}`)
16 url.pathname = `/${database}`
17 return { url: Redacted.make(url.toString()) }
18 }).pipe(
19 Effect.scoped,
20 Effect.provide(Reactivity.layer)
21 )
22 )
23
24 static clientWith = (options: { readonly maxConnections?: number }) =>
25 Layer.unwrap(
26 Effect.gen(function*() {
27 const database = yield* MysqlDatabase
28 return MysqlClient.layer({
29 ...options,
30 url: database.url
31 })
32 })
33 )
34
35 static client = this.clientWith({})
36
37 static layerClient = this.client.pipe(Layer.provide(this.layer))
38
39 static clientWithTransforms = Layer.unwrap(
40 Effect.gen(function*() {
41 const database = yield* MysqlDatabase
42 return MysqlClient.layer({
43 url: database.url,
44 transformQueryNames: String.camelToSnake,
45 transformResultNames: String.snakeToCamel
46 })
47 })
48 )
49}

Callers

nothing calls this directly

Calls 6

injectFunction · 0.85
pipeMethod · 0.65
makeMethod · 0.65
toStringMethod · 0.65
provideMethod · 0.45
layerMethod · 0.45

Tested by

no test coverage detected