Skip to content

feature: findUnique or throw #16

@capaj

Description

@capaj

would be nice to be able to use this for cases where we're loading an entity by an ID and we're like 99.9 percent sure it will be found and we don't want to clog up the code with extra typesafety checks for undefined every time

const result = await db.query.user.findUnique({
  where: {
    id: 42,
  },
})
// => { id: 42, name: 'Chewbacca' } | undefined

const result = await db.query.user.findUniqueOrThrow({
  where: {
    id: 42,
  },
})
// => { id: 42, name: 'Chewbacca' }

would be nice if the thrown error was something like: could not find user with id 1 rather than could not find user

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions