Module to run SQL queries on a Mysql database.
Settings:
DSN syntax <username>:<pw>@tcp(<HOST>:<port>)/<dbname>
Query or queries. If several queries separated by ; (semicolon) provided, they will run in a .
Example for using transactions with last insert ID:
insert into sometable (id,somecolumn) values (null,'somevalue');
set @lastid = last_insert_id();
insert into othertable (id,parent,somecolumn) values (null,@lastid,'some other value');
Example using template loops to generate payload:
UPDATE products SET updated_at = NOW()
WHERE id IN (
{{range $idx, $product := .Payload}}
{{if $idx}},{{end -}}
{{$product.id -}}
{{end -}}
)
Little explanation: templates use go's templating library, ranging through a payload (.Payload
) that's an array of product objects in our example. The array index ($idx
) is used to put comma between the values (first array index is 0, a false value, will not produce a comma, but every other iteration will add the comma). The -
(hyphen) inside the {{
}}
go template tags before the closing }}
will ommit the coming new line character, so the template code is more readable.
The result will be saved into the Header under this key.
returned records will be processed as one array instead of creating a packet for every record.
incoming packet will be copied to the output even if there was no resulting row
continue running the code even if there was an error while running the query/queries. If several queries were provided, the transaction will not be rolled back but committed.