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

[Drizzle] Issue: Type Error When Inserting #477

Open
michael-learns opened this issue Jan 22, 2025 · 7 comments
Open

[Drizzle] Issue: Type Error When Inserting #477

michael-learns opened this issue Jan 22, 2025 · 7 comments

Comments

@michael-learns
Copy link

I have the following code.

const space = await db.insert(spaces).values({ id: '90', name: values.spaceName })

But I'm getting this error instead:

Image

I looked it up and it possible could be a type error.

@Chriztiaan
Copy link
Contributor

Hey @michael-learns, could you possibly give more context? What does your database schema look like?

@Chriztiaan
Copy link
Contributor

We have an example insert in this test. With a schema definition at the top of the file.

@michael-learns
Copy link
Author

michael-learns commented Feb 4, 2025

Hi @Chriztiaan ! Sorry for my late reply. So this is how I structured my AppSchema.

Image

And this is how the spaces schema looks like

Image

Then all together it looks like this

Image

When doing my query I simply import db from powersync.ts and then injected my space schema.

@Chriztiaan
Copy link
Contributor

Chriztiaan commented Feb 4, 2025

Hey @michael-learns I might need minimal repo that reproduces the problem. As a note about the id, you will likely need to make that id: text('id') - with PowerSync the id column is automatically created as a column of type TEXT. I would also recommend using a uuid() value instead of auto incrementing as auto incrementing integer IDs don't work well when synced up (multiple clients might have conflicting entities with the same id).

@michael-learns
Copy link
Author

I'll try to give you a minimal repo. I've turned off typescript for that specific file for now.

Thanks for the heads up on the id column!
How do I reset my local db to reflect the changes? I'm assuming I just need to delete it from my local storage?

@michael-learns
Copy link
Author

After applying the changes the app works when it's offline. However when syncing to supabase it conflicts with the default ID column which is just an int compared to uuid which is a bigint. @Chriztiaan

@Chriztiaan
Copy link
Contributor

For tables where clients will create new rows, it's recommended to use UUIDs for the id field in the backend too.

Could you possibly give more context of what backend you are using, I am assuming Postgres? If this a new project, I would recommend using a text/uuid column on your backend. If this is an established backend where using an int ID is must, please see https://docs.powersync.com/usage/sync-rules/client-id.

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

No branches or pull requests

2 participants