Db.Decode
Decode SQL results into Gren values.
These are typically used in the Db.get*
functions via the decoder
field,
where the string value matches the name of the field in the query.
For example:
-- Assuming a table with id INTEGER, name TEXT
Db.getOne connection
{ query = "select * from users where id = :id"
, parameters = [ Db.Encode.int 1 ]
, decoder =
Db.Decode.map2
(Db.Decode.int "id")
(Db.Decode.string "name")
(\id name -> { id = id, name = name })
}
A decoder for a full record.
This is what's passed to the decoder
field.
A decoder for an individual field.
This is what's passed to your map functions.
Fields
Decode a string field.
Decode an integer field.
Decode a float field.
Decode a boolean field.
Decode an integer field into a Time.Posix value.
The integer in the database should represent the number of milliseconds since 1970 January 1 at 00:00:00 UTC. (See Db.Encode.posix.
Decode a nullable field in the database.
The first parameter is the decoder function for the field type if the value is not null. For example, to decode a nullable INTEGER field:
Db.Decode.maybe Db.Decode.int "myField"
Mapping
Use these map functions to turn one or more field decoders into a full decoder.
Map a single field.
Map 2 fields.
Map 3 fields.
Map 4 fields.
Map 5 fields.
Map 6 fields.
Map 7 fields.
Map 8 fields.
Util
You shouldn't need these unless you are bypassing this package's API to interact with the ws4sql server directly.
Get a json decoder for a raw ws4sql query response.
Get a json decoder for a raw ws4sql statement response.