Sunday, October 25, 2015

A MySQL UDF written in Go

I was wondering if it is possible to write a MySQL User Defined Function (UDF) in Go.  
So I tried and I got a very basic UDF working.
mysql> SELECT udf_fileexists_go("/etc/hosts");
+---------------------------------+
| udf_fileexists_go("/etc/hosts") |
+---------------------------------+
|                               1 |
+---------------------------------+
1 row in set (0.00 sec)

mysql> SELECT udf_fileexists_go("/nonexistend");
+-----------------------------------+
| udf_fileexists_go("/nonexistend") |
+-----------------------------------+
|                                 0 |
+-----------------------------------+
1 row in set (0.00 sec)

This is nowhere near production quality, so be careful.

The code is here:https://github.com/dveeden/udf_fileexists_go/blob/master/udf_fileexists_go.go.

2 comments:

  1. Super cool. I had to install the development libraries rpm and modify the cgo comment to point to the proper location in my env but it compiled & created without issue. Thanks for sharing and blazing the trail!

    ReplyDelete
  2. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. privacyenbescherming

    ReplyDelete

Note: Only a member of this blog may post a comment.