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

(WIP) feat: postgres stream reading #1371

Draft
wants to merge 4 commits into
base: chore/sync-generator
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"kysely-pglite": "^0.6.0",
"pg": "^8.11.3",
"pg-connection-string": "^2.6.2",
"pg-cursor": "^2.12.1",
"picocolors": "^1.0.0",
"pino": "^8.16.2",
"prom-client": "^15.0.0",
Expand All @@ -87,6 +88,7 @@
"@types/node": "^20.10.0",
"@types/pg": "^8.10.9",
"@types/pg-copy-streams": "^1.2.5",
"@types/pg-cursor": "^2.7.2",
"@types/react": "^18.2.38",
"@viem/anvil": "^0.0.6",
"@wagmi/cli": "^1.5.2",
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
} from "kysely";
import { KyselyPGlite } from "kysely-pglite";
import type { Pool } from "pg";
import Cursor from "pg-cursor";
import prometheus from "prom-client";
import { HeadlessKysely } from "./kysely.js";

Expand Down Expand Up @@ -249,7 +250,9 @@ export const createDatabase = (args: {
internal: new HeadlessKysely({
name: "internal",
common: args.common,
dialect: new PostgresDialect({ pool: driver.internal }),
dialect: new PostgresDialect({
pool: driver.internal,
}),
log(event) {
if (event.level === "query") {
args.common.metrics.ponder_postgres_query_total.inc({
Expand Down Expand Up @@ -288,7 +291,8 @@ export const createDatabase = (args: {
sync: new HeadlessKysely<PonderSyncSchema>({
name: "sync",
common: args.common,
dialect: new PostgresDialect({ pool: driver.sync }),
allowCursor: true,
dialect: new PostgresDialect({ pool: driver.sync, cursor: Cursor }),
log(event) {
if (event.level === "query") {
args.common.metrics.ponder_postgres_query_total.inc({
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/database/kysely.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ export class HeadlessKysely<DB> extends Kysely<DB> {
private common: Common;
private name: string;
private isKilled = false;
readonly allowCursor: boolean;

constructor({
common,
name,
...args
}: (KyselyConfig | KyselyProps) & { name: string; common: Common }) {
}: (KyselyConfig | KyselyProps) & {
name: string;
common: Common;
allowCursor?: boolean;
}) {
super(args);
this.common = common;
this.name = name;
this.allowCursor = args.allowCursor ?? false;
}

override async destroy() {
Expand Down
Loading
Loading