Skip to content

Add @effect/sql-pglite package #4692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: next-minor
Choose a base branch
from

Conversation

evelant
Copy link
Contributor

@evelant evelant commented Apr 3, 2025

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Add @effect/sql-pglite package. An @effect/sql driver for PGlite, single user postgresql in the browser or node.

Related

  • Related Issue #
  • Closes #

@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Apr 3, 2025
Copy link

changeset-bot bot commented Apr 3, 2025

🦋 Changeset detected

Latest commit: ad8a7ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/sql-pglite Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-bot effect-bot force-pushed the next-minor branch 5 times, most recently from 02d328c to 1ea11b9 Compare April 4, 2025 15:48
@evelant
Copy link
Contributor Author

evelant commented Apr 4, 2025

Not sure why the lint and docgen failed, they pass on my branch locally.

@effect-bot effect-bot force-pushed the next-minor branch 19 times, most recently from 4cba33b to 5c9e640 Compare April 14, 2025 00:33
@effect-bot effect-bot force-pushed the next-minor branch 2 times, most recently from f265f41 to 0fd314b Compare April 14, 2025 01:59
@effect-bot effect-bot force-pushed the next-minor branch 25 times, most recently from f2312ff to 7e10415 Compare July 21, 2025 22:21
@evelant
Copy link
Contributor Author

evelant commented Jul 22, 2025

@tim-smart Whenever you get a chance I'd appreciate your feedback on this so I can make any necessary changes, thanks!

Migrator.MigrationError | SqlError,
FileSystem | Path | PgliteClient | Client.SqlClient | R2
> = Migrator.make({
dumpSchema(path, table) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does pglite support pg_dump?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executeValues(sql: string, params: ReadonlyArray<Primitive>) {
// PGlite doesn't have a values() method like postgres.js
// We'll just return the regular query results
return this.execute(sql, params, (r) => Object.values(r))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will need an .map here? The results will be an array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I was confused about what executeValues should return. Is it supposed to be an array of arrays of values? That's what this should do since the function param is the row transform, it transforms each row object into an array of values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r will be an array of objects here, so you will need to map over each item.

) {
// PGlite doesn't have a cursor method like postgres.js
// We'll fetch all results at once and convert to a stream
return Stream.fromEffect(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Stream.fromIterableEffect

constructor(private readonly pg: PGlite) {}

private run(query: Promise<any>) {
return Effect.async<ReadonlyArray<any>, SqlError>((resume) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can switch to tryPromise here

extensions: options.extensions ? (client as any) : ({} as any),
listen: (channel: string) =>
Stream.asyncPush<string, SqlError>((emit) =>
Effect.tryPromise({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would use Effect.acquireRelease here. I think this would immediately unsubscribe.

Effect.tryPromise({
try: () => client.query(`NOTIFY ${channel}, '${payload}'`),
catch: (cause) => new SqlError({ cause, message: "Failed to notify" })
}).pipe(Effect.map(() => void 0))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}).pipe(Effect.map(() => void 0))
}).pipe(Effect.asVoid)

@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jul 23, 2025
Comment on lines +16 to +18

test("should work", () => expect(true))
describe("PgliteClient", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test("should work", () => expect(true))
describe("PgliteClient", () => {
describe("PgliteClient", () => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting on Author
Development

Successfully merging this pull request may close these issues.

5 participants