MCPcopy
hub / github.com/Effect-TS/effect / make

Function make

packages/sql/src/SqlEventJournal.ts:18–274  ·  view source on GitHub ↗
(options?: {
  readonly entryTable?: string
  readonly remotesTable?: string
})

Source from the content-addressed store, hash-verified

16 * @category constructors
17 */
18export const make = (options?: {
19 readonly entryTable?: string
20 readonly remotesTable?: string
21}): Effect.Effect<
22 typeof EventJournal.EventJournal.Service,
23 SqlError,
24 SqlClient.SqlClient
25> =>
26 Effect.gen(function*() {
27 const sql = yield* SqlClient.SqlClient
28
29 const entryTable = options?.entryTable ?? "effect_event_journal"
30 const remotesTable = options?.remotesTable ?? "effect_event_remotes"
31
32 yield* sql.onDialectOrElse({
33 pg: () =>
34 sql`
35 CREATE TABLE IF NOT EXISTS ${sql(entryTable)} (
36 id UUID PRIMARY KEY,
37 event TEXT NOT NULL,
38 primary_key TEXT NOT NULL,
39 payload BYTEA NOT NULL,
40 timestamp BIGINT NOT NULL
41 )`.withoutTransform,
42 mysql: () =>
43 sql`
44 CREATE TABLE IF NOT EXISTS ${sql(entryTable)} (
45 id BINARY(16) PRIMARY KEY,
46 event TEXT NOT NULL,
47 primary_key TEXT NOT NULL,
48 payload BLOB NOT NULL,
49 timestamp BIGINT NOT NULL
50 )`.withoutTransform,
51 mssql: () =>
52 sql`
53 CREATE TABLE IF NOT EXISTS ${sql(entryTable)} (
54 id UNIQUEIDENTIFIER PRIMARY KEY,
55 event NVARCHAR(MAX) NOT NULL,
56 primary_key NVARCHAR(MAX) NOT NULL,
57 payload VARBINARY(MAX) NOT NULL,
58 timestamp BIGINT NOT NULL
59 )`.withoutTransform,
60 orElse: () =>
61 sql`
62 CREATE TABLE IF NOT EXISTS ${sql(entryTable)} (
63 id BLOB PRIMARY KEY,
64 event TEXT NOT NULL,
65 primary_key TEXT NOT NULL,
66 payload BLOB NOT NULL,
67 timestamp BIGINT NOT NULL
68 )`.withoutTransform
69 })
70
71 yield* sql.onDialectOrElse({
72 pg: () =>
73 sql`
74 CREATE TABLE IF NOT EXISTS ${sql(remotesTable)} (
75 remote_id UUID NOT NULL,

Callers 1

layerFunction · 0.70

Calls 7

NumberInterface · 0.85
ofMethod · 0.65
pipeMethod · 0.65
mapMethod · 0.65
addMethod · 0.65
subscribeMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected