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

Open
wants to merge 20 commits into
base: v0.9
Choose a base branch
from
Open

live queries #1408

wants to merge 20 commits into from

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.

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).

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?

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