canonical / sqlair

Friendly type mapping for SQL databases
Apache License 2.0
17 stars 9 forks source link

Add support for map inputs and outputs #48

Closed Aflynn50 closed 1 year ago

Aflynn50 commented 1 year ago

This PR allows users to pass map arguments to the query. The maps must have a key type of kind reflect.String. Maps a treated in a similar way to structs.

For inputs one can write in the query x = $M.key and then pass a map called M with key key and the value stored there will be passed to the database as the argument.

For outputs one can either write (col1, col2) AS &M.* or &M.col1. Here, the result columns will be stored with key col1/col2 in the map passed to Decode.

We also add a type sqlair.M = map[string]any that is of a valid type to be used with sqlair.