Skip to content

Instantly share code, notes, and snippets.

MySQL

expandArgs

expandArgs expands any named args that are slices into multiple named args, one for each element in the slice. This is useful for queries that use the IN operator, e.g. SELECT * FROM table WHERE id IN (:id)

  • If there are no args, the original stmt and args are returned.
  • If there are no slices to expand, the original stmt and args are returned.
  • If the args are positional, the original stmt and args are returned, as we can't expand positional args.
  • Only slices of primitives are supported. Slices of structs or other types are not supported.