Skip to content
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

live queries #1408

Merged
merged 46 commits into from
Jan 17, 2025
Merged

live queries #1408

merged 46 commits into from
Jan 17, 2025

Conversation

kyscott18
Copy link
Collaborator

No description provided.

packages/client/src/index.ts Outdated Show resolved Hide resolved

sse.onmessage = (event) => {
// @ts-ignore
callback(prepared.mapResult(JSON.parse(event.data), true).rows);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any error handling to consider here as well?

packages/core/src/client/index.ts Outdated Show resolved Hide resolved
packages/core/src/client/index.ts Outdated Show resolved Hide resolved
packages/core/src/client/index.ts Outdated Show resolved Hide resolved
packages/core/src/client/index.ts Outdated Show resolved Hide resolved
packages/client/src/index.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@typedarray typedarray left a comment

Choose a reason for hiding this comment

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

Looks great, nothing blocking prerelease.

Comment on lines 182 to 189
} else {
return client.live(
(db) => db.select().from(status),
() => {
_query(client.db).then(onData).catch(onError);
},
onError,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Slightly strange block lol but I follow


build.initNamespace({ isSchemaRequired: false });
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicate

Comment on lines 55 to 59
if (listenConnection) {
if (listenConnection.dialect === "postgres") {
listenConnection.connection.release();
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is listenConnection not a property of database ? They seem to be passed around together.

Comment on lines 76 to 78
} catch (error) {
return c.text((error as Error).message, 500);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

May want to strip some of the details from this error object before returning, but can add this after prerelease.

}),
});
}
statusResult = await statusResolver.promise;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This waits for the next status update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

export const client = ({ db }: { db: ReadonlyDrizzle<Schema> }) => {
// @ts-ignore
const session: PgSession = db._.session;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean all queries will use the same connection? Seems important to use a pool here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Variable wasn't being used, deleted

Comment on lines 1018 to 1039
await sql
.raw(`
CREATE OR REPLACE FUNCTION ${notification}
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NOTIFY ${channel};
RETURN NULL;
END;
$$;`)
.execute(qb.internal);

await sql
.raw(`
CREATE OR REPLACE TRIGGER ${trigger}
AFTER INSERT OR UPDATE OR DELETE
ON "${preBuild.namespace}"._ponder_status
FOR EACH STATEMENT
EXECUTE PROCEDURE ${notification};`)
.execute(qb.internal);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

My instinct is that these should happen in the same spot that we create the _ponder_status table (if not exists).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is that the function that creates the status table (migrate()) isn't always run when getListenConnection() is run. For example the serve command. We might be able to come up with a better solution than I have now but that was my original reason for making this change.

if (dialect === "postgres") {
return {
dialect: "postgres",
connection: await (driver as PostgresDriver).internal.connect(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if this connection drops?

kyscott18 and others added 4 commits January 10, 2025 12:32
* @ponder/react

* example working

* include all react-query options

* fix react build

* client docs

* react docs

* docs:

---------

Co-authored-by: typedarray <90073088+0xOlias@users.noreply.github.com>
kyscott18 and others added 6 commits January 13, 2025 18:09
* react packaging wip

* build script

* quick fix for entrypoint issue

* test recursive

* fix postinstall

* fix server logs and port regression

* fix graphql middleware issue

* example cleanup

* docs

---------

Co-authored-by: typedarray <90073088+0xOlias@users.noreply.github.com>
@kyscott18 kyscott18 merged commit c8e412a into v0.9 Jan 17, 2025
8 checks passed
@kyscott18 kyscott18 deleted the kjs/live branch January 17, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants