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

Design suggestions for beta CDC support #243

Open
JayJamieson opened this issue Jul 29, 2024 · 0 comments
Open

Design suggestions for beta CDC support #243

JayJamieson opened this issue Jul 29, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@JayJamieson
Copy link

I've been looking into the new beta /listen endpoint and wondering how consumers would be using this from Typescript SDK.

There is currently no "native" support for SSE on the server side (nodejs process) for SSE that supports authorization headers.

I did manage to find a polly-fill of sorts that adds support for headers and usable from nodejs

API Suggestion

The browser based SSE implementation is based on EventEmitter interface and I think its a good idea to stick to that, would async/await being common we should support that too.

We could expose a cdc property with on(...) method for supported events insert | update | delete.

const turso = createClient({
  url: process.env.TURSO_DATABASE_URL,
  authToken: process.env.TURSO_AUTH_TOKEN,
});

// non-async
turso.cdc.on("insert", "myTable", (event) => {
 // user code here
});

// async
turso.cdc.on("insert", "myTable", async (event) => {
 // user code here
});

Small problem is that current implementation doesn't provide information about what's actually changed, it's just a signal to say an event of insert | update | delete as occurred.

User on discord notrab suggested using triggers to track changes and manage a audit log table. I had a similar idea in previous discussion of CDC and think its clever and probably easiest to implement.

Decision now becomes, does this belong in the SDK as a plugin/extension that allows the user to install the triggers and audit log table OR should this be in documentation that a user will need to manually install ?

My two cents would be that we manage this as some sort of plugin/extension that is opt-in and is an optional configuration property. I think it could work like this:

  1. configure plugin in createClient constructor
  2. createClient would install triggers and name spaced audit log table
  3. consumer can register turso.cdc.on(...) handlers and listen for events
  4. "closing" the client should uninstall triggers and audit log table

Let me know your thoughts. I would also be happy to start on a prototype to get a feel for what works well internally and is easy to manage from consumer side.

Cheers.

@penberg penberg added the enhancement New feature or request label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants