Skip to content

Commit

Permalink
replace unit with void in @effect/sql
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored and mikearnaldi committed Apr 16, 2024
1 parent 2fb7d9c commit c55bcf9
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion packages/sql-mssql/examples/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const program = Effect.gen(function*(_) {
Effect.zipRight(
Effect.catchAllCause(
sql.withTransaction(Effect.die("fail")),
(_) => Effect.unit
(_) => Effect.void
)
),
Effect.zipRight(
Expand Down
12 changes: 6 additions & 6 deletions packages/sql-mssql/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const make = (
if (error) {
resume(Effect.fail(new SqlError({ error })))
} else {
resume(Effect.unit)
resume(Effect.void)
}
})
})
Expand Down Expand Up @@ -265,7 +265,7 @@ export const make = (
if (error) {
resume(Effect.fail(new SqlError({ error })))
} else {
resume(Effect.unit)
resume(Effect.void)
}
})
}),
Expand All @@ -274,7 +274,7 @@ export const make = (
if (error) {
resume(Effect.fail(new SqlError({ error })))
} else {
resume(Effect.unit)
resume(Effect.void)
}
})
}),
Expand All @@ -284,7 +284,7 @@ export const make = (
if (error) {
resume(Effect.fail(new SqlError({ error })))
} else {
resume(Effect.unit)
resume(Effect.void)
}
}, name)
}),
Expand All @@ -294,7 +294,7 @@ export const make = (
if (error) {
resume(Effect.fail(new SqlError({ error })))
} else {
resume(Effect.unit)
resume(Effect.void)
}
}, name)
})
Expand Down Expand Up @@ -351,7 +351,7 @@ export const make = (
([scope, conn, id], exit) => {
const effect = Exit.isSuccess(exit)
? id > 0
? Effect.unit
? Effect.void
: Effect.orDie(conn.commit)
: Effect.orDie(conn.rollback(id > 0 ? `effect_sql_${id}` : undefined))
return scope !== undefined ? Effect.ensuring(effect, Scope.close(scope, exit)) : effect
Expand Down
2 changes: 1 addition & 1 deletion packages/sql-mssql/src/Migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const run: <R>(
)`
},
dumpSchema(_sql, _path, _table) {
return Effect.unit
return Effect.void
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/sql-mysql2/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const make = (

yield* _(Effect.addFinalizer(() =>
Effect.async<void>((resume) => {
pool.end(() => resume(Effect.unit))
pool.end(() => resume(Effect.void))
})
))

Expand Down
2 changes: 1 addition & 1 deletion packages/sql-sqlite-bun/test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { describe, it } from "@effect/vitest"
import { Effect } from "effect"

describe("Client", () => {
it.effect("should work", () => Effect.unit)
it.effect("should work", () => Effect.void)
})
5 changes: 1 addition & 4 deletions packages/sql-sqlite-react-native/src/Migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import type { SqlError } from "@effect/sql/Error"
import * as Migrator from "@effect/sql/Migrator"
import * as Effect from "effect/Effect"
import type * as Effect from "effect/Effect"
import * as Layer from "effect/Layer"
import * as Client from "./Client.js"

Expand Down Expand Up @@ -32,9 +32,6 @@ export const run: <R>(
name VARCHAR(255) NOT NULL
)
`
},
dumpSchema(_sql, _path, _table) {
return Effect.unit
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/sql-sqlite-react-native/test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { describe, it } from "@effect/vitest"
import { Effect } from "effect"

describe("Client", () => {
it.effect("should work", () => Effect.unit)
it.effect("should work", () => Effect.void)
})
5 changes: 1 addition & 4 deletions packages/sql-sqlite-wasm/src/Migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import type { SqlError } from "@effect/sql/Error"
import * as Migrator from "@effect/sql/Migrator"
import * as Effect from "effect/Effect"
import type * as Effect from "effect/Effect"
import * as Layer from "effect/Layer"
import * as Client from "./Client.js"

Expand Down Expand Up @@ -32,9 +32,6 @@ export const run: <R>(
name VARCHAR(255) NOT NULL
)
`
},
dumpSchema(_sql, _path, _table) {
return Effect.unit
}
})

Expand Down
2 changes: 1 addition & 1 deletion packages/sql-sqlite-wasm/test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { describe, it } from "@effect/vitest"
import { Effect } from "effect"

describe("Client", () => {
it.effect("should work", () => Effect.unit)
it.effect("should work", () => Effect.void)
})
8 changes: 4 additions & 4 deletions packages/sql/src/Migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ export class MigrationError extends Data.TaggedError("MigrationError")<{
* @since 1.0.0
*/
export const make = <R extends Client, RD, RE, RL, R2 = never>({
dumpSchema,
dumpSchema = () => Effect.void,
ensureTable,
getClient,
lockTable = () => Effect.unit
lockTable = () => Effect.void
}: {
getClient: Effect.Effect<R, SqlError, R>
dumpSchema: (
ensureTable: (sql: R, table: string) => Effect.Effect<void, SqlError, RE>
dumpSchema?: (
sql: R,
path: string,
migrationsTable: string
) => Effect.Effect<void, MigrationError, RD>
ensureTable: (sql: R, table: string) => Effect.Effect<void, SqlError, RE>
lockTable?: (sql: R, table: string) => Effect.Effect<void, SqlError, RL>
}) =>
({
Expand Down
6 changes: 3 additions & 3 deletions packages/sql/src/Resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export const findById = <T extends string, I, II, RI, A, IA, Row, E, RA = never,
const id = options.ResultId(result, rawResults[i])
const request = idMap.get(id)
if (request === undefined) {
return Effect.unit
return Effect.void
}
idMap.delete(id)
return Request.succeed(request, Option.some(result))
Expand All @@ -382,7 +382,7 @@ export const findById = <T extends string, I, II, RI, A, IA, Row, E, RA = never,
),
Effect.tap((_) => {
if (idMap.size === 0) {
return Effect.unit
return Effect.void
}
return Effect.forEach(
idMap.values(),
Expand Down Expand Up @@ -431,7 +431,7 @@ const void_ = <T extends string, I, II, RI, E, R = never>(
Effect.andThen(
Effect.forEach(
requests,
(request) => Request.complete(request, Exit.unit),
(request) => Request.complete(request, Exit.void),
{ discard: true }
)
),
Expand Down
2 changes: 1 addition & 1 deletion packages/sql/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const void_ = <IR, II, IA, R, E>(
) => {
const encode = Schema.encode(options.Request)
return (request: IA): Effect.Effect<void, E | ParseError, R | IR> =>
Effect.asUnit(
Effect.asVoid(
Effect.flatMap(encode(request), options.execute)
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sql/src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const asyncPauseResume = <A, E = never, R = never>(

const offer = (chunk: Chunk.Chunk<A>) =>
Queue.isFull(queue).pipe(
Effect.tap((full) => (full ? effects.onPause : Effect.unit)),
Effect.tap((full) => (full ? effects.onPause : Effect.void)),
Effect.zipRight(Queue.offer(queue, chunk)),
Effect.zipRight(effects.onResume)
)
Expand Down
2 changes: 1 addition & 1 deletion packages/sql/src/internal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function make({
([scope, conn, id], exit) => {
const effect = Exit.isSuccess(exit)
? id > 0
? Effect.unit
? Effect.void
: Effect.orDie(conn.executeRaw(commit))
: id > 0
? Effect.orDie(conn.executeRaw(rollbackSavepoint(`effect_sql_${id}`)))
Expand Down

0 comments on commit c55bcf9

Please sign in to comment.