Skip to content

Conversation

@LuisDuarte1
Copy link
Contributor

This API abbreviates the usage of (field, test) IN (VALUES (?, ?), (?, ?)) in where conditions by dynamically constructing this query dynamically depending on the number of fields given and the length of values given.

This makes it really easy to build dynamic queries that filter by multiple status:

db.select('employee').whereIn('role', ["eng", "hr", "sales"])

It will generate something like this sql:

SELECT * FROM employee WHERE (role) IN (VALUES ('eng'), ('hr'), ('sales));

This is SQL syntax supported by both postgres and SQLite (therefore D1 and DOs too)

Or we can use this for multiple fields at the same time:

db.select('employee').whereIn(['role', 'team'], [["eng", "workers"], ["eng", "workflows"]])

Also, we make the arguments to whereIn typesafe:

  • whereIn fields only support a string or a array of strings
  • whereIn values are checked against the fields type (if the field type is a string, means that we can only pass a Primitive list, otherwise, if the field type is an array of strings, means that we must pass a list of a list of primitives)

This API abbreviates the usage of `(field, test) IN (VALUES (?, ?), (?, ?))` in where
conditions by dynamically constructing this query dynamically
depending on the number of fields given and the length of values given.

This makes it really easy to build dynamic queries that filter by
multiple status:

`db.select('employee').whereIn('role', ["eng", "hr", "sales"])`

It will generate something like this sql:

`SELECT * FROM employee WHERE (role) IN (VALUES ('eng'), ('hr'), ('sales));`

This is SQL syntax supported by both postgres and SQLite (therefore D1
and DOs too)

Or we can use this for multiple fields at the same time:

`db.select('employee').whereIn(['role', 'team'], [["eng", "workers"], ["eng", "workflows"]])`

Also, we make the arguments to `whereIn` typesafe:
 - whereIn fields only support a string or a array of strings
 - whereIn values are checked against the fields type (if the field type
   is a string, means that we can only pass a Primitive list, otherwise,
   if the field type is an array of strings, means that we must pass a
   list of a list of primitives)
@G4brym G4brym merged commit d9294d9 into G4brym:main Dec 16, 2024
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

Successfully merging this pull request may close these issues.

2 participants