Skip to content

Add $where() method to db.query #8

Description

@aleclarson

This idea was suggested by Discord user @josefchi.

Essentially, it accepts the same value that db.query#findMany's where option does. But instead of executing a query, it returns a SQL instance, which you can use with db.select() calls, db.update() calls, etc.

Internally, it would call relationsFilterToSQL. Its main purpose is to provide type safety and auto-completion.

const where = db.query.user.$where({
  age: { gte: 18 },
})
// => [object SQL]

where.toSQL()
// => {
//   sql: `"user"."age" >= ?`,
//   params: [18],
// }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions