Skip to content

Storing part of a query in a variable and reusing it causes unexpected behaviors #767

Open
@dshukertjr

Description

@dshukertjr

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Storing part of a query in a variable is a common pattern in Firebase development. Right now because our client library is not immutable, when you try to do this with Supabase client library, some of the information is kept in the original instance causing unexpected behaviors.

const restaurantsTable = supabase.from('restaurants')

const { data: restaurant } = await restaurantsTable.select().eq('id', id).single()
const { data: restaurants } = await restaurantsTable.select() // the query here will contain the `eq` and `single` statement from the previous line, therefore returning a single restaurant.

Expected behavior

Storing part of a query in a variable and running multiple queries using it should return the proper data.

const restaurantsTable = supabase.from('restaurants')

const { data: restaurant } = await restaurantsTable.select().eq('id', id).single()
const { data: restaurants } = await restaurantsTable.select() // `restaurants` contains the unfiltered query result.

Additional context

Maybe this is something to keep in mind when doing the next major release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions