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

Type safety is not being adhered on insert queries #508

Open
dvrfluxchat opened this issue Nov 28, 2023 · 4 comments
Open

Type safety is not being adhered on insert queries #508

dvrfluxchat opened this issue Nov 28, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@dvrfluxchat
Copy link

dvrfluxchat commented Nov 28, 2023

I have a insert query in my db which looks like this and I am using the typescript version of supabase-js.

await supaServiceClient
        .from("table_name")
        .insert({
          column1:value,
          column2:value,
          column3:value
        });

I changed the column "column1" to "newColumn1" but the above query did not throw any errors where there is no "column1". This lead to issues in production where this query stopped working as the insert was failing saying there is no column1 but the compiler did not throw any error. Is this the expected behaviour? If so how do i ensure to get compile time warnings for such scenarios.

@dvrfluxchat dvrfluxchat added the bug Something isn't working label Nov 28, 2023
@steve-chavez steve-chavez transferred this issue from supabase/supabase-js Nov 28, 2023
@tecoad
Copy link

tecoad commented May 4, 2024

I have the same issue. Did you find out @dvrfluxchat ?

@FilipPano
Copy link

I am experiencing the same issue. There is no type safety on insert for values that are not part of your table schema.

E.g

const {data, error} = await supaServiceClient
        .from("table_name")
        .insert({
          column1:value, // this exists as a column in table_name
          column2:value, // this exists too
          column3:value // this does not
        }).select("*");

I think It should throw a type error letting you know that there is no column3 column in your table.

@Lambtsa
Copy link

Lambtsa commented Sep 22, 2024

A little irritating that queries are not typesafe automatically if the dbClient is typed but the queries are generic so passing in a type definition will solve this issue

export const insertCountry = async () => {
  return await supabaseClient
    .from('country')
    .insert<UpsertCountryInput>([
      { name: 'Nepal' },
      { name: 'Vietnam' },
    ]);
};

@avallete
Copy link
Member

Still seems to be an issue where extra invalids parameters are juste silently dismissed if the object have all the other properties it need:
Screenshot 2024-10-18 at 11 09 23
Screenshot 2024-10-18 at 11 10 42

I'm not sure this is really a bug tough or an intended behaviour, I can see this come handy if you have things like:

  const res = await postgrest
    .from('users')
    .insert({
      ...someObjectWithExtraKeys
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants